ReadFile Problem

S

Spacetech

Im trying to make it so I can read something out of a file and get it
into a string so I can see if It matches what IM looking for.

Here is what I got:

HANDLE hFile;
DWORD wmWritten;
char strVal[1024];
hFile =
CreateFile("settings.ini",GENERIC_READ|GENERIC_WRITE,

0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);

if(ReadFile(hFile,strVal,1024,&wmWritten,NULL) ==
"ontop=1"){
AppendMenu(hSubMenu, MF_STRING|MF_CHECKED, TOP,
"&Always On Top");
}
else if(ReadFile(hFile,strVal,1024,&wmWritten,NULL) ==
"ontop=0"){
AppendMenu(hSubMenu, MF_STRING|MF_UNCHECKED, TOP,
"&Always On Top");
}
else{
AppendMenu(hSubMenu, MF_STRING|MF_CHECKED, TOP,
"&Always On Top");
}

I got this: "error: ISO C++ forbids comparison between pointer and
integer"
I am useing Code::Blocks v1.0

Please Help
 
L

leconte

Spacetech said:
Im trying to make it so I can read something out of a file and get it
into a string so I can see if It matches what IM looking for.

Here is what I got:

HANDLE hFile;
DWORD wmWritten;
char strVal[1024];
hFile =
CreateFile("settings.ini",GENERIC_READ|GENERIC_WRITE,

0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);

if(ReadFile(hFile,strVal,1024,&wmWritten,NULL) ==
"ontop=1"){
i think this should be the problem. The return value of ReadFile can't
compare with a string "ontop"
 
J

Jonathan Mcdougall

Spacetech said:
Im trying to make it so I can read something out of a file and get it
into a string so I can see if It matches what IM looking for.

You are using Windows specific features which are off-topic in this
newsgroup. Either switch to standard constructs (std::ifstream,
std::string and std::getline) or ask elsewhere
(http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9).
Here is what I got:

if(ReadFile(hFile,strVal,1024,&wmWritten,NULL) ==
"ontop=1"){
I got this: "error: ISO C++ forbids comparison between pointer and
integer"

Looks like the function ReadFile() returns an integer and that you are
comparing it with "ontop=1", which is a pointer (const char*). Check
the documentation on this function.


Jonathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top