Solved

getting method's names and params by object and invoke (com)

Posted on 2001-06-06
15
302 Views
Last Modified: 2013-11-25
how can i get an object's methods names and the parameters they should get ? and how do u invoke it without knowing the number of parameters since u invoke a different method each time in vb ?
callbyname needs a specific number of params, u have to write it out for him or use Array but it's the same thing
i'm trying to do it in c++ for the moment but
it seems very strange that u can't do it right in vb
0
Comment
Question by:Guen
  • 4
  • 2
  • 2
  • +5
15 Comments
 
LVL 2

Expert Comment

by:kmv
ID: 6158820
IDispatch interface have 4 functions:
GetTypeInfoCount
GetTypeInfo
GetIDsOfNames
Invoke

First 3 functions are used to get information about function and its parameters. Most important of them is GetIDsOfNames but all of them are used of course.

All object used in VB have interfaces inherited from IDispatch.

Same way is used for internal (not COM) objects.
If you need more info - read MSDN and ask questions.

Good luck.
0
 
LVL 1

Expert Comment

by:morgan_peat
ID: 6158833
Set a reference to 'TypeLib Information' in VB.
Then do something like the following:

    Dim oTLI As tli.TLIApplication
    Dim oInfo As tli.InterfaceInfo
    Dim oObject As Object
    Dim oMemberInfo As tli.MemberInfo
   
   
    ' Create some new object
    Set oObject = CreateObject("ADODB.Connection")
   
    ' Get info about it
    Set oTLI = New tli.TLIApplication
    Set oInfo = oTLI.InterfaceInfoFromObject(oObject)
   
    ' Have a look at item 21 (I know this is Open)
    Set oMemberInfo = oInfo.Members.Item(21)
   
    Debug.Print oMemberInfo.Name
    Debug.Print oMemberInfo.Parameters.Count


You can also get more info about the parameters from the Parameters Collection.
The TLI should give you enough information to be able to use CallByName.
0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6158908
interesting...
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 6159108
It doesn't really make sense to do something like this in VB. VB is a RAD development language, not a full-fledged 3rd Generation language like C++

Amorphous blobs of objects that you'd have to go and probe in order to find out what exactly they do and how exactly to approach them? Seems a bit odd in VB.

In C++ you can query an object's interface and find out what it does. In VB, typically, you would add a reference to a COM component to your project, and then you *know* what it can do. No probing needed.
0
 
LVL 1

Expert Comment

by:morgan_peat
ID: 6159607
The only reason I can think of (which is a valid reason) is to examine the objects that are registered on the machine.

You could browse the CLSID key, or get the user to type in a PROGID, and show methods / properties of the objects.

Why you wouldn't use the object browser, I don't know...
0
 
LVL 2

Expert Comment

by:kmv
ID: 6162230
What do you want: to know how it works inside VB (how compiler does it) or how to know what parameters are used in each method of VB?
In VB you can call procedures by name. In C/C++ - by address in memory. Do you want to call procedure in VB by addr or something like this?
Could you tell us exactly what do you want to know?

Thank you.
0
 

Author Comment

by:Guen
ID: 6163197
well, i'm writing a method tester, it recieves the object name, creates it and supplies the user with all method names and parameters according to the method chosen
and then activate it with the parameters, so not only
i can't get that info in vb, callByName can't accept a vector of arguments, it needs spelling out so only
a disgusting select-case will work...
0
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

 
LVL 2

Expert Comment

by:kmv
ID: 6168010
Unfortunatelly, I don't know how to help you. May be there are some undocumented functions but I think that it is impossible. It is done on compilator's level. You can only use callByName for functions with same arguments (sin, cos, tan etc.) and use select-case.

You can do it for COM objects with IDispatch interface.
For user defined objects you need some information about its structure. Possible you need to parse source code of object and get information which you need.

If you have more questions you are welcome.

Good luck.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7133333
Hi Guen,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Accept kmv's comment(s) as an answer.

Guen, if you think your question was not answered at all or if you need help, you can simply post a new comment here.  Community Support moderators will follow up.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 

Author Comment

by:Guen
ID: 7133570
I don't think I got an answer to this question, an I solved it by myself.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7133592
Hi guen,
Can you post your solution?  That would let us refund your points and save this Question to the PAQ  -- for future reference.  Thanks!
-- Dan
0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 7136910
Im not sure, thought morgan_peat's one, answer in finding the params for an object.
0
 
LVL 2

Expert Comment

by:kmv
ID: 7164103
ok. Once more.
2Guen.
1. Objects created in VB as instance of VB class are COM objects.
2. VB usually works with objects using IDispatch COM interface.
I enumerated methods of IDispatch interface in my first message. When I developed 2 years ago some special object to asynchronize COM objects I used scheme with IDispatch interface. Using it you can get all information about methods and parameters of COM object, set its values and call any method by its name.
Its enouph to read MSDN about IDispatch to get this information.
But using VB you cannot work with IDispatch directly (you can only get reference to IDispatch but cannot call its methods). All functionality with IDispatch interface is covered by VB framework. You cannot use next code in VB
Dim obj As Object
Dim adoObj As New ADODB.Connection
Dim mem(100) As Long
Dim pMem As Long
Set obj = adoObj ' here is reference to IDispatch
pMem = VarPtr(mem(0))
obj.GetIdsOfNames(0, "Open", 1, 0, pMem) ' here you'll get error message - object doesn't support method. It means that VB itself use method name "GetIdsOfNames" to pass it through IDispatch interface method GetIdsOfNames. As far as IDispatch is not inherited by itself, vb function call of method GetIdsOfNames returns error. VB calls necessary methods to make late binding via IDispatch itself authomatically. You cannot make some trick here.
You can do it using your own COM object written, e.g. on C/C++.

I thought that information which I gave above (in my previous posts) is enouph to find good solution, isn't it?
If you didn't understand it - you could ask more detailed question to clarify situation.

Best regards.
0
 
LVL 16

Expert Comment

by:twalgrave
ID: 7707627
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
- PAQ/no refund re DanRollins Comment 07/06/2002 03:02AM PST
Please leave any comments here within the
next seven days.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 7758271
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Window placement 17 65
Replace Formatted Numbers with text 9 51
VBA color chart bars 12 65
VB 6.0 printer how to align 6 49
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

706 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

22 Experts available now in Live!

Get 1:1 Help Now