VB pass string to VC
Change the ByRef to ByVal in the Declare-statement. Sending it as a ByRef will send it as it is defined internally in VB. ByVal will send the actual string and not the internal struct (something like length + string).
Public Declare Sub DeReceiveStringFromVB Lib "MyVCDLL" ( _
ByVal s1 As String, ByVal s2 As String)DeReceiveStringFromVB "aaa", "bbb"
__declspec( dllexport ) void __stdcall DeReceiveStringFromVB(LPCSTR lp1,LPCSTR lp2)
{
std::stringstream stmp;
stmp<<"ReceiveStringFromVB("<<lp1<<","<<lp2<<")";
OutputDebugString(stmp.str().c_str());
}
VC pass string to VB
__declspec( dllexport ) void __stdcall Long2String2(long lpdata,LPSTR pszString, LONG cSize)
{wsprintf(pszString,"%d",lpdata);
}
Private Declare Sub Long2String2 Lib "MyVCDLL" ( _
ByVal pFunc As Long, ByVal sMyString As String, ByVal cBufferSize As Long)Dim sFillTest As String
sFillTest = Space$(260)
Long2String2 wParam, sFillTest, 260
Change the ByRef to ByVal in the Declare-statement. Sending it as a ByRef will send it as it is defined internally in VB. ByVal will send the actual string and not the internal struct (something like length + string).
Public Declare Sub DeReceiveStringFromVB Lib "MyVCDLL" ( _
ByVal s1 As String, ByVal s2 As String)DeReceiveStringFromVB "aaa", "bbb"
__declspec( dllexport ) void __stdcall DeReceiveStringFromVB(LPCSTR lp1,LPCSTR lp2)
{
std::stringstream stmp;
stmp<<"ReceiveStringFromVB("<<lp1<<","<<lp2<<")";
OutputDebugString(stmp.str().c_str());
}
VC pass string to VB
__declspec( dllexport ) void __stdcall Long2String2(long lpdata,LPSTR pszString, LONG cSize)
{wsprintf(pszString,"%d",lpdata);
}
Private Declare Sub Long2String2 Lib "MyVCDLL" ( _
ByVal pFunc As Long, ByVal sMyString As String, ByVal cBufferSize As Long)Dim sFillTest As String
sFillTest = Space$(260)
Long2String2 wParam, sFillTest, 260
没有试过
Private Declare Sub 函数名 Lib Dll名 (ByRef Strings As Long, ByVal nItems As Long)
Dim TempStrs() as String
Dim TempStrsPtr() as Long
Dim Count As Long
Dim I as Long'赋值
Count=……
ReDim TempStrs(0 to Count-1)
TempStrs(……)=……
……ReDim TempStrsPtr(0 to Count-1)
For I=0 to Count-1
TempStrs(I)=StrConv(TempStrs(I), vbFromUniCode) '转为ANSI+DBCS
TempStrsPtr(I)=StrPtr(TempStrs(I)) '设置地址
Next I
Call 函数名(TempStrsPtr(0), Count)