Thread: Error when following tutorial

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    6

    Error when following tutorial

    Hi, my name's Daggio and I'm new here
    nice to meet you

    I just follow a tutorial at http://www.cprogramming.com/tutorial...ogramming.html

    and encountered an error like this:

    1>c:\documents and settings\yadhiek\my documents\visual studio 2008\projects\cpopengl\cpopengl\belajar.cpp(5) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [14]' 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://c:\Documents and Settings\Yadhiek\My Documents\Visual Studio 2008\Projects\CPOpenGL\CPOpenGL\Debug\BuildLog.htm "
    1>CPOpenGL - 1 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    and this is my code

    Code:
    #include <windows.h>
    
    int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
    {
    	MessageBox(NULL,"\tHello World!","My first windows app",NULL);
    	return 0;
    }
    line 5 is the
    Code:
    MessageBox(NULL,"\tHello World!","My first windows app",NULL);
    I don't know what went wrong, I've followed everything in the tutorial.

    thanks before

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Go into project options -> general -> character set -> change from unicode to multi-byte and it should work.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    6
    It worked! thanks Elysia

    er....I'm allowed to write one line post if it's a thank you right?
    but then again, this is no longer a one line post ^^;

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Sure, if you write something useful or thank someone.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    6
    er... I encountered an error again, this time when following the next tutorial (it's at http://www.cprogramming.com/tutorial...ndows_app.html )

    actually, everything worked fine... except for the window disappeared in a blink of an eye

    I've read the FAQ and it suggest me three things. The first was to open in via command prompt, I've tried this and still the same... gone in a blink of an eye... literally ^^;

    then I tried the next way, to stop it as if it's waiting for user input... I included the
    Code:
    #include <stdlib>
    and right before
    Code:
    return msg.wParam;
    I wrote
    Code:
    system("PAUSE");
    so the last lines of my code looked like this
    Code:
    system("PAUSE");
    return msg.wParam;
    but the result is pretty much the same.. I can see the window now it's just there's also a console window with a string of "Press any key to continue..." appearing

    and oh yeah... the window is not responding, I've checked this using windows task manager

    any help would be appreciated
    thanks before guys

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You need to make sure the message loop is running.
    As long as the window is visible and recieves messages, the message pump will continue to block.
    The message pump is this:
    Code:
    	while(!done)
    	{
    		PeekMessage(&msg,hwnd,NULL,NULL,PM_REMOVE);
    		if (msg.message == WM_QUIT) //check for a quit message
    		{
    			done = true; //if found, quit app
    		}
    		else
    		{
    			/*	Translate and dispatch to event queue*/
    			TranslateMessage(&msg); 
    			DispatchMessage(&msg);
    		}
    	}
    The FAQ solutions are for CLI-type apps only and won't work for GUI-apps.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Jan 2008
    Posts
    6
    it worked! thanks Elysia

    the error turned to be a typo, I typed '=' instead of '=='

    my bad ^^;

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You know that if you turn up warnings to max, the compiler will warn if you use = instead of == in ifs.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My new website
    By joeprogrammer in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 03-17-2006, 07:38 PM
  2. Cprog tutorial: Design Patterns
    By maes in forum C++ Programming
    Replies: 7
    Last Post: 10-11-2004, 01:41 AM
  3. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  4. Problem with tutorial (Vector class)
    By OdyTHeBear in forum C++ Programming
    Replies: 4
    Last Post: 12-18-2002, 02:49 PM
  5. My DirectInput tutorial....
    By jdinger in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 06-18-2002, 11:32 PM