Public Group

# Bizzare code results!!

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

## Recommended Posts

I'm getting really strange result in my WNDCLASSEX code
WNDCLASSEX wce;
wce.cbClsExtra	  = 0;
wce.cbWndExtra    = 0;
wce.style         = CS_HREDRAW | CS_VREDRAW;
wce.cbSize	  = sizeof(WNDCLASSEX);
wce.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wce.lpfnWndProc	  = WndProc;
wce.lpszClassName = ENGINENAME;
wce.hInstance	  = _hInstance;


My VS2005 debugger says that cbWndExtra contains -858993460, however this isn't what breaks my code. It also says the cbSize is 3435973836, not sure if that's correct or not. But what breaks my code is this line: if(!RegisterClassEx(&wce)) { return 0; } So obviously something is stuffed within the structure and I don't know how to fix it... And whenever it breaks it brings up the open.c file. any thoughts?

##### Share on other sites
im pretty sure its your

wce.lpszClassName

try "WindowClass" or L"WindowClass"

##### Share on other sites
No no that's not it, I use
#define ENGINENAME "Window Class"

##### Share on other sites

// Uninitialized member. add this line:wce.lpszMenuName = 0;

I dont see anything else directly wrong with the code at the moment.

##### Share on other sites
ah good good, thanks for that. However now I have another break point.

void Tile::Init(int x, int y, int texture, int type)
{
_box.y = y;
_box.x = x;
_box.w = TILE_WIDTH;
_box.h = TILE_HEIGHT;
_texture = texture;
_type = type;
}

the box values arent being assigned!! it just says the x, y, w etc cannot be evaluated.

class Box
{
public:

Box();
~Box();

int x, y, w, h;
};

Box::Box() :
x(0), y(0), w(0), h(0)
{

}

What could be wrong with this?

##### Share on other sites
Usually you could call GetLastError if the function return an invalid value and check the error message to see what's wrong, but if the application crash it won't work. I remember having exactly the same problem a few years ago when I was starting Win32 programming,... I don't remember exactly what and your code seem fine, but I think it was the way I was doing LoadIcon/LoadCursor... or maybe the background color, anyway it was a stupid error. I also remember keeping nearly the same code but using WNDCLASS and RegisterClass (not ex) was not crashing, but you should use the ex version.

You might want to try to do a ZeroMemory on wce before filling it up.

edit : ohh you are now on something else already :) How are you declaring _box in the Tile class and do you call init on your tiles??

##### Share on other sites
Okay I'll show all the code I believe will be relevant to the problem.
private:
Box _box; thats within the Tile class.

void Field::Init(std::string name){int i = 0;	for (int y = 0; y < _height; y++)	{		for (int x = 0; x < _width; x++)		{			int tile = newMap[y][x];			_tiles[i++].Init(x, y, Gfx::GetTexture(tile), tile);		}	}}

The above code is for loading maps, the file loading code isnt working some I'm using a hard coded character double array to store the map.

##### Share on other sites
void Tile::Init(int x, int y, int texture, int type){   _box.y = y;   _box.x = x;   _box.w = TILE_WIDTH;   _box.h = TILE_HEIGHT;   _texture = texture;   _type = type;}

Set a breakpoint at the end of this routine before it returns. What are the values of its parameters? What are the values of _box?

Do not get these values from your code of what it "should" be. Get them from what your debugger displays during runtime.

Quote:
 No no that's not it, I use#define ENGINENAME "Window Class"

This does not matter with regards to phear-'s reply. Remember that #define is just text replacement.

##### Share on other sites
the reason i know thats the issue is because i placed a breakpoint there, it says {x=??? y=??? w=??? ...} it breaks right at _box.y = y;

##### Share on other sites
Are you compiling in Release mode? Because it sounds like your debugger can't read the memory locations, which is usually a signal you've compiled in Release mode.

Toolmaker

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633735
• Total Posts
3013593
×