Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem using WinMain function with C++

Problem using WinMain function with C++

Scheduled Pinned Locked Moved C / C++ / MFC
helplearningcsharpc++visual-studio
4 Posts 3 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gindi Bar Yahav
    wrote on last edited by
    #1

    Hey, i hope you can help me with my question: I started learning working with DirectX, in the start i saw a codeexample for how open an empty window (without chosing winn app at the start of Visual Studio) but for some reson, the code makes me problems, hope you can say to me why code

    #include <windows.h>

    HINSTANCE hInst; // global handle to hold the application instance
    HWND wndHandle; // global variable to hold the window handle

    // forward declarations
    bool initWindow( HINSTANCE hInstance );
    LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );

    int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow )
    {
    // Initialize the window
    if ( !initWindow( hInstance ) )
    {
    return false;
    }

    // main message loop:
    MSG msg;
    
    ZeroMemory( &msg, sizeof( msg ) );
    
    while( msg.message!=WM\_QUIT )
    {
    	// Check the message queue
    	while (GetMessage(&msg, wndHandle, 0, 0) )
    	{
    		TranslateMessage( &msg );
    		DispatchMessage( &msg );
    	}
    }
    
    return (int) msg.wParam;
    

    }

    bool initWindow( HINSTANCE hInstance )
    {
    WNDCLASSEX wcex;
    // Fill in the WNDCLASSEX structure. This describes how the window
    // will look to the system

    wcex.cbSize = sizeof(WNDCLASSEX); // the size of the structure
    wcex.style = CS\_HREDRAW | CS\_VREDRAW; // the class style
    wcex.lpfnWndProc = (WNDPROC)WndProc; // the window procedure callback
    wcex.cbClsExtra = 0; // extra bytes to allocate for this class
    wcex.cbWndExtra = 0; // extra bytes to allocate for this instance
    wcex.hInstance = hInstance; // handle to the application instance
    wcex.hIcon = 0; // icon to associate with the application
    wcex.hCursor = LoadCursor(NULL, IDC\_ARROW);// the default cursor
    wcex.hbrBackground = (HBRUSH)(COLOR\_WINDOW+1); // the background color
    wcex.lpszMenuName  = NULL; // the resource name for the menu
    wcex.lpszClassName = “DirectXExample”; // the class name being created
    wcex.hIconSm = 0; // the handle to the small icon
    RegisterClassEx( &wcex );
    // Create the window
    wndHandle = CreateWindow(
    	"DirectXExample",
    	"DirectXExample",
    	WS\_OVERLAPPEDWINDOW,
    	CW\_USEDEFAULT, // the starting x coordinate
    	CW\_USEDEFAULT, // the starting y coordinate
    	640, // the pixel width of the window
    	480, // the pixel height of the window
    	NULL, // the parent window; NULL for desktop
    	NULL, // the menu for the application; NULL for
    	hInstance, // the handle to the application instance
    	NULL); // no values passed to the windo
    
    I A 2 Replies Last reply
    0
    • G Gindi Bar Yahav

      Hey, i hope you can help me with my question: I started learning working with DirectX, in the start i saw a codeexample for how open an empty window (without chosing winn app at the start of Visual Studio) but for some reson, the code makes me problems, hope you can say to me why code

      #include <windows.h>

      HINSTANCE hInst; // global handle to hold the application instance
      HWND wndHandle; // global variable to hold the window handle

      // forward declarations
      bool initWindow( HINSTANCE hInstance );
      LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );

      int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow )
      {
      // Initialize the window
      if ( !initWindow( hInstance ) )
      {
      return false;
      }

      // main message loop:
      MSG msg;
      
      ZeroMemory( &msg, sizeof( msg ) );
      
      while( msg.message!=WM\_QUIT )
      {
      	// Check the message queue
      	while (GetMessage(&msg, wndHandle, 0, 0) )
      	{
      		TranslateMessage( &msg );
      		DispatchMessage( &msg );
      	}
      }
      
      return (int) msg.wParam;
      

      }

      bool initWindow( HINSTANCE hInstance )
      {
      WNDCLASSEX wcex;
      // Fill in the WNDCLASSEX structure. This describes how the window
      // will look to the system

      wcex.cbSize = sizeof(WNDCLASSEX); // the size of the structure
      wcex.style = CS\_HREDRAW | CS\_VREDRAW; // the class style
      wcex.lpfnWndProc = (WNDPROC)WndProc; // the window procedure callback
      wcex.cbClsExtra = 0; // extra bytes to allocate for this class
      wcex.cbWndExtra = 0; // extra bytes to allocate for this instance
      wcex.hInstance = hInstance; // handle to the application instance
      wcex.hIcon = 0; // icon to associate with the application
      wcex.hCursor = LoadCursor(NULL, IDC\_ARROW);// the default cursor
      wcex.hbrBackground = (HBRUSH)(COLOR\_WINDOW+1); // the background color
      wcex.lpszMenuName  = NULL; // the resource name for the menu
      wcex.lpszClassName = “DirectXExample”; // the class name being created
      wcex.hIconSm = 0; // the handle to the small icon
      RegisterClassEx( &wcex );
      // Create the window
      wndHandle = CreateWindow(
      	"DirectXExample",
      	"DirectXExample",
      	WS\_OVERLAPPEDWINDOW,
      	CW\_USEDEFAULT, // the starting x coordinate
      	CW\_USEDEFAULT, // the starting y coordinate
      	640, // the pixel width of the window
      	480, // the pixel height of the window
      	NULL, // the parent window; NULL for desktop
      	NULL, // the menu for the application; NULL for
      	hInstance, // the handle to the application instance
      	NULL); // no values passed to the windo
      
      I Offline
      I Offline
      I am BATMAN
      wrote on last edited by
      #2

      not sure right now about the winmain part it looks correct. The DirectXExample has to be a registered class name when you pass it to CreateWindow, it's not just some text you specify. from MSDN:

      lpClassName:
      Pointer to a null-terminated string or a class atom created by a previous call to the RegisterClass or RegisterClassEx function.
      The atom must be in the low-order word of lpClassName; the high-order word must be zero.
      If lpClassName is a string, it specifies the window class name. The class name can be any name registered with RegisterClass or RegisterClassEx,
      provided that the module that registers the class is also the module that creates the window.
      The class name can also be any of the predefined system class names.
      For a list of system class names, see the Remarks section.

      1 Reply Last reply
      0
      • G Gindi Bar Yahav

        Hey, i hope you can help me with my question: I started learning working with DirectX, in the start i saw a codeexample for how open an empty window (without chosing winn app at the start of Visual Studio) but for some reson, the code makes me problems, hope you can say to me why code

        #include <windows.h>

        HINSTANCE hInst; // global handle to hold the application instance
        HWND wndHandle; // global variable to hold the window handle

        // forward declarations
        bool initWindow( HINSTANCE hInstance );
        LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );

        int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow )
        {
        // Initialize the window
        if ( !initWindow( hInstance ) )
        {
        return false;
        }

        // main message loop:
        MSG msg;
        
        ZeroMemory( &msg, sizeof( msg ) );
        
        while( msg.message!=WM\_QUIT )
        {
        	// Check the message queue
        	while (GetMessage(&msg, wndHandle, 0, 0) )
        	{
        		TranslateMessage( &msg );
        		DispatchMessage( &msg );
        	}
        }
        
        return (int) msg.wParam;
        

        }

        bool initWindow( HINSTANCE hInstance )
        {
        WNDCLASSEX wcex;
        // Fill in the WNDCLASSEX structure. This describes how the window
        // will look to the system

        wcex.cbSize = sizeof(WNDCLASSEX); // the size of the structure
        wcex.style = CS\_HREDRAW | CS\_VREDRAW; // the class style
        wcex.lpfnWndProc = (WNDPROC)WndProc; // the window procedure callback
        wcex.cbClsExtra = 0; // extra bytes to allocate for this class
        wcex.cbWndExtra = 0; // extra bytes to allocate for this instance
        wcex.hInstance = hInstance; // handle to the application instance
        wcex.hIcon = 0; // icon to associate with the application
        wcex.hCursor = LoadCursor(NULL, IDC\_ARROW);// the default cursor
        wcex.hbrBackground = (HBRUSH)(COLOR\_WINDOW+1); // the background color
        wcex.lpszMenuName  = NULL; // the resource name for the menu
        wcex.lpszClassName = “DirectXExample”; // the class name being created
        wcex.hIconSm = 0; // the handle to the small icon
        RegisterClassEx( &wcex );
        // Create the window
        wndHandle = CreateWindow(
        	"DirectXExample",
        	"DirectXExample",
        	WS\_OVERLAPPEDWINDOW,
        	CW\_USEDEFAULT, // the starting x coordinate
        	CW\_USEDEFAULT, // the starting y coordinate
        	640, // the pixel width of the window
        	480, // the pixel height of the window
        	NULL, // the parent window; NULL for desktop
        	NULL, // the menu for the application; NULL for
        	hInstance, // the handle to the application instance
        	NULL); // no values passed to the windo
        
        A Offline
        A Offline
        Adam Maras
        wrote on last edited by
        #3

        Gindi Bar Yahav wrote:

        Error 2 error C2065: '“DirectXExample”' : undeclared identifier c:\users\יהב\documents\visual studio 2008\projects\learningdirectx\learningdirectx\winmain.cpp 56 LearningDirectX

        It looks like you're using some abnormal quotation marks around your string constant; make sure you're using regular quotes and not smart quotes. Aside from that, make sure you're not compiling the program as UNICODE (unless you want to change your WinMain function to _tWinMain and wrap all your string constants with the TEXT(...) macro.)

        G 1 Reply Last reply
        0
        • A Adam Maras

          Gindi Bar Yahav wrote:

          Error 2 error C2065: '“DirectXExample”' : undeclared identifier c:\users\יהב\documents\visual studio 2008\projects\learningdirectx\learningdirectx\winmain.cpp 56 LearningDirectX

          It looks like you're using some abnormal quotation marks around your string constant; make sure you're using regular quotes and not smart quotes. Aside from that, make sure you're not compiling the program as UNICODE (unless you want to change your WinMain function to _tWinMain and wrap all your string constants with the TEXT(...) macro.)

          G Offline
          G Offline
          Gindi Bar Yahav
          wrote on last edited by
          #4

          Thanks!! you solved me the problem. i clicked properties and the "charset" was unicode, so i changed to multy-byte charcters (its ok?) but now its compiling me with no error, now i can go back to learn, thanks.

          Gindi Bar Yahav - Web & Software defeloper.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups