Thanks for the comments and links. Ken
Pecan204
Posts
-
Two programs - Same file Instantaneous write and read. -
Two programs - Same file Instantaneous write and read.Can someone suggest a method to accomplish writing to a file and at that moment another program would read that same data for its use. The program is writing a line of floats to just generate data while the other program needs to read and process it. Using two seperate executables and an ascii file led to apparent file locking issues. Thanks for any suggestions. Ken
-
createThread , Prototype, and extren call correctness?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
-
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
-
Help with structure and createThread function callThanks Joaquin.
-
Help with structure and createThread function callI 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); }
-
Errors in createthread file. Need help!Thanks all. The include windows.h cleaned up many errors.
-
Errors in createthread file. Need help!Hello, I am getting syntax errors in this file upon compile but I can't figure out what is wrong. Can someone comment? Thanks. The errors are: cinterface3.cpp(17) : error C2065: 'DWORD' : undeclared identifier cinterface3.cpp(17) : error C2146: syntax error : missing ';' before identifier 'tid' cinterface3.cpp(17) : error C2065: 'tid' : undeclared identifier cinterface3.cpp(19) : error C2065: 'HANDLE' : undeclared identifier cinterface3.cpp(19) : error C2146: syntax error : missing ';' before identifier 'hThread' cinterface3.cpp(19) : error C2065: 'hThread' : undeclared identifier cinterface3.cpp(21) : error C2065: 'CreateThread' : undeclared identifier cinterface3.cpp(23) : error C2146: syntax error : missing ';' before identifier 'CloseHandle' cinterface3.cpp(23) : error C2065: 'CloseHandle' : undeclared identifier #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; 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); }
-
Need help calling fortran dll from VCYes Joaquin. I am using MS VC 5.0. The library was built using Compaq Visual Fortran 6.0 Not sure what is the SP? Are there any work arounds? Thanks
-
Need help calling fortran dll from VCHello, Does anyone know how to call a fortran dll in MS VC? I need some help calling one.I compiled the file below. Added the .lib file to the link tab. But I get this error. Linking... debug/DLL_ROUT.lib : fatal error LNK1106: invalid file or disk full: cannot seek to 0x3e218d3c Error executing link.exe. DLL_ROUT_EXE.exe - 1 error(s), 0 warning(s) Fortram file is below.
! Fortran part of a C-Fortran DLL example. This ! routine DLL_ROUT is called from a C executable program. SUBROUTINE DLL_ROUT (INT_ARG, STR_IN, STR_OUT) IMPLICIT NONE ! Specify that DLL_ROUT is exported to a DLL !DEC$ ATTRIBUTES DLLEXPORT :: DLL_ROUT INTEGER INT_ARG CHARACTER*(*) STR_IN, STR_OUT ! This routine converts INT_ARG to a decimal string. ! appends the string value to STR_IN and stores it ! in STR_OUT. A trailing NUL is added to keep C ! happy. ! ! Note that there are implicit length arguments following ! the addresses of each CHARACTER argument. CHARACTER*5 INT_STR WRITE (INT_STR,'(I5.5)')INT_ARG STR_OUT = STR_IN // INT_STR // CHAR(0) RETURN END
The main c file is below./* Main program written in C++ that calls a Fortran DLL */ #include #include /* Declare the Fortran routine. The following items are of note: - The "C" attribute prevents C++ name mangling Remove it if the file type is .c - The dllimport specification is required - Fortran routines use the _stdcall interface by default - Fortran character arguments have a hidden length argument following the address - Routine name must be in uppercase to match Fortran. */ //extern "C" __declspec(dllimport) void _stdcall DLL_ROUT ( extern "C" void _stdcall DLL_ROUT ( int *INT_ARG, char *STR_IN, int STR_IN_LEN, char *STR_OUT, int STR_OUT_LEN); void main (int argc, char *argv[]) { char instring[40]; char outstring[40]; int intarg; strcpy(instring,"Testing..."); intarg = 123; /* Call Fortran routine - pass intarg by reference, pass length of outstring explicitly */ DLL_ROUT(&intarg,instring,strlen(instring),outstring,40); printf("%s\n",outstring); }
T