Results 1 to 13 of 13
  1. #1
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty

    !@#*$(@_$*@!! 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;

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  2. #2
    zeco's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Canada
    Posts
    683
    Reputation
    12
    Thanks
    78
    My Mood
    Cynical
    =)....

    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
    Last edited by zeco; 10-25-2009 at 05:04 PM.

  3. The Following User Says Thank You to zeco For This Useful Post:

    Hell_Demon (10-25-2009)

  4. #3
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Well I suppose one good thing did come out of this:


    I was finally able to express my true feelings to Windows... :l

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  5. #4
    zeco's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Canada
    Posts
    683
    Reputation
    12
    Thanks
    78
    My Mood
    Cynical
    xD im starting to think that all coders have anger problems >_>"

  6. #5
    radnomguywfq3's Avatar
    Join Date
    Jan 2007
    Gender
    male
    Location
    J:\E\T\A\M\A\Y.exe
    Posts
    8,858
    Reputation
    381
    Thanks
    1,823
    My Mood
    Sad
    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.



    There are two types of tragedies in life. One is not getting what you want, the other is getting it.

    If you wake up at a different time in a different place, could you wake up as a different person?


  7. The Following 3 Users Say Thank You to radnomguywfq3 For This Useful Post:

    Hell_Demon (10-25-2009),Matrix_NEO006 (10-25-2009),why06 (10-25-2009)

  8. #6
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Quote Originally Posted by Jetamay 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?

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  9. #7
    B1ackAnge1's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Posts
    455
    Reputation
    74
    Thanks
    344
    My Mood
    Cynical
    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

  10. #8
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    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?!

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  11. #9
    Matrix_NEO006's Avatar
    Join Date
    Feb 2008
    Gender
    male
    Posts
    240
    Reputation
    12
    Thanks
    33
    My Mood
    Lonely
    look into MSDN w/e u dont know btw what book are u reading.

  12. #10
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    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...

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  13. #11
    Matrix_NEO006's Avatar
    Join Date
    Feb 2008
    Gender
    male
    Posts
    240
    Reputation
    12
    Thanks
    33
    My Mood
    Lonely
    asm is easy just learn what they stand for
    ASM Tutorial/Ready to Start!

  14. #12
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    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...

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  15. #13
    zhaoyun333's Avatar
    Join Date
    Apr 2009
    Gender
    male
    Posts
    396
    Reputation
    11
    Thanks
    1,125
    You could change your project to ASCII strings...right click your project, click properties configuartion properties -> general -> character set change that to multi byte
    There are five possible operations for any army. If you can fight, fight; if you cannot fight, defend; if you cannot defend, flee; if you cannot flee, surrender; if you cannot surrender, die." - Sima Yi

Tags for this Thread