Solved

Ctrl-Alt-Delete: The Close Program Box

Posted on 1998-12-16
9
151 Views
Last Modified: 2013-11-20
I'm attempting to prevent my application's name from being seen in the close program box

I've added the following code in the proper sections that contains the InitInstance function.

  #define REGISTER 0
  #define UNREGISTER 1

to the top of your main source code file (the one with the InitInstance function in it).  Then add:

  typedef DWORD (WINAPI *fp_RegServProc) (DWORD, DWORD);
  fp_RegServProc pRegisterServiceProcess = NULL;

  pRegisterServiceProcess = (fp_RegServProc) GetProcAddress (GetModuleHandle ("KERNEL32.dll"), "RegisterServiceProcess");

  (pRegisterServiceProcess)(0, UNREGISTER);

to your InitInstance member function.  

Yet it doesn't work.
What have I done wrong????
0
Comment
Question by:lynn402
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 1326242
The problem is simply the way to obtain the DLL module handle. Change the code to read
HANDLE hDll = LoadLibrary ( "kernel32.dll");

  pRegisterServiceProcess = (fp_RegServProc) GetProcAddress (hDll, "RegisterServiceProcess");

  (pRegisterServiceProcess)(GetCurrentProcessId(), UNREGISTER);

BTW: the correct operation codes for this function:

// from http://support.microsoft.com/support/kb/articles/q125/7/14.asp,
// How to Start an Application at Boot Time Under Windows 95
// Last reviewed: September 25, 1995
// Article ID: Q125714

// Define                    Value       Meaning
#define RSP_SIMPLE_SERVICE        0x00000001      // Registers the process as a
                                                                        // simple service process.
#define RSP_UNREGISTER_SERVICE    0x00000000      // Unregisters the process as a
                                                                        // service process.

0
 

Author Comment

by:lynn402
ID: 1326243
Now when I compile my program I get a spawning error --"error spawning c1.exe"
0
 

Author Comment

by:lynn402
ID: 1326244
CORRECTION: the error I'm getting is c2664: cannot convert param 1 from 'void *' to 'struct HINSTANCE__*'
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:jkr
ID: 1326245
Check your include path!!! This error usually occurs when outdated (Win16!) header files are involved (formerly, 'LoadLibrary()' indeed returned a 'struct HINSTANCE', whereas it returns 'void*' nowadays...). Here some code that compiles AND works:

typedef DWORD ( *RSPPROC)   (   DWORD,  DWORD);

RSPPROC RegisterServiceProcess;


            g_hSvcDll   =   LoadLibrary (   "kernel32.dll");

            if  (   !g_hSvcDll)
                {
                    // error
                }

            RegisterServiceProcess  =   ( RSPPROC)  GetProcAddress  (   g_hSvcDll,
                                                                        "RegisterServiceProcess"
                                                                    );

            if  (   !RegisterServiceProcess)
                {
                    FreeLibrary (   g_hSvcDll);
                }
             else
                {
                    if  (   !RegisterServiceProcess (   GetCurrentProcessId (),
                                                        RSP_SIMPLE_SERVICE
                                                    )
                        )
                        {
                            // error
                        }
                }

0
 
LVL 23

Expert Comment

by:chensu
ID: 1326246
GetModuleHandle is OK.

The following code should work.

// Registers the process as a simple service process.
#define RSP_SIMPLE_SERVICE        0x00000001
// Unregisters the process as a service process.
#define RSP_UNREGISTER_SERVICE    0x00000000
// ...
 typedef DWORD (WINAPI *fp_RegServProc)(DWORD dwProcessId,DWORD dwType);
 fp_RegServProc fncptr=NULL;
// ...
HMODULE hModule = ::GetModuleHandle(TEXT("kernel32.dll"));
fncptr=(fp_RegServProc)::GetProcAddress(hModule, "RegisterServiceProcess");
if (fncptr!=NULL)
    (*fncptr)(0, RSP_SIMPLE_SERVICE);

0
 

Author Comment

by:lynn402
ID: 1326247
It's working now.Thanks, JKR
0
 
LVL 86

Expert Comment

by:jkr
ID: 1326248
Fine! Do you think i may lock the Q?
0
 

Author Comment

by:lynn402
ID: 1326249
Yes. Lock the question. It seems that expert exchange isn't presenting me with the options of whether to accept or refuse a person's solution.


0
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 1326250
Thanks! ;-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Prevent this page from creating additional dialogs. 3 767
Line meaning 9 96
unix example issues 18 112
Making an alias 7 121
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

738 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