Solved

How to write a Control Panel Application with MFC Extension DLL

Posted on 1998-09-21
2
402 Views
Last Modified: 2013-11-19
Hi! I would like to write a control panel application(tabbed property sheet) with MFC extension DLL( which is generated from the Appwizard). My problem is that I can not get the correct CURRENT INSTANCE HANDLE.(When I open my application icon in the Control Panel, A dialog will show "Program c:\win98\rundll32.exe
 File:afxwin1.inl
 Line 19........."  )
I think it indicates the AfxGetInstanceHandle() function fails. So, could you tell me how to get my correct instance handle ???


Thanks,
Jenny

p.s Just let me briefly write my code:


static HINSTANCE hDLLinstance;
int  CreatePropertySheet( HWND hWnd);


static AFX_EXTENSION_MODULE ControlAppletDLL = { NULL, NULL };
extern "C" int APIENTRY DllMain (HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
      // Remove this if you use lpReserved
      UNREFERENCED_PARAMETER(lpReserved);

      if (dwReason == DLL_PROCESS_ATTACH)
      {
            TRACE0("CONTROLAPPLET.DLL Initializing!\n");
            
            
            // Extension DLL one-time initialization
            if (!AfxInitExtensionModule
                        (ControlAppletDLL, hInstance))
                return 0;

            new CDynLinkLibrary(ControlAppletDLL);
            hDLLinstance=hInstance;
            
      }
      else if (dwReason == DLL_PROCESS_DETACH)
      {
            TRACE0("CONTROLAPPLET.DLL Terminating!\n");
            // Terminate the library before destructors are called
            AfxTermExtensionModule(ControlAppletDLL);
      }
      return TRUE;   // ok
}



LONG  CALLBACK APIENTRY CPlApplet( HWND hWnd, UINT uMessage, LPARAM lParam1,LPARAM lParam2)
{

      ......      
      LPNEWCPLINFO   lpNewCPlInfo;
       
      switch ( uMessage )
      {
                       
            ......
          case CPL_DBLCLK:
                 CreatePropertySheet(hWnd);
                    break;
           
        case CPL_STOP:
            .....
   
      }
      return TRUE;

}


int  CreatePropertySheet( HWND hWnd)
{
    .............
      
    AfxSetResourceHandle(ControlAppletDLL.hModule);

    CMypropertySheet dlg("My Property Sheet")
      
    dlg.DoModal();
      
    return 0;
}
0
Comment
Question by:jennyhou
2 Comments
 

Author Comment

by:jennyhou
ID: 1322368
Edited text of question
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 50 total points
ID: 1322369
First off
1. Your DLL should _NOT_ be an MFC Extension DLL.   Here's why
i. An MFC Extension DLL is one that uses MFC, and uses the same copy of MFC as the host app it belongs to (this saves memory and allows you to share objects between the app and the DLL).  However Control Panel itself is not written with MFC so using an MFC extension DLL won't work, hence the difficulty in finding the instance handle
ii. However a regular MFC DLL will work for you.  (you can also generate these using the app wizard).  This will allow you to use MFC in your control panel applet.

2. If you want some samples
i. Go to www.codeguru.com
ii. Search for "Control Panel"
iii. First article that comes up "ctrl_panl_appwiz.shtml" is an AppWizard you can install and use that will generate a control panel extension.
iv. Second article "cplframework.shtml" is a framework set of classes for the same job (if you prefer not to use a wizard)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 84
Excel Use VBA to get user's Mac Address for their computer 5 112
matchUp  challenge 6 53
SQUD PROXY SERVER, UNIX, SLL/HTTPS 5 74
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now