?
Solved

Ctrl-Alt-Delete: The Close Program Box

Posted on 1998-12-16
9
Medium Priority
?
158 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
  • 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
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 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 200 total points
ID: 1326250
Thanks! ;-)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

830 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