当前位置: 代码迷 >> VC >> VC编写DLL PB取字符串不正确,该如何处理
  详细解决方案

VC编写DLL PB取字符串不正确,该如何处理

热度:1555   发布时间:2013-02-25 00:00:00.0
VC编写DLL PB取字符串不正确
VC定义如下:
extern "C" _declspec(dllexport) __int64 __stdcall Hello(BSTR* x)
{
*x=::SysAllocString(L"1");
  __int64 c=0; 
  return c;
}
PB引用:
public function integer Hello(ref string xyz) library "Hello.DLL" alias for "Hello"

string z
Hello(z)

得到z="";

在C#中引用这函数正常.
把BSTR* 改为 char** 也不行.

------解决方案--------------------------------------------------------
VC定义如下: 
extern "C " _declspec(dllexport) __int64 __stdcall Hello(BSTR* x) 
vc定义的函数返回值是 __int64 

PB引用: 
public function integer Hello(ref string xyz) library "Hello.DLL " alias for "Hello " 
声明的返回值是integer .integer 应该32位整型变量。。
把pb引用改成

public function long Hello(ref string xyz) library "Hello.DLL " alias for "Hello " 
试试看。。

------解决方案--------------------------------------------------------
返回值是会影响的.在32位的编译器上 返回一个 int 和 __int64代码会差别很多的.
  相关解决方案