用户定义的类的对象/类数组失败

发布于 2024-08-05 20:17:33 字数 696 浏览 8 评论 0原文

我希望有更多 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);
};

I am hoping someone with some more C++ knowledge might be able to help me. I am trying to create an array of objects in C# from a Class I've created in a Managed C++ DLL. I haven't any clue what is going on. I am able to run the application and build it setting up the array of classes appears to work perfectly fine but when I call a function from the array it never researches the Managed DLL. I've traced it and it simply doesn't work. The application doesn't fail with any errors either. Interestingly enough when I removed the array of classes and only initiated the class once it works all fine and dandy. Please help me figure out how to fix this.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独岁月 2024-08-12 20:17:33

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

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

}

doesn't look like you ever initialize the array

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

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文