like this vb use dll compile by vc 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
楼上的,你没看到这个问题吗? ******************************************************* 我的数据有5个字节,不能用现成的数据类型呀! 我在链接库中的函数是: unsigned int fun(unsigned char *re) 我在VB中用的是ByRef re() as Byte 可是运行的时候说调用约定错误。 *******************************************************
例: __int16 __stdcall bm_thrc13(HANDLE dev_id,unsigned char *sernr)调用:Declare Function bm_thrc13 Lib "bm32.dll" (ByVal dev_id As Long, ByVal sernr As String) As IntegerDim sernr As String * 8 st = bm_thrc13(dev, sernr)
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
但是现在有 *,指针,怕是不行了
如果调用者接收,可以是不定长字符串;否则用定长字符串(最好8,16,32......1024之类)。2 声明成Byte数组,byref。
*******************************************************
我的数据有5个字节,不能用现成的数据类型呀!
我在链接库中的函数是:
unsigned int fun(unsigned char *re)
我在VB中用的是ByRef re() as Byte
可是运行的时候说调用约定错误。
*******************************************************
__int16 __stdcall bm_thrc13(HANDLE dev_id,unsigned char *sernr)调用:Declare Function bm_thrc13 Lib "bm32.dll" (ByVal dev_id As Long, ByVal sernr As String) As IntegerDim sernr As String * 8
st = bm_thrc13(dev, sernr)