Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Returning a string from VC++ dll to VB

  • 26-02-2006 12:23PM
    #1
    Registered Users, Registered Users 2 Posts: 250 ✭✭


    I have seen a few "examples" on the web for returning a string from a dll written in VC++ to VB, in particular an article written by Nick Skapura (posted on various VB sites).

    My problem is that this article (which has very good working example of passing parameters between VB and C++ in general) does not cover passing a newly created string back to VB, but uses a memory address already allocated to a parameter passed into the dll function at the initial call, to return the string to vb.

    Does anybody know of a good tutorial that will explain how to do this? Also, some tutorials talk abt using BSTR to return a string-like structure for VB to work with, and other tutorials talk abt only passing passing back the pointer address. Which is better for safe and stable VB-C++ communication (taking into consideration coding efforts to make each scenario work)

    TIA


Comments

  • Registered Users, Registered Users 2 Posts: 6,652 ✭✭✭daymobrew


    Why do you want to return a newly created string? Why not follow the method in the article where it sends a pointer to the string location? Many Windows API functions use this form.


  • Registered Users, Registered Users 2 Posts: 250 ✭✭ikoonman


    daymobrew wrote:
    Why do you want to return a newly created string? Why not follow the method in the article where it sends a pointer to the string location? Many Windows API functions use this form.

    That would be ideal, but I haven't really seen any examples/tutorials where it returns pointer-to-string for use in VB. Do you perhaps have any links?

    TIA


  • Registered Users, Registered Users 2 Posts: 6,652 ✭✭✭daymobrew


    ikoonman wrote:
    That would be ideal, but I haven't really seen any examples/tutorials where it returns pointer-to-string for use in VB. Do you perhaps have any links?

    TIA
    ikoonman wrote:
    but uses a memory address already allocated to a parameter passed into the dll function at the initial call, to return the string to vb.
    pointer == memory address.
    I meant use Nick Skapura's example you found. It's a solution that works. Why don't you want to use that form?


  • Registered Users, Registered Users 2 Posts: 250 ✭✭ikoonman


    daymobrew wrote:
    pointer == memory address.
    I meant use Nick Skapura's example you found. It's a solution that works. Why don't you want to use that form?

    I understand that yes, but then I read up on Google Groups and a lot of people were complaining that you could only use the length of the buffer as passed in by the VB app - so i assume that meant that if the var declared in VB was STRING * 100, you pretty much had a buffer of 100 bytes for the C dll to populate and return. I want more than that (to a max of say 1 meg)


  • Closed Accounts Posts: 3,357 ✭✭✭Beano


    I havent read the article you mention but a string in VB is either fixed length or variable length. If the article mentions variable length strings then you have no problem as their max size is approx 2 billion characters. If it uses fixed length strings then you're out of luck as they have a max of 64K characters.


  • Advertisement
Advertisement