Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I have got dll staticly linked to mfc.
In the dll is dialog class located.
I call exported function from main program.
void __stdcall ShowMMInfo(DWORD id, HWND parent)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	CMainDialog dlg(CWnd::FromHandle(parent));
	dlg.DoModal();
}

In DoModal occures an unhandled exception in the line
if (CreateDlgIndirect(lpDialogTemplate,
                CWnd::FromHandle(hWndParent), hInst))


What can be wrong?


Update:
I have replaced Skin Controls from our library with mfc controls. After that program begun work well.
But i need Skin controls in that dialog.

In main program skin controls work well.
What should i do to make skin controls to load well?
I just added lib file to link and include header files.
I took a look with hdependency walker: there are skin controls classes.

But when i replace for example CDialog with CSCScaleDialog i got an exception.

I tryed to link staticly and dinamicly to main program, but there is no difference.
Posted
Updated 30-Mar-11 2:35am
v2
Comments
Richard MacCutchan 30-Mar-11 4:12am    
Check what the exception is, that may give you a clue.
[no name] 30-Mar-11 4:17am    
Access violation.
[no name] 31-Mar-11 7:16am    
I resolved problem moving files from dll project to exe project.

It could be the hInst. We have had problems with this and include the following code:

class CMyApp : public CWinApp
{
public:
  CMyApp();
  ~CMyApp();

// Overrides
public:
  virtual BOOL InitInstance();
  virtual int ExitInstance();

  static HINSTANCE GetInstance();

  DECLARE_MESSAGE_MAP()
};

// In the body

HINSTANCE hMyInst = 0;

// The one and only CMyApp object
CMyApp theApp;

BOOL CMyApp::InitInstance()
{
  CWinApp::InitInstance();
  hMyInst = AfxGetInstanceHandle();

  return TRUE;
}

int CMyApp::ExitInstance()
{
  return CWinApp::ExitInstance();
}

HINSTANCE CMyApp::GetInstance()
{
  return hMyInst;
}


The your code becomes:

if (CreateDlgIndirect(lpDialogTemplate,
             CWnd::FromHandle(hWndParent), CMyApp::GetInstance()))
 
Share this answer
 
Comments
[no name] 30-Mar-11 4:40am    
if (CreateDlgIndirect(lpDialogTemplate, CWnd::FromHandle(hWndParent), CMyApp::GetInstance()))

is not my code.
It is mfc 42 code.
Hi,

Make sure that the Dialog resource is in your dll project. AFX_MANAGE_STATE(AfxGetStaticModuleState()); sets the current resoure handle as that of dll. So if the specified dialog resource is not found in dll CreateDlgIndirect will fail.

hope this helps
 
Share this answer
 
Comments
[no name] 30-Mar-11 5:00am    
Thank you. I decided to recreate dialog class and all functionality as if i just begin to make dialogs. Simple not skined dialog works well.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900