Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. I have trouble with fgets function in C code

I have trouble with fgets function in C code

Scheduled Pinned Locked Moved C#
helpcsharpc++
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dinh van hai
    wrote on last edited by
    #1

    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,

    C 1 Reply Last reply
    0
    • D dinh van hai

      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,

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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++

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups