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

解决方案 »

  1.   

    字符串数组?以前想过
    没有试过
    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)
      

  2.   

    holydiablo(鱼头)、jennyvenus(JennyVenus) 两位没明白我的意思,我说的是字符串数组,是数组。zyl910(910:分儿,我来了!)你的想法真是奇特,不愧有三个星,不过我也没试你的,我用了另外一笨办法,我首先取得数组大小,然后循环取得字符串数组,:D