Solved

Using ActiveX Control in MFC DLL

Posted on 2001-07-11
5
685 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
Comment Utility
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
Comment Utility
Don't forget to call CoUninitiliaze in the ExitInstance function.
0
 
LVL 2

Expert Comment

by:tdubroff
Comment Utility
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
Comment Utility
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
Comment Utility
PAQed, with points refunded (75)

Computer101
E-E Admin
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa‚Ķ
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

743 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

15 Experts available now in Live!

Get 1:1 Help Now