lmmedina
asked on
WMEndSession Doubt
Hi Experts. For a reason i really don't know, my app can't close or terminate when i shut down or i restart windows. So, i use WMEndSession to force to close my app. It works, but it appears that windows stops shutdown or restart. Maybe i'm forgetting something. This is my code
class TMyForm: public TForm
{
private:
void __fastcall WMEndSession(TWMEndSession &Msg);
public:
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER( WM_ENDSESSION, TWMEndSession, WMEndSession )
END_MESSAGE_MAP( TForm )
};
void __fastcall TMyForm::WMEndSession(TWME ndSession &Msg)
{
Application->Terminate(); //Or Close(); both close my app
TForm::WMEndSession(Msg); //This line generates an error
}
//------------------------ ---------- ---------- ---------- ---------- ---------- -
Last line generates this error :
[C++ Error] MyFormClass.cpp(287): E2451 Undefined symbol 'WMEndSession'
What should i do?
class TMyForm: public TForm
{
private:
void __fastcall WMEndSession(TWMEndSession
public:
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER( WM_ENDSESSION, TWMEndSession, WMEndSession )
END_MESSAGE_MAP( TForm )
};
void __fastcall TMyForm::WMEndSession(TWME
{
Application->Terminate(); //Or Close(); both close my app
TForm::WMEndSession(Msg); //This line generates an error
}
//------------------------
Last line generates this error :
[C++ Error] MyFormClass.cpp(287): E2451 Undefined symbol 'WMEndSession'
What should i do?
ASKER
Thanks so much, but it doesn't work. What could be happen? What should be Msg values?
You can't call the function from within the function...
Compiler treat that function as local parameter..
Replace:
>>TForm::WMEndSession(Msg) ; //This line generates an error
with:
Dispatch(&Msg);
That will work...
gtokas.
Compiler treat that function as local parameter..
Replace:
>>TForm::WMEndSession(Msg)
with:
Dispatch(&Msg);
That will work...
gtokas.
Addition:
Your app is closing when you shut down windows.... If not there is something else wrong there... Incorect handler source, OnIdle routine or something else....
gtokas.
Your app is closing when you shut down windows.... If not there is something else wrong there... Incorect handler source, OnIdle routine or something else....
gtokas.
ASKER
Hi, Incorrect Handler... how could happend this?... OnIdle routine means threads or something like that??? Please could u give more information. I'musing threads on my app. Could it be the reason why my code doesn't work?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi experts, i had been looking for a lost thread or a process that were on background in my app. But it seems all ok. My app is still not closing when i try to restar or shut down windows. So, i'm trying to force it to close. But i want to know if there is a way to get if i selected "restart" or "shut down" when i catch WMEndSession message to force and use the right flag on ExitWindowsEx();
I'm doing something like this.
int __fastcall MyForm::WMEndSession(TMess age &Msg)
{
HANDLE token;
TOKEN_PRIVILEGES tok,old;
LUID priv;
DWORD dwSize = sizeof (TOKEN_PRIVILEGES);
PostMessage(Application->H andle,WM_C LOSE,0,0);
DefWindowProc(Application- >Handle, Msg.Msg, Msg.WParam, Msg.LParam);
IntToStr(ENDSESSION_LOGOFF ));
if(Msg.LParam==ENDSESSION_ LOGOFF)
ExitWindowsEx(EWX_LOGOFF|E WX_FORCE ,0);
else
{ if(!OpenProcessToken(GetCu rrentProce ss(),
TOKEN_ADJUST_PRIVILEGES|TO KEN_QUERY, &token))
return(0);
if(!LookupPrivilegeValue(N ULL,SE_SHU TDOWN_NAME ,&priv))
return(0);
ZeroMemory(&tok,sizeof(tok ));
tok.PrivilegeCount=1;
tok.Privileges[0].Luid=pri v;
tok.Privileges[0].Attribut es=SE_PRIV ILEGE_ENAB LED;
if(!AdjustTokenPrivileges( token,fals e,&tok,
sizeof(TOKEN_PRIVILEGES),& old,&dwSiz e))
return(0);
ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE ,0);
}
return(0);
}
//------------------------ ---------- ---------- ---------- ---------- ---------- -
I'm doing something like this.
int __fastcall MyForm::WMEndSession(TMess
{
HANDLE token;
TOKEN_PRIVILEGES tok,old;
LUID priv;
DWORD dwSize = sizeof (TOKEN_PRIVILEGES);
PostMessage(Application->H
DefWindowProc(Application-
IntToStr(ENDSESSION_LOGOFF
if(Msg.LParam==ENDSESSION_
ExitWindowsEx(EWX_LOGOFF|E
else
{ if(!OpenProcessToken(GetCu
TOKEN_ADJUST_PRIVILEGES|TO
return(0);
if(!LookupPrivilegeValue(N
return(0);
ZeroMemory(&tok,sizeof(tok
tok.PrivilegeCount=1;
tok.Privileges[0].Luid=pri
tok.Privileges[0].Attribut
if(!AdjustTokenPrivileges(
sizeof(TOKEN_PRIVILEGES),&
return(0);
ExitWindowsEx(EWX_SHUTDOWN
}
return(0);
}
//------------------------
TForm::Dispatch(&Msg);