Solved

Using a ActiveX Control in a DLL

Posted on 2002-06-18
5
461 Views
Last Modified: 2008-01-09
I am new for VC++. I am currently writing a DLL which will in turn invoke the function of ActiveX control.

I create a MFC AppWizard (dll) project and add the reference of the activeX Control. It compiled OK.
I write a simple console program to test it. I seem OK to load the dll. However, when I try to invoke the function of the ActiveX Control. I got error.


void CWnd::GetProperty(DISPID dwDispID, VARTYPE vtProp,
     void* pvProp) const
{
     ASSERT(m_pCtrlSite != NULL);    // not an OLE control (not yet, at least)
....
}

It got error on the first ASSERT statement of the winocc.cpp file. I don't know what is going on. I do call the AfxEnableControlContainer(); already.

Do I miss anything?

0
Comment
Question by:nixonc
5 Comments
 
LVL 22

Expert Comment

by:ambience
Comment Utility
possibly a lot, how are you instantiating the control?
0
 
LVL 3

Expert Comment

by:jimbucci
Comment Utility
An ActiveX control requires a window to draw itself - the client site.  Is your dll itself an ActiveX control?
Are you actually trying to display the wrapped control using your dll?  
The MFC ActiveX control wizard can create a container control which allows you to wrap a control into your control.  It is a pain to implement though.
I suggest creating an ATL composite control and pulling the ActiveX control into it.
I can provide code suggestions since I've done this and it works great.  There are a few caveats so the response would be lengthy.  Let me know if this would help you.
Jim
 
0
 

Author Comment

by:nixonc
Comment Utility
I just declare the control inside the application object which inherite from CWinApp. My dll itself is not an ActiveX control. I not trying to display any thing. Is there a different windowed control and windowless control.

Here are the story. We are developing an application which try to control different brand of digital camera. We try to standardize the interface between the application and the digital camera. SDK from Nikon have been wrapped into a dll easily since it provide all the source code. However, the SDK from Olympus is an ActiveX control.  So I have to wrapped the ActiveX Control into DLL as well.

All I need is a DLL which can invoke the ActiveX function.
What kind of project should I create? Any suggestion?
Can ATL composite control can do?
0
 
LVL 3

Accepted Solution

by:
jimbucci earned 100 total points
Comment Utility
If you're getting a m_pCtrlSite error that means that the ActiveX control is looking for window in which to display itself.  Even if it doesn't display anything it still wants a window.  So you need to trick the ActiveX control into thinking it has a window.  I can suggest one thing to try - create the control on the fly.  Try this:

IOlympusPtr  m_spControl;// smart pointer to control

// Create an ActiveX control instance and place it into this window
   m_spOlympus.CreateInstance(__uuidof(TChart));
   if( m_spChart )
   {
      CComPtr<IAxWinHostWindow> spHost;
      QueryHost(&spHost);
      spHost->AttachControl(m_spControl, m_hWnd);
   }
   This creates a control and gives it a client site.  However you don't have a window.  
I haven't tried this, but create a window handle but don't show it.
   HWND m_Hwnd = CreateWindow(...)
I don't know if this will work - I can try a few things and get back to you.
Good luck.
JB
0
 
LVL 11

Expert Comment

by:griessh
Comment Utility
Dear nixonc

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "jimbucci"

comment(s) as an answer.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

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

12 Experts available now in Live!

Get 1:1 Help Now