?
Solved

OLE Control fails in a dialog in a DLL.

Posted on 1998-06-06
5
Medium Priority
?
899 Views
Last Modified: 2013-11-25
I have a DLL. There is a dialog in this DLL which I call from the application. The dialog has a MSComm OLE control. Everything works fine if the dialog resources is in app. If it is in the DLL, CoCreateInstance of the control fails which makes the dialog creation failing. Can OLE control be invoked in a dialog in DLL?
0
Comment
Question by:chacko
  • 2
  • 2
5 Comments
 

Expert Comment

by:t004024
ID: 1316123
if it helps, I had to do something similar, create an ole control in a DLL.

The DLL uses the context state of the application, so if U have not initialized Ole in the application, the DLL call fails. If U check the help, he says, U need to call AfxEnableControlContainer() to enable activex control containment. This can be done either in the application or the DLL. If U are initializing and enabling control containment in  the DLL, then U need to call AFX_MANAGE_STATE(AfxGetStaticModuleState()) in every exported function, so that the DLL, uses U'r DLL state and not the state of the application.

My problem was, even if though the CoCreateInstance created the control correctly, any other call, like setting a property or invoking a method failed, this was because, when I created an instance I was not providing the control with a control site!!! But I was trying to create the control as any other automation object and that is not possible I think.
0
 
LVL 1

Accepted Solution

by:
IgorGrebnev earned 100 total points
ID: 1316124
Dear chacko

You need to call AfxOleInit( ) in the InitInstance of your DLL. Calling of AfxEnableControlContainer() in DLL is not enough, I found it on experience.
You need to do this of you are using MFC Regular DLL ( I guess you use it ).
Sincerely yours,
Igor.

0
 
LVL 1

Author Comment

by:chacko
ID: 1316125
Dear Igor,

I tried AfxOleInit() in the calling application InitInstance not in DLL InitInstance. Could u please clarify?

thanks,
chacko
0
 
LVL 1

Expert Comment

by:IgorGrebnev
ID: 1316126
Dear chacko

You need to call AfxOleInit() for regular ( not extension ) DLLs.
I do not know exactly why.
If you create extension DLL it use the same enviromen block of MFC as applicatoin, so you do not need to call AFX_MANAGE_STATE(AfxGetStaticModuleState()) in every exported and fo not need specific initialisation of MFC. In regular DLL with shared MFC you need it.
Just add the call to AfxOleInit() and AfxEnableControlContainer() and check result.
Yours,
Igor.
      function
0
 

Expert Comment

by:t004024
ID: 1316127
If U have Ole initialized in the application, the the AfxOleInit() function in the DLL, will  give U an assertion, because, Ole is already initialized. If U have the AfxOleInitialize and AfxEnableControlContainer in U'r application, then U'r control creation in the DLL, should work fine, without any module specific initialization and so without AFX_MANAGE_STATE.

If U call AfxEnableControlContainer(), what this really does is initialize the afxOccManager of the current state(U can look at the occmgr.cpp file in the mfc src). So, if AfxEnableControlContainer is called in the InitInstance of the DLL, the afxOccManager in the DLL module is initialized and not that in the application instance.

AFX_MANAGE_STATE(AfxGetStaticModuleState()) is required when the state in which U want U'r dll exported function to run is different from that of the application, and that is how it is here. The DLL state should provide for a OccManager, where as the application does not provide for a OccManager.
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question