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. createThread , Prototype, and extren call correctness?

createThread , Prototype, and extren call correctness?

Scheduled Pinned Locked Moved C / C++ / MFC
debuggingperformancehelpquestion
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

    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

    J 1 Reply Last reply
    0
    • P Pecan204

      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

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

      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 replacing

      CloseHandle(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

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

        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 replacing

        CloseHandle(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

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

        Thanks 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

        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