Jump to content
  • Advertisement
Sign in to follow this  

dll window question

This topic is 5072 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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);
*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)
return false;

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!