Solved

exe files and ocx

Posted on 2001-06-18
6
204 Views
Last Modified: 2010-05-02
Hi,

I did the following:

Created an OCX with one button and one method inside:

Private Sub Command1_Click()
   MsgBox UserContorl.Parent.MyFunc
End Sub

Then, I put this OCX in another project(exe project) that
have this method:

Public function MyFunc() as long
   MyFunc = 11223344
End function

It worked, but I can't understand how it worked.
Does the exe project is a COM object ?
Does it has some kind of table that keeps is methods ?

Can anyone explain me this mechanism ?

Thanks


0
Comment
Question by:amavr
6 Comments
 
LVL 2

Expert Comment

by:agriggs
ID: 6203355
<ping>
0
 
LVL 1

Expert Comment

by:Freekeko
ID: 6203366
HUH!!!????!!??!??!??!?!?!?!?!?!??!????!???!??
0
 
LVL 5

Expert Comment

by:gbaren
ID: 6203405
amavr,

Yes, everything in VB 4, 5 and 6 is COM-based. The form containing your OCX is a COM object.

Gary
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 5

Expert Comment

by:bob_online
ID: 6203411
The parent property of the user control is a reference to the form on which it resides.

Since MYFunc is public, and the user control has a reference to the form, it can execute it
s code.

0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 100 total points
ID: 6203412
Yes, this works for the following reasion:

VB forms are (some special kind of) com objects, and the property USERCONTROL.PARENT will be assigned internally to the usercontrol when the control is loaded. It will refer to the form it is loaded on.
Now the PARENT variable is internally defined AS OBJECT, and thus any method or property called on this variable will be late bound, thus the entry point will only be looked up when the project (ie this line of code) runs.

At that point, VB code will look if the method MyFunc exists on the object PARENT (yes, it is there) and then executes it.

You can simulate similar behaviour with the CallByName method of VB:
Move the form to the top edge of the screen...
Private Sub Form_Load()
  CallByName Me, "Top", vbPropertyLet, 0
End Sub

 
Cheers
0
 
LVL 5

Expert Comment

by:gbaren
ID: 6203440
amavr,

You should handle all the questions you have open. You have a couple from December.

Go to your profile and grade all the questions that are no longer active. You should do this immediately when you get an answer.

Thanks
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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 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

12 Experts available now in Live!

Get 1:1 Help Now