Results 1 to 5 of 5

Thread: Passing Strings

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Location
    Cardiff, UK
    Posts
    8

    Passing Strings

    Hi,

    I'm writing a DLL that needs to be able to call back into my VB app with various information. One of the functions in the VB app is like this:

    Public Sub MyCallBackFunction(byval text as string)

    I have passed the address of this function into the DLL, and can call other functions perfectly normally if I don't need to pass them a string, and I can return a string from a function in the DLL using the method below, but I can't call back into my vb app passing a string as one of the parameters.

    LPVOID PackVBStr(char * InBuffer)
    {
    LPVOID OutBuffer ;
    int BufLen ;
    BufLen = GetvbStringLen(InBuffer);

    OutBuffer =(char*)malloc((BufLen*2)+1);
    memcpy(OutBuffer,InBuffer,((BufLen*2)+1));
    return OutBuffer ;

    }


    USHORT GetvbStringLen(LPVOID InBuffer)
    {
    char *t;
    int count=0;
    int BufLen=0;

    t = (char*)InBuffer;

    while(count<2)
    {
    if(*t != '\0')
    {
    count = 0;
    BufLen++;
    }
    else
    {
    count++;
    }
    t++;
    }
    return(BufLen);
    }

    LPVOID APIENTRY ReturnString()
    {
    LPVOID ret = PackVBStr("Hello World");
    return ret;
    }

    Any ideas?

  2. #2
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    See your thread in the VB forum.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Search this forum, it has been discussed several times. Search especially for BSTR.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    I BSTR'ed him up in the other forum

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    That's gotta hurt
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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