Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Returning a string from VC++ dll to VB

Options
  • 26-02-2006 12:23pm
    #1
    Registered Users 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 Posts: 6,508 ✭✭✭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 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 Posts: 6,508 ✭✭✭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 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