Results 1 to 4 of 4

Thread: How do I declare a string and pass it from a Visual Basic GUI to a C++ DLL?

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    14

    How do I declare a string and pass it from a Visual Basic GUI to a C++ DLL?

    How do I declare a string and pass it from a Visual Basic GUI to a C++ DLL?

    Now I am debugging successfully. I can debug either on the Visual Basic end or I can debug on the C++ side by using the DLL's project file and declaring the compiled VB code as the launching executable. I have narrowed the problem down to the way that I am declaring and passiing the string variables.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: How do I declare a string and pass it from a Visual Basic GUI to a C++ DLL?

    Here is a sample to get user name via windows api function (basically the same thing you're after):
    VB Code:
    1. Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA"
    2.     (ByVal lpBuffer As String, nSize As Long) As Long
    3.  
    4. Private Sub Form_Load()
    5. Dim strUserName As String
    6.  
    7.     'Create a buffer
    8.     strUserName = String(100, Chr$(0))
    9.    
    10.     'Get the username
    11.     GetUserName strUserName, 100
    12.    
    13.     'strip the rest of the buffer
    14.     strUserName = Left$(strUserName, InStr(strUserName, Chr$(0)) - 1)
    15.  
    16. End Sub

  3. #3
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Re: How do I declare a string and pass it from a Visual Basic GUI to a C++ DLL?

    an example,


    VB Code:
    1. #include <windows.h>
    2.  
    3. BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved){
    4.     return TRUE;
    5. }
    6.  
    7. extern "C" __declspec( dllexport ) __stdcall char *UChar(char *);
    8.  
    9. extern "C" __declspec( dllexport ) __stdcall char *UChar(char *UCaseString)
    10.  
    11. {
    12.  
    13.     int StrUCaseLen;
    14.  
    15.     StrUCaseLen=strlen(UCaseString);
    16.  
    17.     char *myChar = new char[StrUCaseLen+1];
    18.  
    19.     strncpy(myChar,UCaseString,StrUCaseLen);
    20.  
    21.     return strupr(myChar) ;
    22.  
    23. }



    VB Code:
    1. Private Declare Function UChar Lib "c:\dll.dll" (ByVal strTxt As String) As String
    2.  
    3. Private Sub Command1_Click()
    4.  
    5.     MsgBox UChar("huh¿")
    6.  
    7. End Sub

  4. #4
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Re: How do I declare a string and pass it from a Visual Basic GUI to a C++ DLL?

    you don't need a def file if doing it this way..

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