?
Solved

Wrapper for ActiveX Object

Posted on 2009-04-29
13
Medium Priority
?
1,545 Views
Last Modified: 2013-11-20
Hi experts,
I know this may sound easy, but I really need some advices on this urgently.
I have a third party Active X Object (.ocx) written by using Microsoft C++ 2005 (MFC).  The object contains a dialog based custom control and some control functions.
I wonder if it is possible for me to embed the active X object to my MFC application to reuse its control functions but not the object's GUI, because I'll create my own GUI to use the object's control function.
A step-by-step guide is very much appreciate as I'm really in an urgent.

0
Comment
Question by:cskiong
  • 5
  • 4
  • 3
  • +1
13 Comments
 
LVL 12

Expert Comment

by:williamcampbell
ID: 24263177
The OCX is simply a COM Object that exposes several Interfaces.

You can do a CoCreateObject using it GUID then do a QueryInterface for the control function
Interface.

Use OleView to study the OCX and find its GUID and the exposed Interfaces.

Alternatively if the OCX is registered it should show up as an insertable object. Once inserted you can query it and call hide or set the size to 0,0. Not 1005 sure on this route maybe some experimentation is in order.

Something to start you off anyways.

0
 
LVL 7

Expert Comment

by:HalfAsleep
ID: 24268405
As long as the control functions are not reliant on the component's own GUI, then you can call those control functions if they are exposed, and create your own GUI.  If the Control creates and shows the GUI as soon as you instantiate it, then you are out of luck I think.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 24276338
The simplest technique would be to use the AppWizard create a dialog-based app. In the dialog editor, right-click and select "Insert ActiveX object" then find the object. When you are done, the ClassWizard will provide you with a C++ wrapper for the exposed functions of the object.
There may be exposed functions that do no require a U/I and/or it may be possible to make the window that is normally displayed hidden or set its size to 0,0.
If you need help with any of this, please reply.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:cskiong
ID: 24302347
Hi DanRollins,

I would like to try your way, can you please kindly advise me on these by some step-by-step example?
I tried to Insert the Active X control object to my dialog, somehow it just turns out to be a white rectangular.  I have used OLEView to view the control, luckily the functions are exposed.

Thank you!
0
 
LVL 7

Expert Comment

by:HalfAsleep
ID: 24303361
The functions will have to be exposed AND not have UI dependencies.  Aside from that, the white area, does it show at design time only, or does it show at runtime as well?  A common method, is to create a separate form to put the control on, and keep that form invisible.

After you have added the control to the form, can you call the control methods without getting errors and without the UI appearing?

Also, does this ActiveX rely on a windows handle?  .NET application are not very keen on handing out windows handles (unmanaged/unsafe code??), which may be why you only see a white area, instead of the ActiveX UI properly.
0
 
LVL 7

Expert Comment

by:HalfAsleep
ID: 24303366
Hmm.  I just saw that your application is also MFC, so disregard the .NET part of my comment.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 24303850
If you have used the dialog editor to insert an ActiveX object onto the form, then use the ClassWizard to create a "Control" type variable for that object.  The ClassWizard will then automatically generate .CPP and .H files that describe and will let you access the exposed functions of the object.
-- Dan
0
 

Author Comment

by:cskiong
ID: 24311003
Hi All,  thanks for your suggestions and advices, I'm working on it and it really gives me a great start.  I have to create a wrapper dll for the object so that it can be reused in future for all kinds of Windows Programming language.  Any advices or experiences to share on this?  Thanks in advance.

HalfAsleep, thanks for your suggestion, it is a good approach for me.  Luckily the white area only appears at design time, and I manage to call the control functions with no UI appearing.
0
 

Author Comment

by:cskiong
ID: 24311130
Hi,
I have created a DLL which wraps the ActiveX Object.  I create the ActiveX object in the DLL with the following code Snippet:

However at the VC++ 2005 Compile Output window, it shows the following message when I call the Wrapper->InitControl(this, 0);

Control wants to be windowless
ATL: IOleControlImpl::GetControlInfo not implemented.

Any idea?  Thanks in advance.
int Wrapper::InitControl (CWnd *pWnd, int nCtrlID)
{
CRect rect(0, 0, 50, 50);
m_Object.Create(NULL, 0, rect, pWnd, nCtrlID);
m_Object.ShowWindow(SW_HIDE);
return S_OK;
}

Open in new window

0
 
LVL 7

Expert Comment

by:HalfAsleep
ID: 24311885
I do not know what your wrapper DLL consists of, but an ActiveX component, or any COM object, is dependent on a set of methods from IOleControlImpl among others.

This is because any entity that wants to "contain" an ActiveX component, has to be an ActiveX control container.  My guess is that you will have to declare a class that inherits from IOleControlImpl and maybe others as well, and then implement some of these methods.  I am not very experienced with making ActiveX control containers, so I may be a bit in over my head here.  I will see if I can find out more when I get home from work.

What you can also do, is create a very simple ActiveX component yourself, maybe just containing one property and one method, and see if you can create a wrapper for that.  Another benefit of that, is that you can post the entire source here as well.  Again, I will see if I can find out more after work :)
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 1050 total points
ID: 24313267
An MFC CDialog can act as an ActiveX container.  Perhaps the easiest way to proceed (other than HalfAleep's excellent suggestion above) would be to to make your wrapper actually wrap a CDialog-derived object that contains just one control -- the ActiveX object of interest.
0
 
LVL 7

Assisted Solution

by:HalfAsleep
HalfAsleep earned 450 total points
ID: 24329511
0
 

Author Closing Comment

by:cskiong
ID: 31575986
To DanRollins, thank you for your kind advice, I'm working on with your approach.
To HalfAsleep, really appreciate your help and posts, which really do assist in my work.  Your last post is a good reference to me.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
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.
Suggested Courses

850 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