New WinMain?

Hi, I'm trying to test out a chapter of a directx book, and I get errors like I can't overload winmain. Why is this happening When I go back to my old vc++ 6.0, it compiles fine (there's a linking error, but that has to do with directx 9 not being supported).

I mean, this shouldn't be that difficult, should it I've started a new, empty win32 application (not console). I create a new, blank file called winmain.cpp and I paste in the code. I compile it and it spits out a bunch of errors:

1>winmain.cpp

1>c:\documents and settings\jombee\my documents\visual studio 2005\projects\erase_me_2\erase_me_2\winmain.cpp(32) : error C2731: 'WinMain' : function cannot be overloaded

1> c:\documents and settings\jombee\my documents\visual studio 2005\projects\erase_me_2\erase_me_2\winmain.cpp(29) : see declaration of 'WinMain'

1>c:\documents and settings\jombee\my documents\visual studio 2005\projects\erase_me_2\erase_me_2\winmain.cpp(35) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [24]' to 'LPCWSTR'

1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

1>c:\documents and settings\jombee\my documents\visual studio 2005\projects\erase_me_2\erase_me_2\winmain.cpp(41) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [24]' to 'LPCWSTR'

1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

1>c:\documents and settings\jombee\my documents\visual studio 2005\projects\erase_me_2\erase_me_2\winmain.cpp(88) : error C2440: '=' : cannot convert from 'const char [15]' to 'LPCWSTR'

1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

1>c:\documents and settings\jombee\my documents\visual studio 2005\projects\erase_me_2\erase_me_2\winmain.cpp(103) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [15]' to 'LPCWSTR'

1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Did all of the types get changed when I wasn't looking Any help would be most appreciated!



Answer this question

New WinMain?

  • Mohit Bhardwaj

    I hate to ask, but could you be more specific Do you mean while working in the project go to Project-> <Project_name> Properties-> and then where

    I've got the directx sdk with october 2005 addition. I tried to download the december sdk but it would not let me saying that it's digital signature was wrong.

  • the head guy

    A linking error means that your code can see the header files to compile the code, but at link time, when it actually tries to find the code to call when those functions are references, it cannot find them, either in .cpp files, or linked in a .lib file. So, you need to go to your project properties, and set the path to the lib directory in the DirectX sdk as a path for lib files.

    The trouble with ANSI is that it allows for 255 characters only, which is fine for English, doesn't work for other languages. UNICODE uses 2 bytes per character, and therefore can cover chinese, japanese, etc.



  • chileto7

    An overload means that Winmain occurs twice in your application.

    It's often the case that such a fundamental error causes a lot of other errors to be generated.

    However, some of your problems are to do with calling stuff like MessageBox, which was calling MessageBoxA, but in this new project is calling MessageBoxW. Wrap text in the _TEXT macro to make this always work, as in

    AfxMessageBox(_TEXT("Show this"));

    In other words, your new project is UNICODE and your old one was not.



  • frdyr

    Look carefully at the lpCmdLine argument. Its type should be LPSTR. It is ALWAYS passed as a 'narrow' string, even if you compile for unicode. To get the unicode command line, make a call to GetCommandLineW from within WinMain.

    As Christian said, your new application is being compiled with UNICODE defined. That means that most Windows APIs that take string arguments will expect unicode strings (WinMain is special as mentioned above). This is the default for new VC++ express applications, whereas in VC6, the default was to use ANSI (narrow) strings. You can change this in the project properties dialog. Look under "Configuration Properties\General" for the "Character Set" property and change it to "Use multibyte character set" or "Not set".



  • vikki_k1

    Thanks for getting back to me cgraus.

    There's only one Winmain in my app:

    /*********************************************************************
    * WinMain
    *********************************************************************/
    int WINAPI WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPTSTR lpCmdLine, int nCmdShow)
    {
    if (!initWindow(hInstance))
    {
    MessageBox(NULL, "Unable to create window", "ERROR", MB_OK);
    return false;
    }

    ...

    I'm unfamiliar with the difference between UNICODE and otherwise and with the calls to things such as AfxMessageBox. Is there anyway to, I don't know, switch a project variable so that this code would work Is it because of the Platform SDK I'm still confused by this error stuff.

    Thanks again!



  • Walter Sobcak

    I don't have express, but in the VSTS edition, it's tools/options/Projects and Solutions/VC++ directories

    then there's a combo box, which I use to select Library files, and one of my paths there is C:\Program Files\Microsoft SDKs\DX9\Lib



  • Avilash

    Ok, I got it to link by doing this:

    Project-> <project_name> Properties (the last one in there)

    Then I expanded Linker->Input and then in the Additional Dependencies spot I entered:

    d3d9.lib

    This made the project compile, link and execute without any errors. I've got my first directx program to work!

    Thanks for all your help!

  • Tany Pham

    Okay, that solved that problem. Now, there's just one more thing and it has to do with DirectX. I'm getting a linking error:

    error LNK2019: unresolved external symbol _Direct3DCreate9@4 referenced in function "bool __cdecl initDirect3D(void)" ( initDirect3D@@YA_NXZ)

    Do I have to make some sort of explicit call to Direct3D or add another lib or something

    You guys have been a great help. Thank you very much.

    Oh, and one question...why was the decision made to go to UNICODE as opposed to "regular" ANSI

  • New WinMain?