我想用一个DLL,并把char sn[8]内容形成一个字符串并输出(输出函数已定义),该如何做?
在VB中调用DLL,并能直接获取输出的字符串值。

解决方案 »

  1.   

    void __stdcall FillString(LPSTR pszString, LONG cSize)
          {
             // Create a temp buffer with our string
             char buffer[] = "Hello from the C DLL!";         // Copy our temp string to pszString
             // but check the size to make sure we have a buffer
             // big enough to hold the entire string.
             if (cSize > strlen(buffer))
                strcpy(pszString, buffer);
          }
    To make the functions exportable, add the following to "StrSamp.def:"       LIBRARY StrSamp
          DESCRIPTION 'Microsoft KB Sample DLL'
          EXPORTS
             FillString
    VB declare:
          Private Declare Sub FillString Lib "StrSamp.dll" _
             (ByVal sMyString As String, ByVal cBufferSize As Long)sample
             Dim sFillTest As String         sFillTest = Space$(260)
             FillString sFillTest, 260
             MsgBox Trim$(sFillTest), vbInformation, "Fill String"
      

  2.   

    CString str = (const char*)charBuf