I have to write a program which includes communication using TCP/IP and which is controlable through a Windows form. Therefore i have written a multithread-program using "pthread.h". The one thread is for windows-form, the other for the winsock-stuff.
int main(int argc, char* argv[])
{
pthread_t t1, t2; // declare 2 threads.
pthread_create(&t1, NULL, RunTCPIP, NULL); // create a thread running TCP-Communication
pthread_create(&t2, NULL, RunForms, NULL); // create a thread running Windows Forms
pthread_exit(NULL);
return 0;
}
void * RunForms(void * argument)
{
// //run GUI
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Server_C_GUI::Mainform form;
Application::Run(%form);
return 0;
}
void * RunTCPIP(void * argument)
{
//Winsock-stuff....
return 0;
}
There are some variables which i have to use in both threads. And that´s my problem. I have created "globals.h" where i have defined my global variables.
#include <string>
using namespace std;
#ifndef EXTERN
#define EXTERN extern
#endif
//Variables for OperatingMode & GUI
EXTERN const string szServerResponse;
EXTERN char cPlay;
EXTERN char cBreak;
EXTERN char cQuit;
I have included "globals.h" in the main.cpp - There it works. But when i try to include "globals.h" in "MyForm.h" - the header of my CLR-windows-form - several failures arise.
In "MyForm.h" i'd like for example to write the following code:
private: System::Void btnQuit_Click(System::Object^ sender, System::EventArgs^ e)
{
cQuit = 0; //cQuit = global variable
}
How can i use global variables in a multithread program with winsock and clr windows forms? What am i doing wrong?
Aucun commentaire:
Enregistrer un commentaire