Solved

Using ActiveX Control in MFC DLL

Posted on 2001-07-11
5
686 Views
Last Modified: 2013-11-20
Hi,

I'm trying to create an MFC DLL that creates a dialog and has a Microsoft Web Browser control in it and use it in a straight-api style windows program. I know my activex stuff is correct because i tried creating a dialog-only mfc exe app with a web browser control in it, and it worked fine. i know my dll function is exported correctly because when the web browser control isn't in the dialog, it acts fine.  Its when i throw the activex control and dll into the mix together that things get nasty. The only thing that the debugger says is that CoCreateInstance has failed, and it asks me if i'm sure the control is registered properly and it lists the CLSID. Any help would be greatly appreciated. I'm new, so I only have 75pts, but you can answer this, they're yours.

-zack
0
Comment
Question by:zack_angelo
5 Comments
 

Author Comment

by:zack_angelo
ID: 6273515
hey guys, i just figured this out--when using activex in an MFC dll, you must call CoInitialize() for the DLL's thread. So...just throw a call to CoInitialize() in your DLL's InitInstance() event and you're all set, I hope this helps out anyone else that was having this problem. It seems that Microsoft has a habit of writing their "wizards" to do everything except a smidgen of a task for you to do...and of course that small task will make everything fall apart. <sigh>

-zack
0
 
LVL 4

Expert Comment

by:mandhjo
ID: 6273754
Don't forget to call CoUninitiliaze in the ExitInstance function.
0
 
LVL 2

Expert Comment

by:tdubroff
ID: 6274116
Yes, CoInitialize() must be called per thread!  In MFC though, I believe you can make a call to AfxOleInit() which does both the CoInitialize() and the CoUninitialize() for you.
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9490295
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ'd and pts refunded

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 9537282
PAQed, with points refunded (75)

Computer101
E-E Admin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now