String tables doesn't work. Reading a tutorial...

This is a discussion on String tables doesn't work. Reading a tutorial... within the Windows Programming forums, part of the Platform Specific Boards category; I am learning Win32 programming by reading a tutorial, and I came to a point where they teach you about ...

  1. #1
    Novice programmer newn's Avatar
    Join Date
    Aug 2010
    Posts
    59

    String tables doesn't work. Reading a tutorial...

    I am learning Win32 programming by reading a tutorial, and I came to a point where they teach you about string tables. I am using Visual Studio 2010.
    The error is that LPWSTR isn't compatible with an argument type of char. My guess is that the code is outdated, as the tutorial was created using Visual Studio 6. How can I make it work?
    Here is the code:
    Code:
    //---------------------------------------------------------------------------
    #include <windows.h>
    #include "resource.h"
    
    //---------------------------------------------------------------------------
    char AppCaption[40];
    LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg,
    			      WPARAM wParam, LPARAM lParam);
    //---------------------------------------------------------------------------
    INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
    	MSG        Msg;
    	HWND       hWnd;
    	WNDCLASSEX WndClsEx;
    	LPCTSTR ClsName = L"ResFund";
    
    	LoadString(hInstance, IDS_APP_NAME, AppCaption, 40); // This is where the first error comes in - on 'AppCaption'.
    
    	// Create the application window
    	WndClsEx.cbSize        = sizeof(WNDCLASSEX);
    	WndClsEx.style         = CS_HREDRAW | CS_VREDRAW;
    	WndClsEx.lpfnWndProc   = WndProcedure;
    	WndClsEx.cbClsExtra    = 0;
    	WndClsEx.cbWndExtra    = 0;
    	WndClsEx.hIcon         = LoadIcon(hInstance,
    				 MAKEINTRESOURCE(IDI_RESFUND2));
    	WndClsEx.hCursor       = LoadCursor(NULL, IDC_ARROW);
    	WndClsEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    	WndClsEx.lpszMenuName  = MAKEINTRESOURCE(IDR_MAINFRAME);
    	WndClsEx.lpszClassName = ClsName;
    	WndClsEx.hInstance     = hInstance;
    	WndClsEx.hIconSm       = LoadIcon(hInstance,
    					  MAKEINTRESOURCE(IDI_RESFUND2));
    
    	// Register the application
    	RegisterClassEx(&WndClsEx);
    
    	// Create the window object
    	hWnd = CreateWindowEx(0,
                                  ClsName,
                                  AppCaption,
                    	      WS_OVERLAPPEDWINDOW,
                                  CW_USEDEFAULT,
                                  CW_USEDEFAULT,
                                  CW_USEDEFAULT,
                                  CW_USEDEFAULT,
                                  NULL,
                                  NULL,
                                  hInstance,
                                  NULL);
    	
    	// Find out if the window was created
    	if( !hWnd ) // If the window was not created,
    		return FALSE; // stop the application
    
    	// Display the window to the user
    	ShowWindow(hWnd, nCmdShow);// SW_SHOWNORMAL);
    	UpdateWindow(hWnd);
    
    	// Decode and treat the messages
    	// as long as the application is running
    	while( GetMessage(&Msg, NULL, 0, 0) )
    	{
                 TranslateMessage(&Msg);
                 DispatchMessage(&Msg);
    	}
    
    //	return Msg.wParam;
        return 0;
    }
    //---------------------------------------------------------------------------
    LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg,
    			   WPARAM wParam, LPARAM lParam)
    {
        switch(Msg)
        {
        case WM_DESTROY:
            PostQuitMessage(WM_QUIT);
            break;
        default:
            // Process the left-over messages
            return DefWindowProc(hWnd, Msg, wParam, lParam);
        }
        // If something was not done, let it go
        return 0;
    }
    //---------------------------------------------------------------------------
    Last edited by newn; 04-18-2011 at 05:43 AM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    Modern visual studio implementations default to using UNICODE, where VC6 used plain old ASCII.

    visual studio - How do I turn off Unicode in a VC++ project? - Stack Overflow

    Or you could just make your code UNICODE compatible by using _T or _TEXT
    Unicode Programming Summary
    Generic-Text Mappings in Tchar.h
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Novice programmer newn's Avatar
    Join Date
    Aug 2010
    Posts
    59
    Turning the code into Unicode was too complicated for me at this point, so I turned the Unicode off.
    The program works fine now.
    Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 12-07-2010, 05:53 AM
  2. how do hash tables work?
    By c_weed in forum C++ Programming
    Replies: 3
    Last Post: 08-31-2010, 01:57 PM
  3. Why doesn't this work - about tables
    By Slither in forum C Programming
    Replies: 2
    Last Post: 10-25-2007, 02:47 PM
  4. String tables in console apps
    By Sentral in forum C++ Programming
    Replies: 3
    Last Post: 10-16-2006, 04:08 AM
  5. my function doesn't work! it should work
    By Unregistered in forum C Programming
    Replies: 13
    Last Post: 05-02-2002, 02:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21