Solved

creating ocx files in c++ to use in vbasic

Posted on 1998-08-02
11
428 Views
Last Modified: 2013-11-25
What is the structure/format and requirements for creating ocx files in c++ so that it can be used in a visual basic project?
0
Comment
Question by:khurshid
  • 6
  • 5
11 Comments
 
LVL 1

Accepted Solution

by:
tulin earned 50 total points
ID: 1169210
The question is very common. To write ActiveX from begin till the end yourself is a big work. If you have not special resons not to to do this, I suggest you to use ActiveX wizard of MSVC5.0. It will build you the skeleton of an ActiveX control, and you will need only put stuff in the controls methods/events.
   If you still want to write whole control yourself, I'll point you the general thing, but about everyone it's possible to write whole book. It's also depend on what your control suppose to do . The minimum requirment for ActiveX control:
1. It must export DllRegisterServer() and DllUnregisterServer() functions , it will be called when regsvr32.exe will registr/unregister the control, to write into registry control information ( CLSID, implementation, threading model and more...). Registry records have their's own standart. You can see this if you open regedit and go to HKEY_CLASSES_ROOT/CLSID/{your control clsid}/...          and
HKEY_CLASSES_ROOT/<your control progID>
2. It must export DllCanUnloadNow() function to give to know whether the control from which it is exported is still in use.
3.It must export DllGetClassObject() function that will be called when the control will be created.
4.It needs to have the type library - place, where information about controls methods/events/properties/.. is put. It is written in special language (.odl files ), and than the utility mktypelib.exe will compile it is and the result will be put as custom resources of type "TYPELIB" in resourse section and also as .tlb file.
5. It must implement IClassFactory or IClassFactory2 interface to make the "factory" that will produce the instances of your control.
6. It must implement IUnknown interface.
About all of these things you can read in help, but I am not sure that there is enough.

All these things are the minimum is needed only for creation the control. Than, if your control will have a methods, it must implement IDispatch interface, and so on...There are a lot of standart interfaces, and you must decide yourself which of them you need to implement, depend on fuctionality of your control. It's not very simple, so I return one time more that probably will be better if you will use MSVC ActiveX Wizard, it will do most of work. Inspite of that I myself do not like MFC very much, this is the simplest way. For example, when you only have created the control, it has already implemented about 20 interfaces, and probably it will have everything you need.  You can ask more here if you will have a problems.
0
 

Author Comment

by:khurshid
ID: 1169211
First of all thank you for your speedy reply,
  I of course read your answer  and in reply would like to clarify a few points I thought you misinterpreted, maybe because I did not give enough  info in the question for which I apologize.

1. I want to create an object for visual basic in C++(not visual C)
2. According to the info I have, such objects are invoked in VB     as OCX files .
3. This object will help me use a font which is written from            right to left (rather than left to right which is standard like in the     English language)
4. Now what I wanted to know is :
    What is the format for writing a C++ program so that i can use     it as an OCX file?
    It should be kept in mind that this OCX format should be interprettable by VB so that I could use the created OCX file as an object in visual basic.
 A simple example would be wonderful.
 Hope I get a reply soon. Thanks.
                                                        khurshid
0
 

Author Comment

by:khurshid
ID: 1169212
First of all thank you for your speedy reply,
  I of course read your answer  and in reply would like to clarify a few points I thought you misinterpreted, maybe because I did not give enough  info in the question for which I apologize.

1. I want to create an object for visual basic in C++(not visual C)
2. According to the info I have, such objects are invoked in VB     as OCX files .
3. This object will help me use a font which is written from            right to left (rather than left to right which is standard like in the     English language)
4. Now what I wanted to know is :
    What is the format for writing a C++ program so that i can use     it as an OCX file?
    It should be kept in mind that this OCX format should be interprettable by VB so that I could use the created OCX file as an object in visual basic.
 A simple example would be wonderful.
 Hope I get a reply soon. Thanks.
                                                        khurshid
0
 
LVL 1

Expert Comment

by:tulin
ID: 1169213
Hi,
there are answers on your questions.

>>>OCX format should be interprettable by VB so that I could use the created OCX file as an object in visual basic.
OCX is a file extension of  an objects that are ActiveX controls. This is a common format is based on COM model is developed by Microsoft. The idea is to create a separate components that will be usable from different other applications. In your case this is Visual Basic, but for example Internet Explorer or VisualC itself also support ocx. So ActiveX controls have common build principles. If you will develop it right, you will be able to use it from VB as well as from other applications are pointed above.
   Second thing is how to create an ActiveX. This depends on what C++ compiler you use. Nowadays usually either VisualC++ of Microsoft or CBuilder of Borland is in use. The first one has an ActiveX Wizard, that helps to build you a control. About the second one I am not sure, may be it also has something like this. It will be not bad if you say what compiler you use...:-)
  If you don't want to use by wizards, you can try to build the control yourself, but this is not so simple. The ActiveX inside looks like dll, so your project may be opened as dll. But there are some requirments about the function must be ex
0
 
LVL 1

Expert Comment

by:tulin
ID: 1169214
exported (see my first answer). In additional you should write the type library, compile this and result binary data put as resources of type "TYPELIB" in your project. In every case, if you really want to understand how an ActiveXs work and write it yourself, my answer will be not enough. You must look at the books. The good one is the book of Kraig Brockchmidt "Ole Inside", 2-nd edition. Hope my answers give you something.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:khurshid
ID: 1169215
Thankyou for your answer.
You did not comment on Point no. 3 of my question. That is what i am really after. I dont think Borland C++ has any such wizards  that you mentioned nevertheless I shall check.

I would like to include that I only insist on using C++ since I have good practice in this language. I would welcome your suggestion as to make  a switch to Visual C++ If you think that it  would be easier for me to implement what I am after (refer to point # 3 of my comment.
      I have never used Visual C before !!!!
0
 
LVL 1

Expert Comment

by:tulin
ID: 1169216
Borland C++ is not a good solution for developing ActiveXs.
You have to use either Borland C++ Builder or Microsoft Visual C++. I have an expirence in Visual C++, but I don't want to suggest you this only for this reason, may be to  continue with Borland  will be better for you. Now I install C++ Builder and check how it can help you.
  #3 - what do you exactly want to do?
0
 

Author Comment

by:khurshid
ID: 1169217
What I want to do is use a font in the VB textbox object which works from right to left (like Arabic).

Since there is no option available in VB (atleast none to my knowledge so far) which would help the font to work right to left, I wanted to create an object for Visual Basic in C++ which I shall use to achieve the right to left writing in a Visual Basic textbox object. For this I need the OCX format so that I can include my C++ object in my VB project. Hope to hear from you soon.
                                            Thanx.                                  


0
 
LVL 1

Expert Comment

by:tulin
ID: 1169218
Hi,
I have checked the C++ Builder - it has not anything you need.
 So, I recommend you to use Visual C++. (version 5)

Your steps in control building will be like this:
1. You choose "New..." option in menu, and then MFC ActiveX control Wizard. Give a name to the project.
2. On the first screen you get you press "Next" button.
3. On the second window in combo "which control your control will subclass..." you chose EDIT option.
4. Press "Finish" button. Wizard will generate you project files.
5. Then I have two ways, how to solve your task.
   a) You go to C<YourName>Ctrl::PreCreateWindow() function
   and change the window styles, for example like this
    cs.dwExStyle &= ~WS_EX_LTRREADING;  // throw left-to-right reading style
    cs.dwExStyle |=  WS_EX_RTLREADING; // add right to left reading style
   But you must have your right-to-left language support on the computer. I am not sure 100% that this way will work.

   b) second way is to overload window procedure of your control. You go to the "Class Wizard", choose in right list box "WindowProc" and press "Add function". You write yourself function body - relevant messages processing, to give to the contro
0
 
LVL 1

Expert Comment

by:tulin
ID: 1169219
control functionality as you want. This way is a little more longer, but more sure.
  Good luck.
0
 

Author Comment

by:khurshid
ID: 1169220
Hi,
   I'll have to try this out to see whether it works or not so I cannot grade you until then, but be sure I'll get back to you.
 
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now