Creating window in regular DLL that link MFC through a entry point function

  • Thread starter Thread starter Jeff0803
  • Start date Start date
J

Jeff0803

Guest
I tried sample MFC code.
This DLL's entry point is My_Entry() which is exported by MFCDLL.DEF file for other application to call it and removed existing DllEntry() because I will add initialize code in the CMyApp.InitInstance().


// MFCDLL.def
LIBRARY
EXPORTS
; Explicit exports can go here
DS_Entry
-------------------------------------------------------------------------
// MFCDLL.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include <afxwin.h>
class CMyApp : public CWinApp
{
public:
virtual BOOL InitInstance ();
};
class CMainWindow : public CFrameWnd
{
public:
CMainWindow();
protected:
afx_msg void OnPaint ();
DECLARE_MESSAGE_MAP()
};
CMyApp myApp;
BOOL CWinApp::InitInstance()
{
m_pMainWnd = new CMainWindow;
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
BEGIN_MESSAGE_MAP(CMainWindow, CFrameWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()
CMainWindow::CMainWindow()
{
Create (NULL, _T("The Hello Window"));
}
void CMainWindow::OnPaint()
{
CPaintDC dc (this);

CRect rect;
GetClientRect(&rect);
dc.DrawText(_T("Hello, MFC"), -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
void FAR PASCAL My_Entry( )
{
// How to initialize MFC here to show Hello, MFC window?

// I tried following function here but nothing happened

// AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0);

}

This is a typical MFC hello program except My_Entry which is the entry point of this DLL and called from other application program.
MFC class interfaces cannot be exported and for some other reason, this DLL should have this kind of structure.
I want to know how to add code in the My_Entry() to show Hello window.
What should I do in the My_Entry()?

Continue reading...
 
Back
Top