C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 23rd, 2008, 10:19 AM
Daniel Zen Daniel Zen is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Posts: 2 Daniel Zen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 17 m 47 sec
Reputation Power: 0
"The variable X is being used without being initialized." Help :/

Hello everyone , i have a problem with this simple windows program. It gives me "The variable 'cc_hwnd' is being used without being initialized." error and it doesnt compile.

Code:
#include <windows.h>
/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "WindowsApp";

void FillWindowClass(HINSTANCE a1,HWND a2); 



int WINAPI WinMain (HINSTANCE a_hThisInstance,
                    HINSTANCE a_hPrevInstance,
                    LPSTR a_lpszArgument,
                    int a_nFunsterStil)

{
    HWND cc_hwnd;               /* This is the handle for our window */
    MSG cc_messages;            /* Here cc_messages to the application are saved */
    WNDCLASSEX cc_wincl;        /* Data structure for the windowclass */
    
      /* The Window structure */
    cc_wincl.hInstance = a_hThisInstance;
    cc_wincl.lpszClassName = szClassName;
    cc_wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    cc_wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    cc_wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    cc_wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    cc_wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    cc_wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    cc_wincl.lpszMenuName = NULL;                 /* No menu */
    cc_wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    cc_wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    cc_wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;      
        
    

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&cc_wincl))
        return 0;
        
FillWindowClass(a_hThisInstance,cc_hwnd);
    

    /* Make the window visible on the screen */
    ShowWindow (cc_hwnd, a_nFunsterStil);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&cc_messages, NULL, 0, 0))
    {
        /* Translate virtual-key cc_messages into character cc_messages */
        TranslateMessage(&cc_messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&cc_messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return cc_messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND cc_hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the cc_messages */
    {
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for cc_messages that we don't deal with */
            return DefWindowProc (cc_hwnd, message, wParam, lParam);
    }

    return 0;
}


void FillWindowClass(HINSTANCE a1,HWND a2){
                               
                               /* The class is registered, let's create the program*/
    a2 = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Windows App",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           544,                 /* The programs width */
           375,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           a1,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           ); 
                               
                               };



I just want to simplfy the code , moving the unnecessary mess to other functions or files if possible and have a better look at the main logic .

I would greatly appreciate any help , thanks very much in advance !

Reply With Quote
  #2  
Old October 23rd, 2008, 11:34 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 8 h 12 m 36 sec
Reputation Power: 15
Well, you are passing cc_hwnd to the FillWindowClass function but you never assign any value to cc_hwnd. You didn't post the line number where the error occurs but I guess that is the line.

I see you are not using that parameter at all in FillWindowClass so maybe you could remove it? Although you are using the cc_hwnd variable later in ShowWindow again.. So you should just initialize the variable, just like the compiler tells you to


Maybe, what you (?) were trying to do is pass the handle to the FillWindowClass as an 'out' parameter (either passing by reference or pointer, whatever you prefer) ? So that after that call the handle would be initialized? (The FillWindowClass is actually using a variable called a3, which i cannot spot anywhere)
__________________
There is no such thing as C/C++, you either program C or C++

Reply With Quote
  #3  
Old October 23rd, 2008, 12:03 PM
Daniel Zen Daniel Zen is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Posts: 2 Daniel Zen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 17 m 47 sec
Reputation Power: 0
Hey thanks a lot for the repply !

I would like to initialize cc_hwdn but initialize it to what ?
And i only wanted to take away some of the code to somewhere else , adding to the code would just confuse me more.

Fixed a3 , its a2 now . Second argument of the function etc. I will try to make use of pointers now .

At first, i used macro's in another file to simplfy the code , i just created multiline macro's and used them to clear out main logic part. But i dont think thats what i should be doing , if you you could tell me what other methods i could use instead , i would greatly appreciate that too ! Thanks a lot.

Edit : Using pointers solved the problem .

Reply With Quote
  #4  
Old October 31st, 2008, 01:25 AM
jasonlang jasonlang is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Posts: 164 jasonlang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 3 h 13 m 21 sec
Reputation Power: 10
the small change, probably, to the program needed to get ur HWND value is from this :

void FillWindowClass(HINSTANCE a1,HWND a2)

to this:

void FillWindowClass(HINSTANCE a1,HWND &a2) //note the & symbol

the first means "a2 is a copy of a HWND passed from the main program, do what you want to the copy, which will be deleted when FillWindowClass ends"

the second means "a2 is a reference to the original HWND, when a2 changes the original is automatically updated too"

also you WndProc function always gets sent a valid HWND by Windows as one of it's parameters

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > "The variable X is being used without being initialized." Help :/


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap