1

私は現在、2つのプログラム間でデータを送信するためにVisual Studio C ++を使用して.dllを生成しています。基本的に、一方のプログラムは、イベントが発生したときにもう一方のプログラムに通知します。TcPクライアントソケットを介してこれを実行しようとしています。

私のヘッダーファイルは次のようになります。

#include <string>

using namespace std;

extern "C"
{
    __declspec (dllexport) bool trackerConnect( char* ipAddress, int port );
    __declspec (dllexport) void sendEvent ( char* ev);
    __declspec (dllexport) void disconnect();
}

私の.cppファイルは次のようになります

#define WIN32_LEAN_AND_MEAN

#include "logEvents.h"
#using "system.dll"

using namespace System;
using namespace System::Net;
using namespace System::Net::Sockets;
using namespace System::Text;

TcpClient^ logClient;
NetworkStream^ logStream;

bool trackerConnect( char* ipAddress, int port )
{
    /*Connects to server, gets stream, and returns whether the connection was
    successful or not*/
}

void sendEvent ( char* ev )
{
    /*Converts ev into a Byte array and sends it to the server to notify it 
    that an event has occurred*/
}

void disconnect ()
{
    //closes the connection with the server
}

3つの関数すべてがTcPClientにアクセスする必要があることを考えると、私はそれをグローバル変数として宣言しました。ただし、コンパイルすると、エラーC3145が発生します。グローバル変数または静的変数にマネージタイプがない可能性があります。TcPClientをグローバル変数として宣言できない場合、3つの関数でどのように使用するのですか?

4

0 に答える 0