Solved

Loading dialog resource from DLL

Posted on 2003-10-27
7
559 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
GIF file bit manipulation for color change 5 107
isEverywhere  challenge 19 72
withoutTen challenge 14 100
x-bar in Google Sheets 2 26
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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

896 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

16 Experts available now in Live!

Get 1:1 Help Now