[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to write a Control Panel Application with MFC Extension DLL

Posted on 1998-09-21
2
Medium Priority
?
442 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 200 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Suggested Courses

656 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