Solved

How to write a Control Panel Application with MFC Extension DLL

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 47
if loop error 4 77
Best tools for Backup and restore of Wordpress site 6 53
centeredAverage challenge 8 124
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…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

743 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

10 Experts available now in Live!

Get 1:1 Help Now