I have trouble with fgets function in C code
-
Hi, In C# code I declared like this: [DllImport("mydll.dll")] public static extern int SearchString(out double x); And I called the function: double m_vo2Max=1; SearchString(out m_vo2Max); The SearchString function is on the mydll.dll. This dll is written in VC++ and the description is here: #include "stdafx.h" #include BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } int WINAPI SearchString (double &X) { FILE *F; char szString[255]; F= fopen("C:\\ParaLimit1.tbf", "rt"); fgets(szString, 255, F); fclose(F); return 1; } I always have an error : System.NullReferenceException Additional Information : Object reference not set to an instance of an object. I checked and found out that the error in the code below: fgets(szString, 255, F); Can you help me to solve this error. Thank you,
-
Hi, In C# code I declared like this: [DllImport("mydll.dll")] public static extern int SearchString(out double x); And I called the function: double m_vo2Max=1; SearchString(out m_vo2Max); The SearchString function is on the mydll.dll. This dll is written in VC++ and the description is here: #include "stdafx.h" #include BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } int WINAPI SearchString (double &X) { FILE *F; char szString[255]; F= fopen("C:\\ParaLimit1.tbf", "rt"); fgets(szString, 255, F); fclose(F); return 1; } I always have an error : System.NullReferenceException Additional Information : Object reference not set to an instance of an object. I checked and found out that the error in the code below: fgets(szString, 255, F); Can you help me to solve this error. Thank you,
Why are you using C file handling instead of C++ ? You should check if F is NULL, perhaps that's where the real problem is. Christian Graus - Microsoft MVP - C++