当前位置: 代码迷 >> ASP.NET >> 拜求调用C的Dll 在 C#中的写法解决办法
  详细解决方案

拜求调用C的Dll 在 C#中的写法解决办法

热度:1894   发布时间:2013-02-25 00:00:00.0
拜求调用C的Dll 在 C#中的写法
C 函数接口如下:

#ifdef __cplusplus
extern "C" {
#endif
/*
参数:
char *pStrIn[in]
long lLenIn[in]
char *pStrOut[out]
long *lLenOut[in,out]
*/
CS_BASEEN_API int BaseEn(char *pStrIn, long lLenIn, char *pStrOut, long *lLenOut);

我在C#中
  
[DllImport(@"BaseEn.dll")]
    protected static extern int BaseEn(string pStrIn, int BaudRate, ref string pStrOut, ref int lLenOut);

都是提示错误:尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
求解决,在线等

------解决方案--------------------------------------------------------
试试

        [DllImport(@"BaseEn.dll",CallingConvention= CallingConvention.Cdecl)]
        protected static extern int BaseEn(string pStrIn, long BaudRate, string pStrOut, ref long lLenOut);

------解决方案--------------------------------------------------------
尝试读取或写入受保护的内存。这通常指示其他内存已损坏是参数传递错误
试试BaseEn(byte[],int,byte[],ref int)
------解决方案--------------------------------------------------------
[DllImport(@"BaseEn.dll")]
    protected static extern int BaseEn(string pStrIn, int BaudRate, ref stringbuilder pStrOut, ref int lLenOut);
  相关解决方案