2012-01-18 150 views
1

我有一个C++ dll。我必须在c#代码中使用此dll。在这个DLL中:用C调用C++函数#

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

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

+0

是的,这是永远不会工作。因为它是C++,所以你需要找出错位的名字(如果这是个问题)。你可能有更多的运气将'CServerInterface'作为COM对象导出。 – leppie 2012-01-18 09:22:19

回答

0

我是新手,但试试这个; 制作CServerInterface和UserRecord“public class”。一个例子;

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