【问题标题】:Calling c++ function in a struct with C#使用 C# 在结构中调用 c++ 函数
【发布时间】: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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-11
    • 1970-01-01
    相关资源
    最近更新 更多