Using a ActiveX Control in a DLL

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?

nixoncAsked:
Who is Participating?
 
jimbucciConnect With a Mentor Commented:
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
 
ambienceCommented:
possibly a lot, how are you instantiating the control?
0
 
jimbucciCommented:
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
 
nixoncAuthor Commented:
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
 
griesshCommented:
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
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.

All Courses

From novice to tech pro — start learning today.