Solved

Ctrl-Alt-Delete: The Close Program Box

Posted on 1998-12-16
9
152 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

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!

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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 this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

719 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