Sign in to follow this  

segmentation fault

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

thanx for the replies
here's the code
Error_check.h
 
// Adriaan Larmuseau
// Sylvarant Studios
// Project-Mage version 0.1

//------------------------------------------------------------------------------
// ERROR_CHECK HEADER VERSION 0.1
//------------------------------------------------------------------------------

#include "Windows.h"
class Error_check {

public:

// set window properties
void Win_prop();
// update function
void Window_status();
// constructor
Error_check(char* error_report);
// destructor
~Error_check();
};



Error_check.cpp
 
// Adriaan Larmuseau
// Sylvarant Studios
// Project-Mage version 0.1

//------------------------------------------------------------------------------
// ERROR_CHECK SOURCE CODE VERSION 0.1
//------------------------------------------------------------------------------
#include "Error_check.h"

void Error_check::Win_prop(){
//create structure for window properties
WNDCLASSEX wac;
// set size
wac.cbSize = sizeof(WNDCLASSEX);
// set window style
wac.style = CS_CLASSDC;
// set message handler
wac.lpfnWndProc = NULL;
// set extra bytes for structure
wac.cbClsExtra = 0;
// set extra bytes for window instance
wac.cbWndExtra = 0;
// set unique HINSTANCE
wac.hInstance = GetModuleHandle ( NULL );
// set cursor
wac.hCursor = LoadCursor(NULL, IDC_ARROW);
// set background
wac.hbrBackground = HBRUSH (COLOR_BTNFACE);
// set windows Icon
wac.hIcon = LoadIcon(NULL, IDI_APPLICATION);
// set Icon Sm
wac.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
// set class
wac.lpszClassName = "Error_check";
// set menu
wac.lpszMenuName = NULL;

// register structuur
RegisterClassEx(&wac);
}

void Error_check::Window_status(){
// define window handle
HWND window_handle;
// windows shows window
ShowWindow(window_handle,SW_SHOW);
// windows updates window
UpdateWindow(window_handle);
// windows shows the cursor
ShowCursor(TRUE);
}

Error_check::Error_check(char* error_report){
// create window properties
Win_prop();
// create window handle
HWND window_handle;
// create window
window_handle = CreateWindow("Error_check","Error_check",WS_POPUPWINDOW,
300,200,200,200,NULL,NULL,GetModuleHandle ( NULL ),NULL);
//error message box
MessageBox(window_handle,error_report, "Project-Mage error!", MB_OK|MB_ICONSTOP);
// update window status
Window_status();
}





Share this post


Link to post
Share on other sites
Quote:
Original post by Iftah
I don't know windows programming


Same here, but Window_status looks fine to me. Since you are using a pupup window, try cutting CreateWindow("Error_check","Error_check",WS_POPUPWINDOW, 300,200,200,200,NULL,NULL,GetModuleHandle ( NULL ),NULL); down to CreateWindow("Error_check","Error_check",WS_POPUPWINDOW, 300,200,200,200);

Not sure if this will help since I don't program windows, but I'm pretty sure you can just use the default parameters here.

EDIT -

wac.lpszClassName = "Error_check";

According to http://windowssdk.msdn.microsoft.com/en-us/library/ms633577.aspx, lpszClassName should be null terminated.

Share this post


Link to post
Share on other sites
What are you compiling this under btw? On VS 2k5 I needed to make a number of changes ( mostly revolving arounds strings ) to get it to compile.

However, here is a line that will definatly cause a seg fault:


HWND window_handle;
// windows shows window
ShowWindow(window_handle,SW_SHOW);
// windows updates window
UpdateWindow(window_handle);



You passing a handle to nothing into a call to ShowWindow. You need to call ( or have called ) CreateWindow to get a valid HWND to pass into ShowWindow().

Right now, its trying to call ShowWindow() on a NULL HWND value, which will cause it to go kaploowy!

Share this post


Link to post
Share on other sites
Quote:
Original post by lmb
wac.lpszClassName = "Error_check";

According to http://windowssdk.msdn.microsoft.com/en-us/library/ms633577.aspx, lpszClassName should be null terminated.


Just a quick point, but a const string like "Error_check" is null terminated automatically.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this