Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to use the mysql in the child thread ?

How to use the mysql in the child thread ?

Scheduled Pinned Locked Moved C / C++ / MFC
c++mysqlhelptutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wangningyu
    wrote on last edited by
    #1

    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 ?

    _ 1 Reply Last reply
    0
    • W wangningyu

      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 ?

      _ Offline
      _ Offline
      _AnsHUMAN_
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups