der Einstieg in die WinAPI...



  • Hi,
    wollte mich mal reinarbeiten in die WinAPI-Welt und hab ein paar tutorials ausfindig gemacht, aber bei jedem Tutorial die eine MessageBox herzaubern soll, bekomme ich nur eine Fehlermeldung.

    Und zwar dieser Code:

    #include <windows.h>
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
    {
    	MessageBox(NULL,"Hello, Windows 98","Hello World",0);
    }
    

    Fehlermeldung:
    1>------ Build started: Project: winapi01, Configuration: Debug Win32 ------
    1>Compiling...
    1>winmain.cpp
    1>e:\projekt\tests\winapi01\winapi01\winmain.cpp(6) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [18]' to 'LPCWSTR'
    1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    1>Build log was saved at "file://e:\Projekt\tests\winapi01\winapi01\Debug\BuildLog.htm"
    1>winapi01 - 1 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    --->>> cannot convert parameter 2 from 'const char [18]' to 'LPCWSTR' <<<---

    Muss ich noch was beim Projekt einstellen?

    VLG,
    Cyrill



  • Du hast wahrscheinlich das UNICODE Charset eingestellt (ist Default beim 2005).
    Findeste in den Projektoptionen



  • Ah ok... funktioniert. Danke dir. Warum ist das so? Für was brauche ich den UNICODE?



  • Die WinAPI (bzw. besser gesagt das PSDK) basiert auf TCHAR... d.h. Du musst z.B. bei String-Literalen alles in das "_T" makro packen... also =>

    #include <windows.h>
    #include <tchar.h>
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
    {
        MessageBox(NULL, _T("Hello, Windows 98"), _T("Hello World"), 0);
    }
    

    Siehe:
    http://msdn2.microsoft.com/c426s321

    PS: Heute sollte man immer UNICODE verwenden, wenn Du auch andere Sprachen als english unterstützen willst..



  • Ok, danke dir. Gut zu wissen.

    Also vielen Dank für eure Hilfe. Muss man ja vorher wissen. 🙂



  • Ah ja, wieder was gelernt..Danke Jochen


Anmelden zum Antworten