Solved

Loading dialog resource from DLL

Posted on 2003-10-27
7
599 Views
Last Modified: 2013-11-20
I have a very simple question, but I forgot the answer...

I want to put my dialog resources in a resource DLL, but when the program tries to access ii, it fails.

I have a very simple view that derives from CFormView with a constructor like this:

CMyView::CMyView()
: CFormView(CMyView::IDD)  {

  // init
}

This is in my main program module. The resource that CMyView::IDD points to is in a DLL.

The program crashes saying "ERROR: Cannot find dialog template with IDD 0x01A7." in the console output.

This of course happens, because the current instance is that of the main module and not that of the DLL, so 0x01A7 is not a valid value, I know. I already knew how to solve this, but I forgot...

Somebody please remind me :-)
0
Comment
Question by:hirnsieb
[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
7 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9626131
Use "AfxSetResourceHandle()"

HINSTANCE hInstance = LoadLibrary("YourResource.DLL");
AfxSetResourceHandle(hInstance);

Good Luck
0
 
LVL 1

Author Comment

by:hirnsieb
ID: 9626164
Sorry, that doesn't work.
The assertation happens in the Create method of the CFormView class:

#ifdef _DEBUG
      // dialog template must exist and be invisible with WS_CHILD set
      if (!_AfxCheckDialogTemplate(m_lpszTemplateName, TRUE))
      {
            ASSERT(FALSE);          // invalid dialog template name
            PostNcDestroy();        // cleanup if Create fails too soon
            return FALSE;
      }
#endif //_DEBUG

Any ideas?
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 125 total points
ID: 9626166
This is not tested, but I hope will work. Overwrite Create function by the following way:

BOOL CMyView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
    HINSTANCE h = AfxGetResourceHandle();
    AfxSetResourceHandle(hDll);    // set here resource Dll handle

    BOOL b = CFormView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);

    AfxSetResourceHandle(h);
}
0
 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9626180
Put that code in InitInstance of your App class

Good Luck
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9626500
Would it not be simpler for you to export a class in your dll.  You are using a form based view which implies controls on the form and, quite likely, events relating to said controls.
eg.
class AFX_EXT_CLASS CMyView : public CFormView

You then use this class as the basis for your view in your main app.
That keeps the code with the resource.
0
 
LVL 1

Author Comment

by:hirnsieb
ID: 9626603
Thanx for your help!
0
 
LVL 4

Expert Comment

by:inox
ID: 9626609

Hi hirnsieb,
roshmon war schon richtig, aber das geht nur wenn ALLE resourcen in der DLL sind (glaub ich).

P.S.
Creating a view based on CFormView is similar to creating a dialog box. Use the dialog editor to design the dialog box.

In the Styles and More Styles property pages, set the following properties:
In the Style box, select Child (WS_CHILD on).
In the Border box, select None (WS_BORDER off).
Clear the Visible check box (WS_VISIBLE off).
Clear the Titlebar check box (WS_CAPTION off).
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

627 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