@ limburger Parsing Text File Contents

Sorry I had to start a new thread. There's a forum bug which blocks me from replying in the original thread:
http://www.cplusplus.com/forum/windows/139091/


I was hoping to find a complete compilable, runnable program, such as this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <windows.h>
#include <iostream>
#include <fstream>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) 
{
    std::ifstream ifs("E:\\StateFile.txt");
    
    if (ifs.is_open())    
        MessageBoxA(NULL, "StateFile Opened", "Information", MB_ICONINFORMATION);
    else
        MessageBoxA(NULL, "StateFile could not be opened", "Error", MB_ICONERROR);
     
    return 0;
}


Now that code works ok. However, If I add an extra line, like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <windows.h>
#include <iostream>
#include <fstream>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) 
{

    HANDLE StateFile = CreateFile("E:\\StateFile.txt", GENERIC_ALL, 0, NULL, 
        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, SECURITY_ANONYMOUS); 

    std::ifstream ifs("E:\\StateFile.txt");
    
    if (ifs.is_open())    
        MessageBoxA(NULL, "StateFile Opened", "Information", MB_ICONINFORMATION);
    else
        MessageBoxA(NULL, "StateFile could not be opened", "Error", MB_ICONERROR);
     
    return 0;
}
then it will fail. There's no reason to use both the Windows as well as the C++ stream to access the file. The CreateFile() here grabs exclusive control of the file, thus preventing any other access.
hmm I took out the statefile script and it still failed on reboot. did you want me to post the entire code? Its about 300 lines haha.
did you want me to post the entire code? Its about 300 lines haha.

I was hoping you would post the entire code, with all the non-relevant parts removed. As it is, the code which I'm running is not the same as the code which you are running, so there's little chance of finding a solution.
hmm did you maybe want to pm me your email address and i can send you the .cpp? I don't want giving you anything that might be important, up to you otherwise I can post the script in here.
actually I tested it a few more times after that and it is opening the statefile and reporting the values so I think that part is good. Is there a way that following it reading those values I can have it go to the CASE ID_INSTALL:? Or is there some other way I should have it initilize installing again?
I'm glad that the original problem is apparently resolved.

As for the follow-up question, i feel I'm out of my depth here. Either my knowledge of Windows software development isn't great enough (others here may be better placed), or a lack of a clear view of the code as a whole leaves me a bit out of my depth here. I was certainly willing to follow up on the original question, but maybe it's time for me to withdraw, rather than promise something I can't deliver.
Topic archived. No new replies allowed.