作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在 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
}
问题是我不断收到以下错误消息。
An unhanded exception of type 'System.NullReferenceException' occurred in Blarggg.dll Additional information: Object reference not set to an instance of an object.
我正在使用 VS2008 构建 DLL 和 C# 应用程序。
我不是 C# 程序员。
我做错了什么?
最佳答案
我将你的代码直接粘贴到 VS2008 中,它在我的 32 位机器上运行完美(添加了一个 .def 文件来设置导出的名称)。你的 C++ 库绝对是一个纯 win32 项目吗?您提供的错误消息似乎暗示它引发了 CLR 异常。
关于c# - DllImport a c++ DLL in to a C# app, BYTE * p,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1603834/
我是一名优秀的程序员,十分优秀!