Results 1 to 6 of 6

Thread: Function arguments

  1. #1

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471
    I'm writing a DLL in C++ for VB. If i'm passing a string to a C Function, would I use char[255] or some character
    array large enough to hold the string? Do I need any other
    arguments.
    Bababooey
    Tatatoothy
    Mamamonkey

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    No - you'd pass a pointer:
    Code:
    void func(char *pcString) {
        ...
    }
    And the VB prototype:
    Code:
    Declare Sub func Lib "whatever" (ByVal pcString As String)
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471
    Thanks for the help!
    Bababooey
    Tatatoothy
    Mamamonkey

  4. #4

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471
    Parksie (or anyone else for that matter)

    I'm trying to get the C function to return a char back as well.

    adding on to the above mentioned code, how do i get the
    c func to return a char or string and also hvae the vb func
    accept it?
    Bababooey
    Tatatoothy
    Mamamonkey

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    To do that, you pass a pointer to a buffer (using char* / ByVal x as String), and a length.

    I did an example on this for someone a while back, and here it is: http://www.parksie.net/StringDLL.zip
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471
    Thank you once again, i will try it
    Bababooey
    Tatatoothy
    Mamamonkey

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width