?
Solved

WMEndSession Doubt

Posted on 2005-05-13
7
Medium Priority
?
611 Views
Last Modified: 2013-11-17
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(TWMEndSession &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?
0
Comment
Question by:lmmedina
  • 3
  • 3
7 Comments
 
LVL 5

Expert Comment

by:Greybird
ID: 13994137
you sould do :
TForm::Dispatch(&Msg);
0
 

Author Comment

by:lmmedina
ID: 13995740
Thanks so much, but it doesn't work. What could be happen? What should be Msg values?
0
 
LVL 16

Expert Comment

by:George Tokas
ID: 13996554
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.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 16

Expert Comment

by:George Tokas
ID: 13996579
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.
0
 

Author Comment

by:lmmedina
ID: 13997439
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?
0
 
LVL 16

Accepted Solution

by:
George Tokas earned 150 total points
ID: 13997715
OnIdle is a function the application call when there is no other message or function executed... Of course this function must be declared at the header.. If not ignore it...
Anyway since you are using threads at your application probably some thread locks the execution and don't finnish so the application hangs...
It will be better if you post some more more details... the headers at least...

gtokas.
0
 

Author Comment

by:lmmedina
ID: 14027579
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(TMessage  &Msg)
{
 HANDLE token;
  TOKEN_PRIVILEGES tok,old;
  LUID priv;
  DWORD dwSize = sizeof (TOKEN_PRIVILEGES);

  PostMessage(Application->Handle,WM_CLOSE,0,0);
  DefWindowProc(Application->Handle, Msg.Msg, Msg.WParam, Msg.LParam);
IntToStr(ENDSESSION_LOGOFF));
  if(Msg.LParam==ENDSESSION_LOGOFF)
    ExitWindowsEx(EWX_LOGOFF|EWX_FORCE ,0);
  else
  { if(!OpenProcessToken(GetCurrentProcess(),
          TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&token))
      return(0);
    if(!LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&priv))
      return(0);
    ZeroMemory(&tok,sizeof(tok));
    tok.PrivilegeCount=1;
    tok.Privileges[0].Luid=priv;
    tok.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;
    if(!AdjustTokenPrivileges(token,false,&tok,
        sizeof(TOKEN_PRIVILEGES),&old,&dwSize))
      return(0);
    ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE ,0);
  }

  return(0);
}
//---------------------------------------------------------------------------
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question