access conflict with (LPVOID)this in CreateWindowEx

Y

Young

This makes me very puzzled and angry.Please have a look at :
.......
.......
_hSelf=::CreateWindowEx(
WS_EX_ACCEPTFILES,
(LPCWSTR)_className,\
(LPCWSTR)"Web Studio 2008",\
WS_OVERLAPPEDWINDOW,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
_hParent,\
NULL,\
_hInst,\
(LPVOID)this);
........
........
The code is compiled and linked successly under VS2005.But ever time
it runs to "(LPVOID)this" in the function "CreateWindowEx" ,an
exception occurs which say
0x00000000 Department untreated anomaly: 0xC0000005: reading position
0 x00000000 visit when conflict
in the VS 2005.

Why?Why?WWWWW?
 
B

Barry

Young said:
This makes me very puzzled and angry.Please have a look at :
......
......
_hSelf=::CreateWindowEx(
WS_EX_ACCEPTFILES,
(LPCWSTR)_className,\
(LPCWSTR)"Web Studio 2008",\
WS_OVERLAPPEDWINDOW,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
_hParent,\
NULL,\
_hInst,\
(LPVOID)this);
.......
.......
The code is compiled and linked successly under VS2005.But ever time
it runs to "(LPVOID)this" in the function "CreateWindowEx" ,an
exception occurs which say
0x00000000 Department untreated anomaly: 0xC0000005: reading position
0 x00000000 visit when conflict
in the VS 2005.

Your code is not detailed enough, what kind of class object does "this"
points to?

And I suspect that this is off-topic, better post it to windows
programming NG.
 
Y

Young

Oh,I'm sorry I'm new to this usernet.I think the bug concerned with
cpp,so...And if it can't be solved here ,I will go windows programming
NG. But please do me a favor, thanks.
......
class WebStudio:public Window
{
public:
WebStudio():Window(){};
//,_mainWindowStatus(0),_pMainSplitter(NULL),_hTabPopupMenu(NULL),_hTabPopupDropMenu(NULL),_pEditView(NULL),_pDocTab(NULL)
{};

void init(HINSTANCE,HWND,const char*);
bool doOpen(const char *fileName);
static const char * getClassName() {
return _className;
};
private:
static const char _className[32];
};
.....
class Window
{
public:
Window():_hSelf(NULL),_hParent(NULL),_hInst(NULL){};
virtual ~Window(){};
virtual void init(HINSTANCE hInst, HWND parent)
{
_hInst = hInst;
_hParent = parent;
}

protected:
HINSTANCE _hInst;
HWND _hParent;
HWND _hSelf;
};
.....
 
B

Barry

Young said:
Oh,I'm sorry I'm new to this usernet.I think the bug concerned with
cpp,so...And if it can't be solved here ,I will go windows programming
NG. But please do me a favor, thanks.
.....
class WebStudio:public Window
{
public:
WebStudio():Window(){};
//,_mainWindowStatus(0),_pMainSplitter(NULL),_hTabPopupMenu(NULL),_hTabPopupDropMenu(NULL),_pEditView(NULL),_pDocTab(NULL)
{};

void init(HINSTANCE,HWND,const char*);
bool doOpen(const char *fileName);
static const char * getClassName() {
return _className;
};
private:
static const char _className[32];
};
....
class Window
{
public:
Window():_hSelf(NULL),_hParent(NULL),_hInst(NULL){};
virtual ~Window(){};
virtual void init(HINSTANCE hInst, HWND parent)
{
_hInst = hInst;
_hParent = parent;
}

protected:
HINSTANCE _hInst;
HWND _hParent;
HWND _hSelf;
};
....

Well, after I looked at the CreateWindowEx API on MSDN,
the last parameter requires a pointer to "CREATESTRUCT", "this " is
absolutely not typeof(CREATESTRUCT*).
 
Y

Young

Mm,after I send the last message,I suddenly notice that the last param
in CreateWindowEx should point to a CREATESTRUCT struct.But if so, I
have no idea to make it point to the CREATESTRUCT struct.How to do
that?
 
J

johanatan

Mm,after I send the last message,I suddenly notice that the last param
in CreateWindowEx should point to a CREATESTRUCT struct.But if so, I
have no idea to make it point to the CREATESTRUCT struct.How to do
that?

Declare a struct like so:

CREATESTRUCT cs;

then fill in the members of cs like:

cs.x = y;
cs.a = b;
....

then pass "&cs" as the last param.
 
Y

Young

I did that,such as:
.....
CREATESTRUCT p;
p.cx=0;
p.cy=0;
p.dwExStyle=0;
p.hInstance=hInst;
p.hMenu=NULL;
p.hwndParent=NULL;
p.lpCreateParams=NULL;
p.lpszClass=(LPCWSTR)_className;
p.lpszName=TEXT("SB");
p.style=NULL;
p.x=0;
p.y=0;
_hSelf=::CreateWindowEx(
WS_EX_ACCEPTFILES,\
(LPCWSTR)_className,\
(LPCWSTR)"Web Studio 2008",\
WS_OVERLAPPEDWINDOW,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
_hParent,\
NULL,\
_hInst,\
(LPVOID)&p);
.....
But the same conflict still exists.
Where's the problem ??
 
J

johanatan

I did that,such as:
....
CREATESTRUCT p;
p.cx=0;
p.cy=0;
p.dwExStyle=0;
p.hInstance=hInst;
p.hMenu=NULL;
p.hwndParent=NULL;
p.lpCreateParams=NULL;
p.lpszClass=(LPCWSTR)_className;
p.lpszName=TEXT("SB");
p.style=NULL;
p.x=0;
p.y=0;
_hSelf=::CreateWindowEx(
WS_EX_ACCEPTFILES,\
(LPCWSTR)_className,\
(LPCWSTR)"Web Studio 2008",\
WS_OVERLAPPEDWINDOW,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
_hParent,\
NULL,\
_hInst,\
(LPVOID)&p);
....
But the same conflict still exists.
Where's the problem ??

One other problem I see is that your constant string "Web Studio 2008"
ought to be:

L"Web Studio 2008"

you could be causing a runaway scan since the null terminator of the
first is only one byte and the API might be looking for a double-byte
zero.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,181
Messages
2,570,970
Members
47,537
Latest member
BellCorone

Latest Threads

Top