Login Page - Create Account

Support Board


Date/Time: Fri, 10 May 2024 20:13:40 +0000



Post From: TCP/IP Server in custom study

[2021-06-02 07:36:39]
User310645 - Posts: 49
It will be something to do with the reference. Its c++ so MyData.sc needs to be initialised to something.
You could make it more c++ like

class Server {
public:
Server(SCStudyInterfaceRef sc, int debug) : sc(sc), debug(debug) {}

void Start() {
hThreadArray = CreateThread(
NULL, // default security attributes
0, // use default stack size
startThread, // thread function name
(void*)this, // argument to thread function
0, // use default creation flags
&dwThreadIdArray); // returns the thread identifier
}

private:
SCStudyInterfaceRef sc;
int debug;

HANDLE hThreadArray;
DWORD dwThreadIdArray;

static DWORD WINAPI startThread(void* param) {
Server* data = reinterpret_cast<Server*>(param);
return data->run();
}

DWORD run() {
// do thread stuff here
sc.AddMessageToLog("started thread", debug);
return 0;
}

};

Server TcpServer(sc, 1);
TcpServer.Start();

or if you wanted to keep it similar to what you have you could probably change the reference to a pointer


typedef s_sc* SCPtr;

typedef struct MyData {
SCPtr sc;
int debug;
} SERVER_SOCKET_MYDATA, * PMYDATA;

pDataArray->sc = &sc

Date Time Of Last Edit: 2021-06-02 08:01:37