Solved

Loading dialog resource from DLL

Posted on 2003-10-27
7
575 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
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add content to output file 4 67
maxBlock challenge 30 142
while loop over for loop 7 115
Smart Camera scanning and reading information 3 114
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…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

830 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