Link to home
Start Free TrialLog in
Avatar of billskeen68
billskeen68

asked on

Use fopen() from c#

I have a 'c' dll that requires a FILE * fileHandle to be passed into a function. I want to use c# to do the fopen() or whatever from C#, then trough DLLIMPORT, call the 'c' function with the fileHandle created. Same applies for fclose().

Thanks,

Bill
Avatar of AlexFM
AlexFM

fopen is function from C runtime library (CRT). It is impossible to call it using PInvoke. You need to write Dll in C++ which has exported function, this function calls fopen and returns FILE*. Call this function from C# client.
Think about using managed C++, which has better interoperability features than C# and allows to call C++ functions and classes directly.
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of billskeen68

ASKER

The fopen()/fclose() work okay from C#, but the passinig IntPtr down doesn't work. Don't I need to create some type of structure for FILE?

Bill
Please show your code and describe what error you have.
iam not able to open a file using fopen in windows DDK , inspite of setting the MSVCRT=1 the sources file, do i have to set any other variable for the file operations to work?

Thank you

FILE *fp;
fp= fopen("ubl_davinci_nor.BIN", "r");
sources