[Webinar] Streamline your web hosting managementRegister Today


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

Posted on 2001-06-06
Medium Priority
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
Question by:Guen
  • 4
  • 2
  • 2
  • +5

Expert Comment

ID: 6158820
IDispatch interface have 4 functions:

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.

Expert Comment

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.

Expert Comment

by:Valliappan AN
ID: 6158908
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

LVL 10

Expert Comment

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.

Expert Comment

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...

Expert Comment

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.

Author Comment

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...

Expert Comment

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.
LVL 49

Expert Comment

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

Author Comment

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

Expert Comment

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

Expert Comment

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

Expert Comment

ID: 7164103
ok. Once more.
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.
LVL 16

Expert Comment

ID: 7707627

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.

Accepted Solution

modulo earned 0 total points
ID: 7758271
Finalized as proposed


Community Support Moderator
Experts Exchange

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

591 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