我有一个c ++本机dll文件,我应该通过c#
从Dll调用一些函数我应该调用的c ++函数是
extern NCSError NCS_CALL NCSOpenFileViewA(const char *szUrlPath, NCSFileView **ppNCSFileView,NCSReadStatus (*pRefreshCallback)(NCSFileView *pNCSFileView));
NCSFileView对象是
typedef struct NCSFileViewStruct NCSFileView;
和工作示例c ++代码是
NCS::CApplication App
NCSCompressClient *pClient;
char *szInputFilename = "C:\\testdata\\RGB_8bit.ecw";
NCSFileView *pNCSFileView;
NCSFileInfo *pNCSFileInfo;
NCSFileMetaData *pNCSFileMeta;
NCSError eError;
NCSInit();
eError = NCSOpenFileViewA(szInputFilename, &pNCSFileView, NULL);
if (eError != NCS_SUCCESS) {
ReportError("Could not open view for file:%s, Error = %s",
szInputFilename, NCSGetErrorText(eError));
exit(1);
}`
我制作了像这样的c#代码
[DllImport("C:\\NCSEcw.dll",CallingConvention=CallingConvention.Cdecl)]
public static extern IntPtr NCSOpenFileViewA ([MarshalAs(UnmanagedType.LPStr)] string path,
IntPtr a,
IntPtr c);
但我得到像这样的错误
尝试读取或写入受保护的内存。这通常表明其他内存已损坏。
所以,你能帮我写一个包装器吗?