01-12-2009 11:08 AM
Hello,
I'm looking to implement the GNU function "getline()" in CVI and the function starts like:
getline.dll:
LIBAPI ssize_t WINAPI getline(char **lineptr, size_t *n, FILE *stream) {
int c;
while (TRUE) {
c = fgetc(stream); // Error occurs here
...
}
}
(LIBAPI is DLLEXPORT or DLLIMPORT.) This is then compiled as a DLL and put somewhere global. Then I have another DLL that does this:
driver.dll:
int ReadWaveform(void) {
FILE *fwave;
char *lineptr = NULL;
int n = 0;
fwave = fopen("waveform.txt", "r");
len = getline(&lineptr, &n, fwave);
...
}
I get the error "Argument must be an open stream" when the function "fgetc()" is called. If this fgetc() is put into the function ReadWaveform() it doesn't produce an error. The file exists, it's readable (the file permissions are read-only, but read/write doesn't change behaviour either). Both libraries are compiled as debug (or the getline.dll has also been compiled as release, but doesn't change in that the file can't be read and fgetc() reports EOF immediately as it should on error).
So there appears to be some cross DLL boundary issues when working with file streams if open the stream in DLL driver.dll and work with it in getline.dll. I haven't had this problem with other C languages.
any help on this issue would be appreciated. I'm using CVI 9.0 on WinXP.
Thanks,
Jason.
Solved! Go to Solution.
01-13-2009 11:34 AM
01-14-2009 03:48 AM
Yes - the different run time engines is important. They both need to be the same (which for generalisation, therefore need to be the full runtime engine). Then the FILE pointer can be shared.