473,320 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 6379
weaknessforcats
9,208 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

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

Similar topics

21
by: Jason Heyes | last post by:
I want to allow objects of my class to be read from an input stream. I am having trouble with the implementation. Here are the different approaches I have tried: // Version 1.0 - Default...
1
by: ds | last post by:
Launch an exe from Servlet based on mime-type. Hi, I launch a windows based program to handle a custom-defined mime type. Eg: my mime-type = .opti. When a servlet posts a buffered stream...
0
by: Jigar Mehta | last post by:
Hye, I have made some DLL through wizard and added MFC support on my own.. By including general stdafx.h (having MFC support) file into the project.. But it gives me error that main function...
4
by: Anders Eriksson | last post by:
Hello! I'm using VC++ 7.1 and MFC. In a header file that is located in a different directory that the main project I include a header file that is located in the main project directory. The...
0
by: Kannan | last post by:
My application is an MFC application but since MFC is essentially a Object Oriented wrapper for Win32 I am taking the liberty to post my question here. I also must confess that I am not an Active X...
8
by: John E Katich | last post by:
When attempt to use the Event Wizard I get the following error message: "Add/Remove of the function impossible, because the parent class code is read only" The Project was convert from VC 6.0....
4
by: jimmy_sayavong | last post by:
I created a simple MFC program using VC++ 6. It generates EXE file and runs fine on one of my computer which has the C++ compiler installed. But when I copy the EXE program to the other...
1
by: doanwon | last post by:
hello, first post, thanks for reading... Say I create an MFC Dialog program. I then click on an "OnCreateButtons" button to create a long list of MFC buttons/objects, which would then be...
9
by: Hollywood | last post by:
Hello members of the comp.lang.c++, My log file is made of a set of 1000 following lines kind: 21/09/07 13:49:56,MW.SET.D_IGLS,2.000000 21/09/07 13:49:56,MW.SET.GNP_NT,7.000000 ..... ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.