Solved

How to write a Control Panel Application with MFC Extension DLL

Posted on 1998-09-21
2
404 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 176
ADO Memory leak with DELPHI 2007 37 181
iSeries FTP Exit Program 8 135
wait notify demo infinite loop 3 110
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…
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

785 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