【发布时间】:2012-02-13 00:42:45
【问题描述】:
我有一个 c++ dll。我必须在 c# 代码中使用这个 dll。在这个 dll 中:
struct UserRecord
{
int login;
//some properties here
}
struct CServerInterface
{
int __stdcall ClientsAddUser(UserRecord *inf);
//some other functions here
}
如何在结构中调用函数?我试试这个:
[DllImport("WebRegistration.dll")]
public extern static int ClientsAddUser(ref UserRecord inf);
public struct UserRecord
{
//properties here
}
static void Main(string[] args)
{
UserRecord user = new UserRecord();
ClientsAddUser(ref user);
}
抛出异常:“无法在 DLL 中找到名为 'ClientsAddUser' 的入口点”。
我想如果这个函数不在结构中,我不会抛出异常。
【问题讨论】:
-
是的,这永远行不通。由于它是 C++,因此您需要找出损坏的名称(如果这是问题所在)。将
CServerInterface导出为 COM 对象可能会更幸运。
标签: c# dllimport interopservices