简体   繁体   中英

Calling c++ function in a struct with C#

i have a c++ dll. i have to use this dll in c# code. in this dll:

struct UserRecord
{
  int               login;
  //some properties here
}
struct CServerInterface
{
  int         __stdcall ClientsAddUser(UserRecord *inf);
  //some other functions here
}

How can i call a function in a struct? I try this:

[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);
}

throws exception: "Unable to find an entry point named 'ClientsAddUser' in DLL".

I suppose that if this function was not in a struct, i would not throw an exception.

I'm a newbee, but try this; Make CServerInterface and UserRecord, "public class". An example;

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM