Link to home
Start Free TrialLog in
Avatar of Nin
Nin

asked on

Ole and DLL

I am programming in VC++ 5 in NT. I've included a dialog in a regualr dll; and in the dialog there is an ole control. When I try to create an instance of the dialog I get the following error in the debug window:

CoCreateInstance of OLE control {53D4F583-DE5B-11D0-8B6C-444553540000} failed.
>>> Result code: 0x800401f0
>>> Is the control is properly registered?
Warning: CreateDlgControls failed during dialog init.
Warning: Dialog creation failed!

The control is already registered in the system (I have used it in a normal application). What do I need to do to register on line (I suppose) the control for the dialog to work correctly??
;)
Avatar of Nin
Nin

ASKER

Edited text of question.
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
BTW: This call is used to initialize athe OLE libraries, no function related to COM/OLE will work unless 'CoInitialize()' is called. The best place for this call is in the constructor of your dialog, and 'CoUninitialize()' should be placed i the dialogs destructor, hence. And: You could also use 'OleInitialize ( NULL);' ;-)
Though OleInitialize(NULL) is inefficient if you're not programming compound documents. BTW, just to be picky ( ;-) ), I believe that CoTaskMemAlloc and CoTaskMemFree will work without the COM library having been initialized.
>>I believe that CoTaskMemAlloc and CoTaskMemFree will
>>work without the COM library having been initialized

Nope, they won't - the COM libraries' heaps are allocated when the DLLs are initialized.
BTW: 'OleInitialize()' & 'AfxOleInit()' are mainly wrappers around 'CoInitialize()' - the just perform a few other things (see the source of 'AfxOleInit()')
Avatar of Nin

ASKER

jkr, is there any other initialization to be done?
the creation of the dialog is successful, but now the control is behaving strange.

No, 'CoInitialize()' usually is enough - or are you using MFC?
In what way is it behaving 'strange'?
Avatar of Nin

ASKER

I am using MFC (initialized with AfxOleInit();) and now when I create an instance of the dialog the control registered correctly; But still the control does not seem to work. It seems that beeing inside the regular dll afects the ole control in a stange way, because I'vw used the same control in another non dll application and it works fine.  
>>beeing inside the regular dll

I assume this is the reason - try to build a MFC extension DLL..