Visual Basic 和 C++ 的 DLL 之间传递一个字符串的方法

.cpp

   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);
}

 

.def(不可或缺的,之前一直少了这个,报很多奇怪的问题)

LIBRARY StrSamp
      DESCRIPTION 
' Microsoft KB Sample DLL '
      EXPORTS
         DisplayStringByVal
         DisplayStringByRef
         FillString
         InStrRev

 

VB

Private   Declare   Sub  FillString  Lib   " StrSamp.dll "  _
         (
ByVal  sMyString  As   String ByVal  cBufferSize  As   Long )

 

 

Private   Sub  Command2_Click()
         
Dim  sFillTest  As   String

         sFillTest 
=   Space $( 260 )
         FillString sFillTest, 
260
         
MsgBox   Trim $(sFillTest), vbInformation,  " Fill String "

End Sub

from:

http://support.microsoft.com/kb/187912

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值