Passing strings from VBA to C++ DLL

后端 未结 5 798
太阳男子
太阳男子 2021-02-05 11:31

I\'m really confused about passing strings from VBA to C++. Here\'s the VBA code:

Private Declare Sub passBSTRVal Lib \"         


        
5条回答
  •  南旧
    南旧 (楼主)
    2021-02-05 11:52

    This is just an illustration to Simon's answer. It shows how to call a native DLL that has parameters of type LPWSTR. As a simple example, I use GetWindowsDirectoryW. As Simon pointed out, always use the "W" version of native DLLs.

    Declare PtrSafe Function GetWindowsDirectoryW Lib "kernel32" _ 
       (ByVal lpBuffer As LongPtr, ByVal nSize As Long) As Long
    
    Sub TestGetWindowsDirectoryW()
      Dim WindowsDir As String
      WindowsDir = Space$(256)
      GetWindowsDirectoryW StrPtr(WindowsDir), 256
      MsgBox WindowsDir
    End Sub
    

提交回复
热议问题