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 / C++ / MFC
  4. read a file using Readfile()

read a file using Readfile()

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
22 Posts 7 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.
  • C chandu004

    Rajesh R Subramanian wrote:

    Just the name of the file will do, if the file is present in the same directory as the program.

    but i have a doubt here, can u please clarify, in one of my apps even i assumed so, but in the same app, if i used CFileDialog, after user selects an input file from any other folder, from tha point onwards, specifying only the file name, will give an error coz, the newly selected folder need not have that file. in this case ihad to use Getcurdirectory api. is there any other way we can reset it back? thank you.

    -------------------------------------------- Suggestion to the members: Please prefix your main thread subject with [SOLVED] if it is solved. thanks. chandu.

    O Offline
    O Offline
    Ozer Karaagac
    wrote on last edited by
    #21

    Hi, There is a flag for CFileDialog, named OFN_NOCHANGEDIR to keep current directory unchanged after file selection. It is used to form dwFlags which is 4th parameter of CFileDialog constructor. It can be used with flags member of OPENFILENAME structure for Win32 API, of course. However, you might also keep track of current directory by yourself using GetCurrentDirectory() and SetCurrentDirectory() functions.

    1 Reply Last reply
    0
    • K krmed

      I think your problem is here:

      do
      {
      i++;
      j++;
      ss[j] = ReadBuffer[i]; // Assume j now has a value of 15, so ss[15] = ReadBuffer[i]
      }while((ReadBuffer[i+1] != '\n')&&(ReadBuffer[i+1] != '\0'));

      ss[j] = '\0'; // j still has the value of 15, so you just replaced the value that was there with 0

      You didn't say if the GetModuleFileName solved your other problem or not, but I'm guessing it did. Hope that helps.

      Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

      R Offline
      R Offline
      rahuljin
      wrote on last edited by
      #22

      i try to get the ip address from a file and then make socket and send info, i want to send same info to same ip twice so i put ip "127.0.0.1" twice in the text file, but it sends info only once. here is the code ----

      #include <windows.h>
      #include <winsock.h>
      #include <stdio.h>
      #include <lm.h>
      #include <tchar.h>
      #include <wchar.h>
      #include <iostream>

      #define NETWORK_ERROR -1
      #define NETWORK_OK 0
      short int c = 1;

      void ReportError(int, const char *);
      void printServ();
      int sockpro();

      int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
      {
      while(1)
      {
      printServ();
      Sleep(1000);
      }
      return 0;
      }

      void ReportError(int errorCode, const char *whichFunc)
      {
      char errorMsg[92]; // Declare a buffer to hold
      // the generated error message

      ZeroMemory(errorMsg, 92); // Automatically NULL-terminate the string

      // The following line copies the phrase, whichFunc string, and integer errorCode into the buffer
      sprintf_s(errorMsg, "Call to %s returned error %d!", (char *)whichFunc, errorCode);

      MessageBoxA(NULL, errorMsg, "socketIndication", MB_OK);
      }

      //to print the state of required process on the server
      void printServ()
      {
      SC_HANDLE hSCM;
      SERVICE_STATUS ss;

      short int j, x;
      
      x = 1;  //Number of services.
      
      //Services to be checked.
      wchar\_t\* prName\[\] = { 
                          
                          \_T("W3SVC"),	//World Wide Web Publishing service
                      
                          };
      
          for(j=0; j<x ; j++)
          {
              //OpenSCManager establishes a connection to the service control manager on the specified computer
              //and opens the specified service control manager database and return value is a handle to the specified
              //service control manager database.
              hSCM = OpenSCManager
                      (
                      NULL,         //Name of the target computer.
                      SERVICES\_ACTIVE\_DATABASE,               //Name of the service control manager database, optional.
                      SC\_MANAGER\_CONNECT                      //Access right to the service control manager.
                      );
      		
      
              if (hSCM != NULL)
              {
                  //OpenService opens an existing service and the return value is a handle to the service.
                  SC\_HANDLE hService = OpenService
      
      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