volking
asked on
iUnknown COM QueryInterface AddRef Release
I need a routine (written in VB) which will accept any OBJECT as a parameter and is then capable of walking through ALL PUBLIC PROPERTIES of the incoming object (similar to walking through a collection using a ForEach/Next loop might do). I need to know the property names, data types AND have access to the property value itself.
Another way of thinking about this problem is to imagine that I want to duplicate the functionality of the VB Object Browser, where all the PUBLIC items in an object are displayed along with their datatype.
I need to do this in VB, so please, no C++ solutions.
Another way of thinking about this problem is to imagine that I want to duplicate the functionality of the VB Object Browser, where all the PUBLIC items in an object are displayed along with their datatype.
I need to do this in VB, so please, no C++ solutions.
http://vbaccelerator.com/codelib/imalloc/objstore.htm
"toring Objects Against ItemData and Tag properties"
http://www.vb2themax.com/HtmlDoc.asp?Table=Books&ID=1500&Page=1
"toring Objects Against ItemData and Tag properties"
http://www.vb2themax.com/HtmlDoc.asp?Table=Books&ID=1500&Page=1
Learning. -e2
You'll need TlbInf32.dll documentation:
http://members.home.net/bruce2u2/hackhall.htm
TypeLib Information Library by Matt Curland. Actually TlbInf32.dll comes with Visual Basic, 5 or 6. This is just the long-awaited documentation file. Once you figure out how everything works, you'll be able to write your own object browser, create wizards to manipulate classes, and do lots of other cool stuff.
http://members.home.net/bruce2u2/hackhall.htm
TypeLib Information Library by Matt Curland. Actually TlbInf32.dll comes with Visual Basic, 5 or 6. This is just the long-awaited documentation file. Once you figure out how everything works, you'll be able to write your own object browser, create wizards to manipulate classes, and do lots of other cool stuff.
You might look into this file written by Matt Curland. It explains how to use the Tlbinf32.dll, its what the VB object browser uses to enumerate VB objects.
The self-extracting zip contains a .chm file thats very extensive.
ftp://ftp.microsoft.com/softlib/mslfiles/tlbinf32.exe
Good Luck :)
Paul
The self-extracting zip contains a .chm file thats very extensive.
ftp://ftp.microsoft.com/softlib/mslfiles/tlbinf32.exe
Good Luck :)
Paul
Yep, that's the same 'documentation file' I mentioned.
ameba wrote:
>This is just the long-awaited documentation file.
wpsjr1, there is no need to lock the question.
Also, points should be reduced, I think.
ameba wrote:
>This is just the long-awaited documentation file.
wpsjr1, there is no need to lock the question.
Also, points should be reduced, I think.
:ping:
wpsjr1 ,
https://www.experts-exchange.com/v3.0/statics/expertonly.html
You will find that most experts here will generally post comments instead of answers
in order to keep the question in the high traffic "questions awaiting answers" section.
Locking a question is unfair to the person asking the question since it might not
be seen by other experts who can add infornation to the question.
There is no penalty to you, as the questioner can accept any comment as an answer.
You don't see the accept comment as answer but the person posting the question can.
Please use the options on the bottom of the page to withdraw your answer to a comment.
Also, please note that an 'answer' is supposed to be 100% sure to fix the problem. And is against to post as an answer another expert's comments
https://www.experts-exchange.com/v3.0/statics/expertonly.html
You will find that most experts here will generally post comments instead of answers
in order to keep the question in the high traffic "questions awaiting answers" section.
Locking a question is unfair to the person asking the question since it might not
be seen by other experts who can add infornation to the question.
There is no penalty to you, as the questioner can accept any comment as an answer.
You don't see the accept comment as answer but the person posting the question can.
Please use the options on the bottom of the page to withdraw your answer to a comment.
Also, please note that an 'answer' is supposed to be 100% sure to fix the problem. And is against to post as an answer another expert's comments
Hey, volking.
You'll get more responses if you reject wpsjr1's supposed answer.
Bye. -e2
You'll get more responses if you reject wpsjr1's supposed answer.
Bye. -e2
ASKER
For 1000 points ... I expect more than a pointer to a document. If I wanted to spend several hours digging through documentation, I would have put the points at 200-300 which would have elicited the much the same responses as I've had to now.
For 1000 points ... I expected to connect with somone who had actually ACCOMPLISHED the task and could give me a code snippet or such.
For 1000 points ... I expected to connect with somone who had actually ACCOMPLISHED the task and could give me a code snippet or such.
Maybe you can start with this
' add reference to 'TypeLib Information'
' add component 'MS Common Dialog Control 6.0'
' Form1, add texbox (multiline=true), and commondialog
Option Explicit
Dim tla As New TLIApplication
Dim tlin As TLI.TypeLibInfo
Private Sub Form_Click()
On Error Resume Next
CommonDialog1.Filter = "Object Libraries (*.ocx, *.dll, *.tlb)|*.ocx;*.dll;*.tlb|S vi zapisi (*.*)|*.*"
CommonDialog1.DialogTitle = "Select"
CommonDialog1.CancelError = True
CommonDialog1.ShowOpen
If Err <> 32755 Then 'user pressed cancel
Caption = CommonDialog1.filename
Text1.Text = ShowInfo(CommonDialog1.fil ename)
End If
End Sub
Private Sub Form_Load()
'CommonDialog1.filename = "C:\windows\system\richtx3 2.ocx"
Show
Print "Click me to select file"
End Sub
Private Sub Form_Resize()
On Error Resume Next
If WindowState <> vbMinimized Then
Text1.Move 60, 240, ScaleWidth - 120, ScaleHeight - 300
End If
End Sub
Public Function ShowInfo(filename As String) As String
On Error GoTo EH
Set tlin = tla.TypeLibInfoFromFile(fi lename)
ShowInfo = tlin.Name
ShowInfo = ShowInfo & vbCrLf & "Version: " & tlin.MajorVersion & "." & tlin.MinorVersion
ShowInfo = ShowInfo & vbCrLf & "coclasses " & tlin.CoClasses.Count
ShowInfo = ShowInfo & vbCrLf & "constants " & tlin.Constants.Count
ShowInfo = ShowInfo & vbCrLf & " typeinfos " & tlin.TypeInfoCount
Dim i As Integer
Dim ti As TLI.TypeInfo
For Each ti In tlin.TypeInfos
ShowInfo = ShowInfo & vbCrLf & ti.TypeKind & " " & ti.Name
ShowInfo = ShowInfo & vbCrLf & " has " & ti.Members.Count & " members,"
ShowInfo = ShowInfo & vbTab & " typekind " & ti.TypeKind
Next
For Each ti In tlin.TypeInfos
Select Case ti.TypeKind
Case 0
ShowInfo = ShowInfo & vbCrLf & ti.TypeKindString & " " & ti.Name
ShowInfo = ShowInfo & vbTab & " has " & ti.Members.Count & " members:"
Dim tm As MemberInfo
For Each tm In ti.Members
ShowInfo = ShowInfo & vbCrLf & " " & tm.Name & " = " & CStr(tm.Value)
Next
Case 4
ShowInfo = ShowInfo & vbCrLf & ti.TypeKindString & " " & ti.Name
ShowInfo = ShowInfo & vbTab & " has guid " & ti.Guid
Dim tc As TLI.MemberInfo
For Each tc In ti.Members
ShowInfo = ShowInfo & vbCrLf & " " & tc.Name & " par " & CStr(tc.ReturnType)
Next
End Select
Next
ShowInfo = ShowInfo & vbCrLf & "Unions:"
Dim tu As TLI.UnionInfo
For Each tu In tlin.Unions
ShowInfo = ShowInfo & vbCrLf & tu.Name & " " & tu.TypeKindString
Next
ShowInfo = ShowInfo & vbCrLf & "Records:"
Dim tr As TLI.RecordInfo
For Each tr In tlin.Records
ShowInfo = ShowInfo & vbCrLf & tr.Name & " " & tr.TypeKindString
Next
Exit Function
EH:
If Err <> -2147220984 Then
ShowInfo = ShowInfo & vbCrLf & " >>>>>> Error: " & Err.Description
End If
Resume Next
End Function
' add reference to 'TypeLib Information'
' add component 'MS Common Dialog Control 6.0'
' Form1, add texbox (multiline=true), and commondialog
Option Explicit
Dim tla As New TLIApplication
Dim tlin As TLI.TypeLibInfo
Private Sub Form_Click()
On Error Resume Next
CommonDialog1.Filter = "Object Libraries (*.ocx, *.dll, *.tlb)|*.ocx;*.dll;*.tlb|S
CommonDialog1.DialogTitle = "Select"
CommonDialog1.CancelError = True
CommonDialog1.ShowOpen
If Err <> 32755 Then 'user pressed cancel
Caption = CommonDialog1.filename
Text1.Text = ShowInfo(CommonDialog1.fil
End If
End Sub
Private Sub Form_Load()
'CommonDialog1.filename = "C:\windows\system\richtx3
Show
Print "Click me to select file"
End Sub
Private Sub Form_Resize()
On Error Resume Next
If WindowState <> vbMinimized Then
Text1.Move 60, 240, ScaleWidth - 120, ScaleHeight - 300
End If
End Sub
Public Function ShowInfo(filename As String) As String
On Error GoTo EH
Set tlin = tla.TypeLibInfoFromFile(fi
ShowInfo = tlin.Name
ShowInfo = ShowInfo & vbCrLf & "Version: " & tlin.MajorVersion & "." & tlin.MinorVersion
ShowInfo = ShowInfo & vbCrLf & "coclasses " & tlin.CoClasses.Count
ShowInfo = ShowInfo & vbCrLf & "constants " & tlin.Constants.Count
ShowInfo = ShowInfo & vbCrLf & " typeinfos " & tlin.TypeInfoCount
Dim i As Integer
Dim ti As TLI.TypeInfo
For Each ti In tlin.TypeInfos
ShowInfo = ShowInfo & vbCrLf & ti.TypeKind & " " & ti.Name
ShowInfo = ShowInfo & vbCrLf & " has " & ti.Members.Count & " members,"
ShowInfo = ShowInfo & vbTab & " typekind " & ti.TypeKind
Next
For Each ti In tlin.TypeInfos
Select Case ti.TypeKind
Case 0
ShowInfo = ShowInfo & vbCrLf & ti.TypeKindString & " " & ti.Name
ShowInfo = ShowInfo & vbTab & " has " & ti.Members.Count & " members:"
Dim tm As MemberInfo
For Each tm In ti.Members
ShowInfo = ShowInfo & vbCrLf & " " & tm.Name & " = " & CStr(tm.Value)
Next
Case 4
ShowInfo = ShowInfo & vbCrLf & ti.TypeKindString & " " & ti.Name
ShowInfo = ShowInfo & vbTab & " has guid " & ti.Guid
Dim tc As TLI.MemberInfo
For Each tc In ti.Members
ShowInfo = ShowInfo & vbCrLf & " " & tc.Name & " par " & CStr(tc.ReturnType)
Next
End Select
Next
ShowInfo = ShowInfo & vbCrLf & "Unions:"
Dim tu As TLI.UnionInfo
For Each tu In tlin.Unions
ShowInfo = ShowInfo & vbCrLf & tu.Name & " " & tu.TypeKindString
Next
ShowInfo = ShowInfo & vbCrLf & "Records:"
Dim tr As TLI.RecordInfo
For Each tr In tlin.Records
ShowInfo = ShowInfo & vbCrLf & tr.Name & " " & tr.TypeKindString
Next
Exit Function
EH:
If Err <> -2147220984 Then
ShowInfo = ShowInfo & vbCrLf & " >>>>>> Error: " & Err.Description
End If
Resume Next
End Function
no way. not enough RTTI from IUnknown. you could query for a more usefull interface tough
</wqw>
p.s. sort of <ping> :-))
</wqw>
p.s. sort of <ping> :-))
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ameba - I've actually already figured out how to do what your code demonstrates. My problem is how to do it INSIDE a running application, where the ONLY information to act upon is the instance of the object instantiation itself.
Reading a type library is one thing. BUT, having a routine which will accept an object as a parameter and then act on that object ... is what I'm after.
So Imagine a VB routine like this:
-----------------------
Public Function GetPropsAndValues(obj as Object) as String
Dim Ret as string
For Each Property in obj
select case obj.DataType
case String
Ret = Ret & obj.Property.Name & vbTab & obj.Property.Value & vbCrLb
case integer
Ret = Ret & obj.Property.Name & vbTab & cstr(obj.Property.Value) & vbCrLb
case boolean
Ret = Ret & obj.Property.Name & vbTab & iif(obj.Property.Value, "True","False")
End Select
Next
GetPropsAndValues = Ret
End Function
-----------------------
Obviously this is a very simplistic example, because there are many complex data types which could theoretically be returned including other objects, data connections, recordsets, images, etc. But hopefully, the example shows what I'm looking for.
And may shed some light on why I'm now offering 1500 points.
Reading a type library is one thing. BUT, having a routine which will accept an object as a parameter and then act on that object ... is what I'm after.
So Imagine a VB routine like this:
-----------------------
Public Function GetPropsAndValues(obj as Object) as String
Dim Ret as string
For Each Property in obj
select case obj.DataType
case String
Ret = Ret & obj.Property.Name & vbTab & obj.Property.Value & vbCrLb
case integer
Ret = Ret & obj.Property.Name & vbTab & cstr(obj.Property.Value) & vbCrLb
case boolean
Ret = Ret & obj.Property.Name & vbTab & iif(obj.Property.Value, "True","False")
End Select
Next
GetPropsAndValues = Ret
End Function
-----------------------
Obviously this is a very simplistic example, because there are many complex data types which could theoretically be returned including other objects, data connections, recordsets, images, etc. But hopefully, the example shows what I'm looking for.
And may shed some light on why I'm now offering 1500 points.
ASKER
Ameba - Looks like we were both typing at the same time. You second answer may hold the key I'm looking for. Let me try a few things and I'll let you know!
Thanks for pursuing a solution!
Thanks for pursuing a solution!
ASKER
Ameba - Looks like we were both typing at the same time. You second answer may hold the key I'm looking for. Let me try a few things and I'll let you know!
Thanks for pursuing a solution!
Thanks for pursuing a solution!
ASKER
Ameba - The mcrider solution works great! Thanks for the help! Here's the points.
Check methods (F2) of TLI.TLIApplication
I used:
Function TypeLibInfoFromFile(FileNa me As String) As TypeLibInfo
Member of TLI.TLIApplication
Create a TypeLibInfo object from a file
but there are more methods:
Function TypeInfoFromRecordVariant( RecordVari ant) As TypeInfo
Function TypeLibInfoFromRegistry(Ty peLibGuid As String, MajorVersion As Integer, MinorVersion As Integer, LCID As Long) As TypeLibInfo
Function InterfaceInfoFromObject(Ob ject As Object) As InterfaceInfo
Member of TLI.TLIApplication
Create an InterfaceInfo object from a running IDispatch object
Function ClassInfoFromObject(Object As Unknown) As TypeInfo
Member of TLI.TLIApplication
Create a TypeInfo object from any running COM object
-------
Uh, thanks, but this is too much points.
And at least 50% belongs to mcrider.
I'll ask CS to split points:
400 mcrider
400 ameba
700 back to you
I used:
Function TypeLibInfoFromFile(FileNa
Member of TLI.TLIApplication
Create a TypeLibInfo object from a file
but there are more methods:
Function TypeInfoFromRecordVariant(
Function TypeLibInfoFromRegistry(Ty
Function InterfaceInfoFromObject(Ob
Member of TLI.TLIApplication
Create an InterfaceInfo object from a running IDispatch object
Function ClassInfoFromObject(Object
Member of TLI.TLIApplication
Create a TypeInfo object from any running COM object
-------
Uh, thanks, but this is too much points.
And at least 50% belongs to mcrider.
I'll ask CS to split points:
400 mcrider
400 ameba
700 back to you
Hi
You need tlbinf.dll for this. Take a look at
at TIBrowse sample by Serge Baranovsky:
http://www.geocities.com/SiliconValley/Hills/9086/TIBrowse.zip
Unfortunatelly, this link (where I got this sample) seems broken now. I can send code on e-mail or place at any free server.
If you have any question on this code, let me know.
ark@fesma.ru
Cheers
You need tlbinf.dll for this. Take a look at
at TIBrowse sample by Serge Baranovsky:
http://www.geocities.com/SiliconValley/Hills/9086/TIBrowse.zip
Unfortunatelly, this link (where I got this sample) seems broken now. I can send code on e-mail or place at any free server.
If you have any question on this code, let me know.
ark@fesma.ru
Cheers
I asked CS to split/reduce points, but ... this is pretty complicated. :-(
I decided to give credits to Ark for his good link,
Ark, please see:
https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=11501678
and to mcrider
https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=11501698
Thanks
I decided to give credits to Ark for his good link,
Ark, please see:
https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=11501678
and to mcrider
https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=11501698
Thanks
http://www.domaindlx.com/e_morcillo/scripts/type/ole.asp