我在 C++ DLL 中有一个导出函数
// C++ DLL (Blarggg.dll)
extern "C"
{
USHORT ReadProperty( BYTE * messsage, USHORT length, BYTE * invokeID )
{
if( invokeID != NULL ) {
* invokeID = 10 ;
}
return 0;
}
}
我想让它可用于我的 C# 应用程序
// C# app
[DllImport("Blarggg.dll")]
public static extern System.UInt16 ReadProperty(
/* [OUT] */ System.Byte[] message,
/* [IN] */ System.UInt16 length,
/* [OUT] */ System.Byte[] invokeID );
private void DoIt()
{
System.Byte[] message = new System.Byte[2000];
System.Byte[] InvokeID = new System.Byte[1];
System.UInt16 ret = ReadProperty( message, 2000, InvokeID ); // Error
}
问题是我不断收到以下错误消息。
Blarggg.dll 中发生了“System.NullReferenceException”类型的未经处理的异常附加信息:对象引用未设置为对象的实例。
我正在使用 VS2008 来构建 DLL 和 C# 应用程序。
我不是 C# 程序员。
我究竟做错了什么?