C# 用C调用结构中的C++函数 我有一个C++ DLL。我必须在c代码中使用这个dll。在此dll中: struct UserRecord { int login; //some properties here } struct CServerInterface { int __stdcall ClientsAddUser(UserRecord *inf); //some other functions here }

C# 用C调用结构中的C++函数 我有一个C++ DLL。我必须在c代码中使用这个dll。在此dll中: struct UserRecord { int login; //some properties here } struct CServerInterface { int __stdcall ClientsAddUser(UserRecord *inf); //some other functions here },c#,dllimport,interopservices,C#,Dllimport,Interopservices,如何调用结构中的函数?我试试这个: [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(); ClientsAddUse

如何调用结构中的函数?我试试这个:

[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”的入口点


我想,如果这个函数不在结构中,我不会抛出异常。

我是新手,但试试这个; 使CServerInterface和UserRecord成为公共类。一个例子

public class CServerInterface() {int __stdcall ClientsAddUser(UserRecord *inf);}

是啊,那是行不通的。由于它是C++,如果需要解决这个问题,你需要找出它的名字。将CServerInterface导出为COM对象可能会更幸运。