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??
;)
NinAsked:
Who is Participating?
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.
0
jkrCommented:
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();')

0

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
jkrCommented:
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);' ;-)
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

semckCommented:
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.
0
jkrCommented:
>>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()')
0
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.

0
jkrCommented:
No, 'CoInitialize()' usually is enough - or are you using MFC?
In what way is it behaving 'strange'?
0
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.  
0
jkrCommented:
>>beeing inside the regular dll

I assume this is the reason - try to build a MFC extension DLL..
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.