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. file

file

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
3 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.
  • S Offline
    S Offline
    swarup
    wrote on last edited by
    #1

    hi i want to open an exe as a file in my application. in my dialog box app there is a button when i click on that it will open a exe as a file and search for suppose "t". how can i open an exe as a file and how to replace a char or string in it. swarup

    P 1 Reply Last reply
    0
    • S swarup

      hi i want to open an exe as a file in my application. in my dialog box app there is a button when i click on that it will open a exe as a file and search for suppose "t". how can i open an exe as a file and how to replace a char or string in it. swarup

      P Offline
      P Offline
      Paolo Ponzano
      wrote on last edited by
      #2

      I think you use the GetOpenFileName() to open the exe file the you need an handle in order to open file using CreateFileA HANDLE hFile=CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL); at this point you should have an handle to your exe file, now we read it into memory using ReadFileA DWORD BR=0; //numbers of bytes read by readfile char *tempbuff=(char*)calloc(dFileSize,sizeof(char)); ReadFile(hFile, tempbuff, dFileSize, &BR, NULL); if( BR < dFileSize){ //Process the error, since not all file could have been read } now we search the string you're looking for char *p=NULL; p=strstr(tempbuff,"TEXT_TO_BE_SEARCHED"); if( p==NULL) // no TEXT_TO_BE_SEARCHED found in tempbuff else you've the first occurrence for writing you do the same using WriteFile, bye Paolo

      S 1 Reply Last reply
      0
      • P Paolo Ponzano

        I think you use the GetOpenFileName() to open the exe file the you need an handle in order to open file using CreateFileA HANDLE hFile=CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL); at this point you should have an handle to your exe file, now we read it into memory using ReadFileA DWORD BR=0; //numbers of bytes read by readfile char *tempbuff=(char*)calloc(dFileSize,sizeof(char)); ReadFile(hFile, tempbuff, dFileSize, &BR, NULL); if( BR < dFileSize){ //Process the error, since not all file could have been read } now we search the string you're looking for char *p=NULL; p=strstr(tempbuff,"TEXT_TO_BE_SEARCHED"); if( p==NULL) // no TEXT_TO_BE_SEARCHED found in tempbuff else you've the first occurrence for writing you do the same using WriteFile, bye Paolo

        S Offline
        S Offline
        swarup
        wrote on last edited by
        #3

        After reading the tempbuff. the size of it is showing as 3. i want to read the whole file. swarup

        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