472,958 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 6360
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.