How to use the mysql in the child thread ?
-
I setup the mysql5.0 and sdk. now I create a mfc dialog project, and use it in the Main Thread ,it's no problem. but I create another thread, in the thread function I define a variables like this: DWORD CTestDlg::ThreadFun(LPVOID lParam) { CTestDlg *pDlg = (CTestDlg *)lParam; MYSQL mysql; mysql_init(&mysql); // here is access violation. Unhandled exception in Test.exe(MYSQLD.exe): 0xc0000005: Access Violation. // if I use it in the main thread,is ok. } so how to use the mysql in the child thread ?
-
I setup the mysql5.0 and sdk. now I create a mfc dialog project, and use it in the Main Thread ,it's no problem. but I create another thread, in the thread function I define a variables like this: DWORD CTestDlg::ThreadFun(LPVOID lParam) { CTestDlg *pDlg = (CTestDlg *)lParam; MYSQL mysql; mysql_init(&mysql); // here is access violation. Unhandled exception in Test.exe(MYSQLD.exe): 0xc0000005: Access Violation. // if I use it in the main thread,is ok. } so how to use the mysql in the child thread ?
Syntax for mysql_init: MYSQL *mysql_init(MYSQL *mysql) Try this:
MYSQL *mysql; // Now initialize and get mysql if(mysql_init(mysql) == NULL) { //Some message saying that the initialization failed }
Alternatively, you can pass the mysql object to the ThreadFun after initializing it in main thread.
You talk about Being HUMAN. I have it in my name AnsHUMAN