Solved

Loading dialog resource from DLL

Posted on 2003-10-27
7
549 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 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

12 Experts available now in Live!

Get 1:1 Help Now