createThread , Prototype, and extren call correctness?
-
My last attempt at launching a fortran dll with createThread resulted in the following error. error LNK2001: unresolved external symbol "unsigned long __stdcall FTREND3(void *)" (?FTREND3@@YGKPAX@Z) Debug/cinterface3.exe : fatal error LNK1120: 1 unresolved externals I am not sure if the extern and DWORD prototypes are correct? If I comment out the DWORD function prototype it compiles and links but does not start the integer function. Does the createThread actually pass the integer argument of 1 or just start the function and then it sees the shared memory? Can someone comment? Thanks. Code below: #include #include #include struct io { char time[10]; int start; }; struct io cio; /* prototype for function */ DWORD WINAPI FTREND3(LPVOID); //DWORD WINAPI FTREND3(LPVOID pvoid); //extern "C" long _stdcall FTREND3 ( long ); // declspec(dllimport) for DLL's extern "C" __declspec(dllimport) long _stdcall FTREND3 ( long ); void main (void) { DWORD tid; HANDLE hThread; cio.start = 1; hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) FTREND3, &cio, 0, &tid); CloseHandle(hThread); printf("In c after fortran thread started\n\n"); printf("string = %s\n",cio.time); } INTEGER FUNCTION FTREND3 (TIO) USE DFPORT IMPLICIT NONE !DEC$ ATTRIBUTES DLLEXPORT :: FTREND3 TYPE IO INTEGER START ! if 1 start timer CHARACTER*10 timeIs END TYPE IO TYPE(io):: tio DO WHILE ( tio%START .EQ. 1) tio%timeIs = CLOCK ( ) ! Uses DFPORT tio%timeIs = tio%timeIs // char(0) write (6,*) 'In fortran after time call' write (6,*) ' Time = ', tio%timeIs FTREND3 = 1 ENDDO FTREND3 = 0 RETURN END FUNCTION FTREND3
-
My last attempt at launching a fortran dll with createThread resulted in the following error. error LNK2001: unresolved external symbol "unsigned long __stdcall FTREND3(void *)" (?FTREND3@@YGKPAX@Z) Debug/cinterface3.exe : fatal error LNK1120: 1 unresolved externals I am not sure if the extern and DWORD prototypes are correct? If I comment out the DWORD function prototype it compiles and links but does not start the integer function. Does the createThread actually pass the integer argument of 1 or just start the function and then it sees the shared memory? Can someone comment? Thanks. Code below: #include #include #include struct io { char time[10]; int start; }; struct io cio; /* prototype for function */ DWORD WINAPI FTREND3(LPVOID); //DWORD WINAPI FTREND3(LPVOID pvoid); //extern "C" long _stdcall FTREND3 ( long ); // declspec(dllimport) for DLL's extern "C" __declspec(dllimport) long _stdcall FTREND3 ( long ); void main (void) { DWORD tid; HANDLE hThread; cio.start = 1; hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) FTREND3, &cio, 0, &tid); CloseHandle(hThread); printf("In c after fortran thread started\n\n"); printf("string = %s\n",cio.time); } INTEGER FUNCTION FTREND3 (TIO) USE DFPORT IMPLICIT NONE !DEC$ ATTRIBUTES DLLEXPORT :: FTREND3 TYPE IO INTEGER START ! if 1 start timer CHARACTER*10 timeIs END TYPE IO TYPE(io):: tio DO WHILE ( tio%START .EQ. 1) tio%timeIs = CLOCK ( ) ! Uses DFPORT tio%timeIs = tio%timeIs // char(0) write (6,*) 'In fortran after time call' write (6,*) ' Time = ', tio%timeIs FTREND3 = 1 ENDDO FTREND3 = 0 RETURN END FUNCTION FTREND3
DWORD WINAPI FTREND3(LPVOID);
extern "C" __declspec(dllimport) long _stdcall FTREND3 ( long );These two lines shouldn't coexist. Both are function prototypes. Remove the first. As for the second problem,
main
is exiting right after the thread has been launched, i.e. it without waiting for it to complete. Try replacingCloseHandle(hThread);
for
CloseHandle(hThread);
WaitForSingleObect(hThread,INFIINTE);Last point is not a question of yours but of mine :) What do you want to create a thread to call
FTREND3
? You sure you cannot simply call it as a regular C function? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
DWORD WINAPI FTREND3(LPVOID);
extern "C" __declspec(dllimport) long _stdcall FTREND3 ( long );These two lines shouldn't coexist. Both are function prototypes. Remove the first. As for the second problem,
main
is exiting right after the thread has been launched, i.e. it without waiting for it to complete. Try replacingCloseHandle(hThread);
for
CloseHandle(hThread);
WaitForSingleObect(hThread,INFIINTE);Last point is not a question of yours but of mine :) What do you want to create a thread to call
FTREND3
? You sure you cannot simply call it as a regular C function? Joaquín M López Muñoz Telefónica, Investigación y DesarrolloThanks Joaquin, What is the include file for the 2nd suggestion. I get undeclared for identifiers upin compile with it. The fortran function is going to be reading alot of data continously and then reducing the data with some large fortran routines already existing. From there it will pass through the C file to a Java GUI for display. There will be option to change the read rate and other calculations that I thought would make this possible with multi threading. The alternative was to have a thread in the Java GUI continuosly looping and calling the fortran through c wrapper but I thought there were possible time delay issues there. Let me know if you have any thoughts on this? Thanks for the help. Ken