简体   繁体   English

.NET和C ++互操作性

[英].NET and C++ interoperability

I'm having a C++ dll which has an exported function having the following signature... 我正在使用C ++ dll,该dll具有具有以下签名的导出功能...

__declspec(dllexport) __stdcall
 void Paint(LPDISPATCH& disp, VARIANT& x, VARIANT& y, VARIANT& z);

I want to call the this exported function from C#.NET. 我想从C#.NET调用此导出函数。 For this is used the following prototype... 为此使用以下原型...

[DllImport("xyz.dll", 
CallingConvention = CallingConvention.StdCall)
public static extern void Paint(
            [MarshalAs(UnmanagedType.IDispatch), In, Out] ref object which,
            [MarshalAs(UnmanagedType.I4), In, Out] ref object x,
            [MarshalAs(UnmanagedType.I4), In, Out] ref object y,
            [MarshalAs(UnmanagedType.I4), In, Out] ref object x);

When i tried to invoke the call, it is throwing an exception saying that Attempted to read/write memory which is invalid. 当我尝试调用该调用时,它抛出异常,表明试图读取/写入无效的内存。

Please advise me on this, on how to P/invoke this C++ API from .NET. 请给我有关如何从.NET P /调用此C ++ API的建议。

Much Thanks, Sundareswaran Senthilvel 非常感谢,Sundareswaran Senthilvel

您有不同的返回类型,它声明为返回void ,但是您使用bool导入了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM