<分区>
我必须替换旧项目中的 DLL。该项目无法更改(向下兼容、其他生产者等)并具有以下方法签名:
typedef UINT(*CALLBACK Initialise)();
Initialise fp_initialise;
typedef UINT(*CALLBACK ReadPosition)(int *ptr_ncolours, float *ptr_pderrs, float *ptr_cderrs);
ReadPosition fp_readposition;
等等...
其中 CALLBACK
是 __stdcall
我的 C# DLL 接口(interface):
[Guid("00005D2D-ABCD-3214-5694-A4EC0005B4D9")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
[ComVisible(true)]
public interface IMainInterface
{
int Initialise();
unsafe int ReadPosition(ref int ptr_ncolours, float* ptr_pderrs, float* ptr_cderrs);
//...
}
以及我使用接口(interface)的类:
[ClassInterface(ClassInterfaceType.None)]
[Guid("04991247-ABCD-ABCD-A4B8-3533D2F264D0")]
[ComVisible(true)]
[ProgId("MyDLL.Main")]
public class Main : IMainInterface
{
//...
}
在我的新 C# dll 中调用 Initialize(它没有参数)有效,但任何其他方法调用都在没有任何信息的情况下崩溃。
当我从 C++ 应用程序调用它时,当我用新的 C# dll 替换旧的 dll 时,我如何在我的 C# dll 中编写这些方法?