1

我希望有更多 C++ 知识的人可以帮助我。我正在尝试从我在托管 C++ DLL 中创建的类中创建 C# 中的对象数组。我不知道发生了什么。我能够运行应用程序并构建它,设置类数组似乎工作得很好,但是当我从数组中调用一个函数时,它从不研究托管 DLL。我已经追踪了它,它根本不起作用。该应用程序也不会因任何错误而失败。有趣的是,当我删除了类数组并且只在它运行良好且花花公子时才启动该类。请帮我弄清楚如何解决这个问题。

//C#

public ClientBridge[] netlobby;

private void connectToLobby(int lobbyIndex)
{
//lobbyIndex = 0

netlobby[lobbyIndex] = new ClientBridge();

connectLobby[lobbyIndex] = netlobby[lobbyIndex].MMK_Connect(host, lobbyport);

}




//C++ DLL

// This class is the managed reference class
public ref class ClientBridge
{
    public:
        ClientBridge();
        virtual ~ClientBridge();
        bool MMK_Connect(String^ hostpass, UInt16 port);
};
4

1 回答 1

2

看起来你从未初始化过数组

public ClientBridge[] netlobby = new ClientBridge[MAX_BRIDGES]; // <- gotta initialize

private void connectToLobby(int lobbyIndex)
{

netlobby[lobbyIndex] = new ClientBridge();

connectLobby[lobbyIndex] = netlobby[lobbyIndex].MMK_Connect(host, lobbyport);

}
于 2009-09-30T20:24:46.253 回答