Help with structure and createThread function call
-
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); }
-
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); }
Two errors here:
-
cio
is aDWORD
, seems like you meant it to be aio
:DWORD tid;
io cio; -
FTREND3
does not have the interface expected byCreateThread
, as it accepts along *
whereCreateThread
wants avoid *
. 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
-
-
Two errors here:
-
cio
is aDWORD
, seems like you meant it to be aio
:DWORD tid;
io cio; -
FTREND3
does not have the interface expected byCreateThread
, as it accepts along *
whereCreateThread
wants avoid *
. 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
-