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. Help with structure and createThread function call

Help with structure and createThread function call

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++question
3 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.
  • P Offline
    P Offline
    Pecan204
    wrote on last edited by
    #1

    I am not real clear on using structure statements and external function calls. I am getting the following errors when I compile the file below. Can someone hlep? Thanks. cinterface3.cpp(22) : error C2228: left of '.start' must have class/struct/union type cinterface3.cpp(24) : error C2664: 'CreateThread' : cannot convert parameter 3 from 'void (long *)' to 'unsigned long (__stdcall *)(void *)' cinterface3.cpp(30) : error C2228: left of '.time' must have class/struct/union type #include #include #include struct io { char time[10]; int start; }; struct io cio; extern "C" __declspec(dllimport) void _stdcall FTREND3 ( long * ); void main (void) { DWORD tid, cio; HANDLE hThread; cio.start = 1; hThread = CreateThread(NULL, 0, FTREND3, &cio, 0, &tid); CloseHandle(hThread); printf("In c after fortran thread started\n\n"); printf("string = %s\n",cio.time); }

    J 1 Reply Last reply
    0
    • P Pecan204

      I am not real clear on using structure statements and external function calls. I am getting the following errors when I compile the file below. Can someone hlep? Thanks. cinterface3.cpp(22) : error C2228: left of '.start' must have class/struct/union type cinterface3.cpp(24) : error C2664: 'CreateThread' : cannot convert parameter 3 from 'void (long *)' to 'unsigned long (__stdcall *)(void *)' cinterface3.cpp(30) : error C2228: left of '.time' must have class/struct/union type #include #include #include struct io { char time[10]; int start; }; struct io cio; extern "C" __declspec(dllimport) void _stdcall FTREND3 ( long * ); void main (void) { DWORD tid, cio; HANDLE hThread; cio.start = 1; hThread = CreateThread(NULL, 0, FTREND3, &cio, 0, &tid); CloseHandle(hThread); printf("In c after fortran thread started\n\n"); printf("string = %s\n",cio.time); }

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      Two errors here:

      1. cio is a DWORD, seems like you meant it to be a io:

        DWORD tid;
        io cio;

      2. FTREND3 does not have the interface expected by CreateThread, as it accepts a long * where CreateThread wants a void *. In this particular case, you can simply force the cast:

        hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)FTREND3, &cio, 0, &tid);

        Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      P 1 Reply Last reply
      0
      • J Joaquin M Lopez Munoz

        Two errors here:

        1. cio is a DWORD, seems like you meant it to be a io:

          DWORD tid;
          io cio;

        2. FTREND3 does not have the interface expected by CreateThread, as it accepts a long * where CreateThread wants a void *. In this particular case, you can simply force the cast:

          hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)FTREND3, &cio, 0, &tid);

          Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        P Offline
        P Offline
        Pecan204
        wrote on last edited by
        #3

        Thanks Joaquin.

        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