Hi I am trying to put up simple app, and i get an error, could you tell me what I am doing wrong please. Here is my code:

#include <afxwin.h>

class myapi: public CWinApp
{
public:
	virtual BOOL InitInstance();
};
class myframe: public CFrameWnd
{
public:
	myframe();
protected:
	afx_msg void OnPaint();
	DECLARE_MESSAGE_MAP()
};
#include "example.h"

BOOL myapi::InitInstance()
{
	m_pMainWnd=new myframe;
	m_pMainWnd->ShowWindow(m_nCmdShow);
	m_pMainWnd->UpdateWindow();
	return TRUE;
}
BEGIN_MESSAGE_MAP(myframe,CFrameWnd)
	ON_WM_PAINT()
END_MESSAGE_MAP()

myframe::myframe()
{
	Create(NULL,_T("bandymas I"));
}
void myframe::OnPaint()
{
	//CPaintDC dc(this);
}

the error msg I get is : Unhandled exception at 0x566d2bea in gdiexample.exe: 0xC0000005: Access violation reading location 0x00000000.
thank you

Edited 5 Years Ago by cppgangster: n/a

As a general rule of thumb, if you're trying to read location 0x00000000, it means you're trying to dereference a null pointer, either directly or by trying to use a member function/variable of a null object.

Edited 5 Years Ago by Moschops: n/a

If you build a version with debug symbols, you can get more information on where the error is happening from the error message. Alternatively, run the program in debug mode (or whatever it's called under your IDE) with breakpoints everywhere, and work out which line must be causing the error

Edited 5 Years Ago by Moschops: n/a

This question has already been answered. Start a new discussion instead.