Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Ctrl-Alt-Delete: The Close Program Box

Posted on 1998-12-16
9
Medium Priority
?
157 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
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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. …
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…
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 video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

636 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