Solved

How to write a Control Panel Application with MFC Extension DLL

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

696 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