• 16
• 15
• 12
• 9
• 10

Problem with a "unused" Varible

This topic is 3298 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hey, Problem ... I have the following Variables declared in my class cWindow
class cWindow
{
private:
HINSTANCE	m_hInst;    //Instance Handle
HWND		m_hWnd;		//Window Handle

protected:
LPCTSTR		m_Class;
LPCTSTR		m_Caption;
WNDCLASSEX	m_wcex;
DWORD	m_style;
DWORD	m_XPos;
DWORD	m_YPos;
DWORD	m_Width;
DWORD	m_Height;

(... more Code ...)
};

now in an function Run i have this piece of code (not Full declaration)
bool cWindow::Run()
{
if(!RegisterClassEx(&m_wcex))
return false;

// Create the Main Window
m_hWnd = CreateWindow(m_Class, m_Caption, m_style, m_XPos, m_YPos, m_Width, m_Height, NULL, NULL, m_hInst, NULL);

if(!m_hWnd)
return false; // Return false here


Now, when i run the check if(!m_hWnd) i get a return false, i added a watch to m_hWnd, and it says "Unused"  cannot be evaluated ** what i dont understand is why its saying Unused, if i just declared that
m_hWnd = CreateWindow(...);

Share on other sites
If you look at the definition of HWND in windef.h, you'll see that it's
DECLARE_HANDLE            (HWND);

where DECLARE_HANDLE is:
#define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name

So HWND is
struct HWND__ { int unused; }; typedef struct HWND__ *name;

And unused is part of the HWND__ definition.

Share on other sites
ok, but i have been declaring them this way while playing with Win32 Lirary.

this is the problem

*m_hWnd).unused CXX0030: Error: expression cannot be evaluated

and i dont understand why, this has suddenly cropped up.

it seems to completely ignore the CreateWindow(...) Function, or doesnt assign it to m_hWnd

Share on other sites
Once upon a time I was writing some code that dealt with the cURL library. I created a cURL handle, and then I checked to see if that handle was valid, and if not, I'd throw an exception. Everything worked great (in Debug mode), but then when I tried it in Release mode, that exception would be thrown every single time I ran the program, no matter what I did. Turns out the MSVC compiler was optimizing away my cURL handle and assumed it was invalid, so it would just throw the exception. I had to declare the cURL handle as volatile to make sure it didn't get optimized away, and when I did this, everything worked just fine. You may want to look into this and see if the compiler is optimizing it away improperly. Try declaring it as volatile, and try using GetLastError() to make sure there wasn't an error when you caled CreateWindow. If you're going through with the debugger and it says something can't be evaluated (I can't remember what the exact message is), it means the compiler optimized it away. So that very well may be your problem.

Share on other sites
Quote:
 Original post by Andy474ok, but i have been declaring them this way while playing with Win32 Lirary.this is the problem*m_hWnd).unused CXX0030: Error: expression cannot be evaluated and i dont understand why, this has suddenly cropped up.
This occurs when to evaluate the expression would lead to an error. Like trying to evaluate 5 + printf, or foo->bar when foo is a null pointer.