We help IT Professionals succeed at work.

Ole and DLL

Nin
Nin asked
on
2,090 Views
Last Modified: 2013-12-04
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??
;)
Comment
Watch Question

Nin

Author

Commented:
Edited text of question.
CERTIFIED EXPERT
Top Expert 2012
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
jkr
CERTIFIED EXPERT
Top Expert 2012

Commented:
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);' ;-)

Commented:
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.
jkr
CERTIFIED EXPERT
Top Expert 2012

Commented:
>>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()')
Nin

Author

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

jkr
CERTIFIED EXPERT
Top Expert 2012

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

Author

Commented:
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.  
jkr
CERTIFIED EXPERT
Top Expert 2012

Commented:
>>beeing inside the regular dll

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

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions