Sign in to follow this  
CProgrammer

dll window question

Recommended Posts

CProgrammer    303
Basically I want to pack the window into a dll. Any kind of window. The exe shoudl the dll via LoadLibrary and export some functions TO the dll. First of: How can I have the window defined in the dll. Do I just substitude 'int main' or WinMain for DLLMain? Furthermore is it possible to have this kind of interaction? -CProgrammer

Share this post


Link to post
Share on other sites
Box2020    142
The method I use involves creating a standard MFC extension dll with an exported function called Init.


extern "C" AFX_EXT_API
UINT Init(CString* confirm,CString* pname,CRuntimeClass **pEditRunTimeClass)
{
new CDynLinkLibrary(WordFitDLL);
*confirm="GLLabPlugin";
*pname ="WordSearch";
*pEditRunTimeClass = RUNTIME_CLASS(CMyDllView);

return 0;
}





The view is defined in the dll and the ability to create it is wrapped up by the RUNTIME_CLASS stuff.

You then load the dll


typedef UINT ( * LPDLLINIT)(CString* confirm,CString* pname,CRuntimeClass **pEditRunTimeClass);


CRuntimeClass* prtcedit;
CString fname="mydllview.dll";
hDLL = LoadLibrary(fname);

dllInit = (LPDLLINIT)::GetProcAddress(hDLL,"Init");
if (!dllInit)
{
FreeLibrary(hDLL);
return false;
}
else
{
dllInit(&verify,&activityName,&prtcedit);




Now, from within the document, you can create the view using

CCreateContext context;
context.m_pNewViewClass = prtcedit;
context.m_pCurrentDoc = this;
CView* pNewView = STATIC_DOWNCAST(CView, pMainWnd->CreateView(&context));







The best thing about this method is thet the objects are created in the app and not the dll so you don't get problems with stack/heap ownership issues

Hope this helps

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this