调用com接口报错,尝试读写受保护的内存!
现需要调用一个dll组件,给的接口原型
HRESULT GetOperInfo([in]LONG i_ind, [in]LONG i_port, [out] BSTR* s_val, [out,retval] long* Result)
在调用过程中一直提示尝试读写受保护的内存,怀疑参数类型BSTR传入问题。于是尝试使用
string
StringBuilder
byte[]
char[]
都失败
[DllImport("xxx.dll",EntryPoint = "GetOperInfo")]
public static extern void GetOperInfo(long i_ind,long i_port,ref string s_val,ref int Result);
public static extern void GetOperInfo(long i_ind,long i_port,ref StringBuilder s_val,ref int Result);
public static extern void GetOperInfo(long i_ind,long i_port,ref byte[] s_val,ref int Result);
public static extern void GetOperInfo(long i_ind,long i_port,ref char[] s_val,ref int Result);
网上搜了确实用string就可以。但就是调用失败,请求思路或者解决方案。谢谢;