!@#*$(@_$*@!! ARFGGHHFF!!@

Posts 1–13 of 13 · Page 1 of 1
!@#*$(@_$*@!! ARFGGHHFF!!@
Bear with me while I vent for a second....

Why Does windows have to be so godam hard! I'm trying to get this to compile right?
Code:
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
	MessageBox(NULL, "Motoko Kusanagi has hacked your system!", "Public Security Section 9", MB_OK | MB_ICONEXCLAMATION);
}
Seems easy enough right, well I got so many fkin errors! I had to completely ReInstall Visual Studios, MANUAL SET 10 different file paths! Including cmd.exe FFS! And If that wasn't enough I still had this error when I tried to compile!!
Code:
'MessageBoxW' : cannot convert parameter 2 from 'const char [40]' to 'LPCWSTR'
So you know what I do? I fkin cast the dam strings then... I figure "Hell Windows if it makes you fkin happy I'll do it!"
Code:
MessageBox(NULL, (LPCWSTR)"Motoko Kusanagi has hacked your system!", (LPCWSTR)"Public Security Section 9", MB_OK | MB_ICONEXCLAMATION);
And you know what happens?!....It compiles.. THANK GOD! But then when I run the program the goddam things Comes out in Japenese!!!!

WAHT THE FUCK!!! WHAT THE FAKK!!! Wat the fuakkk!!!! D:

So I spend a whole fkin hour looking up error solution on the web! and finally I find out how to do the dam thing correctly:
Code:
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
	MessageBox(NULL, L"Motoko Kusanagi has hacked your system!", L"Public Security Section 9", MB_OK | MB_ICONEXCLAMATION);
}
AND THAT WAS MY FKIN INTRODUCTION TO WINDOWS PROGRAMMING. Godammit! D;
=)....

Ive told you about this before but you always ignore me and think i'm crazy

But yeah L"String" is one way, another way is TEXT("string") Macro, and another way i recently discovered is to set the character set from Unicode to multibyte in the project properties =).

I dunno maybe i'm magical. But i rarely have problems with Visual Studio. And when i do I find them fairly easy to fix.

Welcome to windows =D
Well I suppose one good thing did come out of this:


I was finally able to express my true feelings to Windows... :l
xD im starting to think that all coders have anger problems >_>"
Think of the L prefix as 'long string'. Meaning, two bytes a character. If you want to use ascii, use MessageBoxA. It defaults to MessageBoxW because you're set to a unicode build.

TEXT is a macro, when programming with the win32 API, all text should be surrounded with the TEXT() macro, to ease transition between unicode and multibyte builds.
Quote Originally Posted by radnomguywfq3 View Post
Think of the L prefix as 'long string'. Meaning, two bytes a character. If you want to use ascii, use MessageBoxA. It defaults to MessageBoxW because you're set to a unicode build.

TEXT is a macro, when programming with the win32 API, all text should be surrounded with the TEXT() macro, to ease transition between unicode and multibyte builds.
Oh thanks a lot. Anything else I should know before I get screwed over again?
Why do you think most people when they have the option to use something else like MFC/.NET use that instead when it comes to writing windows apps?
Though you can do some pretty powerful things if you deal with it directly.
Just take baby-steps.. you'll get there
Quote Originally Posted by B1ackAnge1 View Post
Why do you think most people when they have the option to use something else like MFC/.NET use that instead when it comes to writing windows apps?
Though you can do some pretty powerful things if you deal with it directly.
Just take baby-steps.. you'll get there
I need my baby booties... so I don't hurt myself. ;l

Anyway I started on chapter 3 of my book today and it was still frustrating, but I guess I knew how to handle it this time, even though it did get a little frustrating:

This is the code that came in the book:
Code:
// Beginning Game Programming
// Chapter 3
// WindowTest program

//header files to include
#include <windows.h>
#include <stdlib.h>
#include <time.h>

//application title
#define APPTITLE "Hello World"

//function prototypes (forward declarations)
BOOL InitInstance(HINSTANCE,int);
ATOM MyRegisterClass(HINSTANCE);
LRESULT CALLBACK WinProc(HWND,UINT,WPARAM,LPARAM);


//the window event callback function
LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hdc;
	char *szHello = "Hello World!";
	RECT rt;
	int x, y, n;
	COLORREF c;

	switch (message)
	{
		case WM_PAINT:
			//get the dimensions of the window
            Ge***ientRect(hWnd, &rt);

            //start drawing on device context
            hdc = BeginPaint(hWnd, &ps);

			//draw some text
			DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);

			//draw 1000 random pixels
			for (n=0; n<3000; n++)
			{
				x = rand() % (rt.right - rt.left);
				y = rand() % (rt.bottom - rt.top);
				c = RGB(rand()%256, rand()%256, rand()%256);
				SetPixel(hdc, x, y, c);
			}

            //stop drawing
			EndPaint(hWnd, &ps);
			break;

		case WM_DESTROY:
			PostQuitMessage(0);
			break;
    }
    return DefWindowProc(hWnd, message, wParam, lParam);
}

//helper function to set up the window properties
ATOM MyRegisterClass(HINSTANCE hInstance)
{
    //create the window class structure
    WNDCLASSEX wc;
    wc.cbSize = sizeof(WNDCLASSEX); 

    //fill the struct with info
    wc.style         = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc   = (WNDPROC)WinProc;
    wc.cbClsExtra	 = 0;
    wc.cbWndExtra	 = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = NULL;
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = APPTITLE;
    wc.hIconSm       = NULL;

    //set up the window with the class info
    return RegisterClassEx(&wc);
}

//helper function to create the window and refresh it
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   //create a new window
   hWnd = CreateWindow(
       APPTITLE,              //window class
       APPTITLE,              //title bar
       WS_OVERLAPPEDWINDOW,   //window style
       CW_USEDEFAULT,         //x position of window
       CW_USEDEFAULT,         //y position of window
       500,                   //width of the window
       400,                   //height of the window
	   NULL,                  //parent window
       NULL,                  //menu
       hInstance,             //application instance
       NULL);                 //window parameters

   //was there an error creating the window?
   if (!hWnd)
      return FALSE;

   //display the window
   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}


//entry point for a Windows program
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR     lpCmdLine,
                   int       nCmdShow)
{
    // declare variables
	MSG msg;

	// register the class
	MyRegisterClass(hInstance);

    // initialize application
	if (!InitInstance (hInstance, nCmdShow)) 
		return FALSE;

	//set random number seed
	srand(time(NULL));

    // main message loop
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return msg.wParam;
}
And this is what I had to do to get it working:
Code:
// Beginning Game Programming
// Chapter 3
// WindowTest program

//header files to include
#include <windows.h>
#include <stdlib.h>
#include <time.h>

//application title
#define APPTITLE "Hello World"

//function prototypes (forward declarations)
BOOL InitInstance(HINSTANCE,int);
ATOM MyRegisterClass(HINSTANCE);
LRESULT CALLBACK WinProc(HWND,UINT,WPARAM,LPARAM);


//the window event callback function
LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hdc;
	char *szHello = "Hello World!";
	RECT rt;
	int x, y, n;
	COLORREF c;

	switch (message)
	{
		case WM_PAINT:
			//get the dimensions of the window
            Ge***ientRect(hWnd, &rt);

            //start drawing on device context
            hdc = BeginPaint(hWnd, &ps);

			//draw some text
			DrawTextA(hdc, szHello, strlen(szHello), &rt, DT_CENTER);

			//draw 1000 random pixels
			for (n=0; n<3000; n++)
			{
				x = rand() % (rt.right - rt.left);
				y = rand() % (rt.bottom - rt.top);
				c = RGB(rand()%256, rand()%256, rand()%256);
				SetPixel(hdc, x, y, c);
			}

            //stop drawing
			EndPaint(hWnd, &ps);
			break;

		case WM_DESTROY:
			PostQuitMessage(0);
			break;
    }
    return DefWindowProcA(hWnd, message, wParam, lParam);
}

//helper function to set up the window properties
ATOM MyRegisterClass(HINSTANCE hInstance)
{
    //create the window class structure
    WNDCLASSEXA wc;
    wc.cbSize = sizeof(WNDCLASSEXA); 

    //fill the struct with info
    wc.style         = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc   = (WNDPROC)WinProc;
    wc.cbClsExtra	 = 0;
    wc.cbWndExtra	 = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = NULL;
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = APPTITLE;
    wc.hIconSm       = NULL;

    //set up the window with the class info
    return RegisterClassExA(&wc);
}

//helper function to create the window and refresh it
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   //create a new window
   hWnd = CreateWindowA(
       APPTITLE,              //window class
       APPTITLE,              //title bar
       WS_OVERLAPPEDWINDOW,   //window style
       CW_USEDEFAULT,         //x position of window
       CW_USEDEFAULT,         //y position of window
       500,                   //width of the window
       400,                   //height of the window
	   NULL,                  //parent window
       NULL,                  //menu
       hInstance,             //application instance
       NULL);                 //window parameters

   //was there an error creating the window?
   if (!hWnd)
      return FALSE;

   //display the window
   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}


//entry point for a Windows program
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR     lpCmdLine,
                   int       nCmdShow)
{
    // declare variables
	MSG msg;

	// register the class
	MyRegisterClass(hInstance);

    // initialize application
	if (!InitInstance (hInstance, nCmdShow)) 
		return FALSE;

	//set random number seed
	srand(time(NULL));

    // main message loop
	while (GetMessageA(&msg, NULL, 0, 0)) 
	{
		TranslateMessage(&msg);
		DispatchMessageA(&msg);
	}

	return msg.wParam;
}
I suppose it's not terrible, its just tough to grasp some of the big points or even completely understand what's going on when dealing when you have to deal with all these errors on top of first being exposed to Windows. Anyway I have found one function of Visual C++ very helpful. Right Click >> Look up Definition. Some of the definitions go all the way back to Windows NT, and I have no idea how they are defined really... as far as what kind of actual size in bytes certain variables are, and I have a feeling hardly anyone does o_O?!
look into MSDN w/e u dont know btw what book are u reading.
Quote Originally Posted by Matrix_NEO006 View Post
look into MSDN w/e u dont know btw what book are u reading.
The one Jetamay recommended, "Beginning Game Programming" second edition by Jonathon S. Harbour

I was going to wait till I was well into learning asm to start learning Windows, but it seems that has taken a little bit of a backtrack...
Ok. So I guess this will sort of be my progress on Windows API... thread thing. Anyway it's taking a lot longer to understand WinMain then it did to understand main() and I think the reason for this was put very simple in one quote out of a book called: "Programming Windows 95" Which is horribly out dated, but nonetheless Charles Petzold states:
Quote Originally Posted by Charles Petzold in "Programming Windows 95"
"Rather then ask why the "Hellow, Windows 95!" program is so long and complex, let's ask why the traditional "Hello, world" program is so short and simple.... The "Hello World program is so simple because it's designed for a simpler age and simpler computers and simpler output devices. It's not in the same ballpark as what we think of today's as modern software, and it's not even playing the same game."
Anyway though this book is horribly outdated... and I'm guessing all Windows Programming books are horribly outdated, it goes into enough detail that I can compensate for its age. I guess the biggest problem for me right now is that Windows relies so heavily on Unicode now. So I while I guess for now I can simply change something to MessageBoxA and so forth just adding the A suffix I will eventually have to confront Unicode, because Windows its used internationally now, and I imagine not using Unicode could cause some compatibility issues later on. Anyway I think I'm close to understanding it. Maybe by the end of the week I will understand how WinMain works exactly...
You could change your project to ASCII strings...right click your project, click properties configuartion properties -> general -> character set change that to multi byte
Posts 1–13 of 13 · Page 1 of 1
This thread is closed for replies.

Tags for this Thread

Talk with us