468,513 Members | 1,834 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,513 developers. It's quick & easy.

How to read .ocx file in C++ (Not MFC)

Hi,

I have an existing .ocx file which contains a map. I need to open this file in C++ and not in MFC. MSDN help suggested me that it can be done throuch " #import "file_name" " However, the description is not descriptive and helpful. If anyone can provide me some ideas or sample code to read this file would be greatful.

Hope someone will give reply to this :-)

Thanks & regards,
Swetha
Nov 24 '07 #1
2 6051
weaknessforcats
9,207 Expert Mod 8TB
A .ocx is a COM object.

Initialize COM in your program and then load the ocx with CoCreateInstance. Then you can QueryInteface and off you go.
Nov 24 '07 #2
Hi,

I have an existing .ocx file which contains a map. I need to open this file in C++ and not in MFC. MSDN help suggested me that it can be done throuch " #import "file_name" " However, the description is not descriptive and helpful. If anyone can provide me some ideas or sample code to read this file would be greatful.

Hope someone will give reply to this :-)

Thanks & regards,
Swetha
The import directive is a Microsoft compiler's propietary prepocessor directive. What this directive does is reading any COM related import library and generate a C++ header file (at pre-compilation time).

Note: Import libraries may live inside DLL or OCX files.

Inside this header file generated at precomiplation time, live the interface definitions of the COM objects included in the import library. Once having these interface definitions, you can get access to the interfaces implementd by the COM objects, without interface defitions you can not access the COM objects; unless said COM objects implement the IDispatch interface.

So, if you are not using the Microsoft compiler, the import directive wont work.

What I did a couple of years ago to overcome this was creating a separate program that would read Import Libraries, and it would spit a C++ header file that would include the definitions of the COM object's interfaces defined inside said Import Libraries. You could do that if you are not using a MIcrosoft compiler.

Now if you are using the Microsoft compiler, you are ready to use the interfaces using some nifty templates like com_ptr<> if I remember correctly.

i.e,

#import "foo.ocx"
using fooclass;
...
com_ptr<IFoo> ifoo;
...

Now bringing an OCX control to life inside a Window without using MFC nor ATL is the closest thing to a punishment from hell you can ever come across in your lifetime; and by bringing it to life I mean displaying it as a control inside a Window, why? because you need to code a control container in your C++ aplication if you want to, that means implementing lots of interfaces.

I wont go any further to avoid confusing you with other details.

Good luck.
Nov 25 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Jigar Mehta | last post: by
4 posts views Thread by Anders Eriksson | last post: by
reply views Thread by Kannan | last post: by
1 post views Thread by doanwon | last post: by
9 posts views Thread by Hollywood | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.