Call MFC DLL from normal C++ app. and load a UI from it

Hi all,

I create a MFC DLL "Static" and with wizard I add a dialog and "Microsoft web browser" ActiveX in this dialog, also I create a class for this Dialog.

All I want here to call this Dll from a Win32 app "normal c++" and load this Dialog into the Main UI, But I got an Assertion error.

Snippet of Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//////////////
// DLL
//////////////
//.h
class CShofhaMFCStaticApp : public CWinApp
{
public:
CShofhaMFCStaticApp();
void CreateBrowser(HWND hWnd);

// Overrides
public:
virtual BOOL InitInstance();
DECLARE_MESSAGE_MAP()

};
extern "C" __declspec(dllexport) void CreateBrowserEx(HWND hWnd);
//.cpp
ShofhaBrowser *m_pMyDlg;
extern "C" __declspec(dllexport) void CreateBrowserEx(HWND hWnd);
CShofhaMFCStaticApp* thisDLL;
__declspec(dllexport) void CreateBrowserEx(HWND hWnd)
{
thisDLL->CreateBrowser(hWnd);
}
CShofhaMFCStaticApp::CShofhaMFCStaticApp()
{
thisDLL = this;
m_pMyDlg = NULL;
}
class tempRoutingFrame {

CFrameWnd* m_pFrame ;

public:

tempRoutingFrame(CFrameWnd * pWnd= NULL)
{
// Save current value
m_pFrame = AfxGetThreadState()->m_pRoutingFrame;
// Set to value passed in. NULL by default.
AfxGetThreadState()->m_pRoutingFrame = pWnd;
}
~tempRoutingFrame()
{
// Restore m_pRoutingFrame to original value.
AfxGetThreadState()->m_pRoutingFrame = m_pFrame;
}

};

void CShofhaMFCStaticApp::CreateBrowser(HWND hWnd)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());

if(m_pMyDlg == NULL)
{ 
CWnd *pParent = CWnd::FromHandle(hWnd);
m_pMyDlg = new ShofhaBrowser(pParent);
m_pMyDlg->Create(IDD_MAIN, pParent); 
m_pMyDlg->ShowWindow(SW_SHOW); 
}
}
//and The dialog
class ShofhaBrowser : public CDialog
{
DECLARE_DYNAMIC(ShofhaBrowser)

public:
ShofhaBrowser(CWnd* pParent = NULL); // standard constructor
virtual ~ShofhaBrowser();

virtual void OnFinalRelease();

// Dialog Data
enum { IDD = IDD_MAIN };

protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

DECLARE_MESSAGE_MAP()
DECLARE_DISPATCH_MAP()
DECLARE_INTERFACE_MAP()
public:
CExplorer1 m_browser;
};
//////////////
// Exe
//////////////
void CMFCtestApp::OnAppAbout()
{
/* get handle to dll */ 
HINSTANCE hGetProcIDDLL = LoadLibrary(TEXT("..\\ShofhaMFCStatic.dll")); 

/* get pointer to the function in the dll*/ 
FARPROC lpfnGetProcessID = GetProcAddress(HMODULE (hGetProcIDDLL),"CreateBrowserEx"); 

/* 
Define the Function in the DLL for reuse. This is just prototyping the dll's function. 
A mock of it. Use "stdcall" for maximum compatibility. 
*/ 
typedef BOOL (__stdcall * pICFUNC)(HWND); 

pICFUNC MyFunction; 
MyFunction = pICFUNC(lpfnGetProcessID); 

HWND fWindow; // Window handle of the window you want to get

fWindow = FindWindow(NULL, _T("Window_title")); // Find the window

///* The actual call to the function contained in the dll */ 
BOOL intMyReturnVal = MyFunction(fWindow); 

/* Release the Dll */ 
FreeLibrary(hGetProcIDDLL);
}


Please Help
Thanks in advance
Topic archived. No new replies allowed.