Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Loading dialog resource from DLL

Posted on 2003-10-27
7
Medium Priority
?
623 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 500 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

660 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