# Unicode WinMain()

## Recommended Posts

beebs1    398
Hiya, I believe there is a C++ function which can be used in place of WinMain, which accepts a wide character command-line argument, but I can't seem to find anything about it. Can anyone tell me what the function declaration is? I think I've seen it before as int APIENTRY tWinMain( /*something something*/ );, but I could be wrong. Thanks for any help :) James.

##### Share on other sites
From MSDN:

[...]
This means that WinMain cannot be used by Unicode programs. The GetCommandLineW function can be used to obtain the command line as a Unicode string. Some programming frameworks might provide an alternative entry point that provides a Unicode command line. For example, the Microsoft Visual Studio C++ complier uses the name wWinMain for the Unicode entry point.

##### Share on other sites
beebs1    398
Thanks, that's exactly what I was looking for. Rating++ [smile]

If I can change the topic slightly, I've been trying to write a simple algorithm to read in record structures from a file, but I've come across a problem. I open the file using std::ifstream, and then use this:

std::ifstream in( L"test.txt", std::ios::in | std::ios::binary );if( !in.is_open() ) return false;// read in the file record by recordwhile( !in.eof() ){    // read in various values...}

Because the EOF flag is only set when you try to read past the end of the file, it always tries to read one record too many. Can anyone suggest a way of correcting this?

Thanks again.

##### Share on other sites
std::ifstream in( L"test.txt", std::ios::in | std::ios::binary );if( !in.is_open() ) return false;// read in the file record by recordwhile( !in.eof() ){   // Try to read -- EOF set if past the end of the file   if (!in.eof)       // read in various values...}

It's not the tidiest, but as far as I know it's the only way to do it (although another alternative, which is probably better, would be to use the same technique but extract it to some sort of 'getSize' function, and then loop until you reach that size).

beebs1    398
Thanks.