[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 322
  • Last Modified:

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

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
Guen
Asked:
Guen
  • 4
  • 2
  • 2
  • +5
1 Solution
 
kmvCommented:
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
 
morgan_peatCommented:
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
 
Valliappan ANCommented:
interesting...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
caraf_gCommented:
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
 
morgan_peatCommented:
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
 
kmvCommented:
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
 
GuenAuthor Commented:
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
 
kmvCommented:
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
 
DanRollinsCommented:
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
 
GuenAuthor Commented:
I don't think I got an answer to this question, an I solved it by myself.
0
 
DanRollinsCommented:
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
 
Valliappan ANCommented:
Im not sure, thought morgan_peat's one, answer in finding the params for an object.
0
 
kmvCommented:
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
 
twalgraveCommented:
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
 
moduloCommented:
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 4
  • 2
  • 2
  • +5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now