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??
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NinAuthor Commented:
Edited text of question.
The error code is 'CO_E_NOTINITIALIZED'. You have to call 'CoInitialize( NULL);' before creating the control (if you're using MFC, the call is 'AfxOleInit();')


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day 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);' ;-)
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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()')
NinAuthor Commented:
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'?
NinAuthor 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.  
>>beeing inside the regular dll

I assume this is the reason - try to build a MFC extension DLL..
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.