LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass FILE I/O pointer to external DLL?

I'm compiling an external C++ DLL with Borland's compiler then importing the DLL into Labwindows. After I create a console application I can get the following code to successfully print to the console:
fprintf(stdout, "hello\n");

But:
OUTFILE = fopen("out.txt", "w");
fprintf (OUTFILE, "hello\n");

creates the out.txt file but nothing ever gets written to out.txt.

Are there any special requirements needed for FILE I/O or passing FILE pointers into a DLL?
0 Kudos
Message 1 of 3
(3,478 Views)
"ni user" wrote in message
news:50650000000800000082C40000-1078497998000@exchange.ni.com...
> I'm compiling an external C++ DLL with Borland's compiler then
> importing the DLL into Labwindows. After I create a console
> application I can get the following code to successfully print to the
> console:
> fprintf(stdout, "hello\n");
>
> But:
> OUTFILE = fopen("out.txt", "w");
> fprintf (OUTFILE, "hello\n");
>
> creates the out.txt file but nothing ever gets written to out.txt.
>
> Are there any special requirements needed for FILE I/O or passing FILE
> pointers into a DLL?


When you open the file to check file contents, make sure that the file was
closed after it was written. The file creaotor application also may need to
be exited before checki
ng the file.

HTH

****************
Mohan Pawar
Message 2 of 3
(3,478 Views)
I tried your solution and it works. Thank you!!!

I need to be much more careful about FILE I/O when using DLLs. So instead of passing FILE pointers into the DLL I'll close the file first in the calling routine, then pass a character string and re-open the file in the DLL, then close the file in the DLL before exiting.
0 Kudos
Message 3 of 3
(3,478 Views)