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.
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:
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA"
(ByVal lpBuffer As String, nSize As Long) As Long
Private Sub Form_Load()
Dim strUserName As String
'Create a buffer
strUserName = String(100, Chr$(0))
'Get the username
GetUserName strUserName, 100
'strip the rest of the buffer
strUserName = Left$(strUserName, InStr(strUserName, Chr$(0)) - 1)
End Sub
Re: How do I declare a string and pass it from a Visual Basic GUI to a C++ DLL?
an example,
VB Code:
#include <windows.h>
BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved){
return TRUE;
}
extern "C" __declspec( dllexport ) __stdcall char *UChar(char *);
extern "C" __declspec( dllexport ) __stdcall char *UChar(char *UCaseString)
{
int StrUCaseLen;
StrUCaseLen=strlen(UCaseString);
char *myChar = new char[StrUCaseLen+1];
strncpy(myChar,UCaseString,StrUCaseLen);
return strupr(myChar) ;
}
VB Code:
Private Declare Function UChar Lib "c:\dll.dll" (ByVal strTxt As String) As String
Private Sub Command1_Click()
MsgBox UChar("huh¿")
End Sub
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..