-
Jun 28th, 2022, 04:09 PM
#1
Thread Starter
Addicted Member
Iterating through UDT members ?
Code:
Type MyType2
a() As Long
b As Variant
End Type
Type MyType1
L As Long
S As String
O As Object
T As MyType2
End Type
Is there a way to iterate though each member of MyType1 UDT and retrieve the UDT members names, their corresponding variable types and their respective assigned values for a given instancated variable ?
Can this be done via the TLBNINF32 DLL or some other way ? is there a code example ?
Thanks.
-
Jun 28th, 2022, 05:09 PM
#2
Re: Iterating through UDT members ?
I don't believe any of those names are preserved once your program is compiled. AFAIK, they all just become memory addresses.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Jun 28th, 2022, 07:52 PM
#3
Re: Iterating through UDT members ?
if it was declared as public in an activex dll then it would be published in the type library.
you could use tlbinf to get the udt name, field names and types.
Code:
Dim mi As MemberInfo, ri As RecordInfo
For Each ri In tli.Records
Debug.Print ri.Name
For Each mi In ri.Members
Debug.Print " " & mi.Name & " " & mi.ReturnType.VarType
‘more: https://github.com/dzzie/MAP/blob/61e600f83f857301d317f22d0caf55dd2737bcdb/tlbViewer/CTlbParse.cls#L120
Next
Next
not sure if it offers a way to interpret a random udt as variant of type x and walk field values.
you could write a manual memory dumper though based on the data you do have. would get annoying for nested types
if you knew the types ahead of time you would probably be happier just having hardcoded routines/classes for each with a .dump method
you could write a generator for them based on udt definition to automate it.
maybe something like kaitai struct: http://kaitai.io/
as elroy said if its in a standard exe, the info is not preserved, you would need custom dump routines by type compiled in
Last edited by dz32; Jun 28th, 2022 at 10:10 PM.
-
Jun 29th, 2022, 03:41 AM
#4
Thread Starter
Addicted Member
Re: Iterating through UDT members ?
-
Jun 29th, 2022, 04:11 AM
#5
Re: Iterating through UDT members ?
so I guess you can get the udt values by name with tli if in ActiveXdll
https://stackoverflow.com/questions/...udt-member-vb6
Code:
Public Function UDTMemberGetValue(ByRef pvUDTValue As Variant, ByVal psMemberName As String)
Dim oApp As TLI.TLIApplication
Dim vTemp As Variant
Set oApp = New TLI.TLIApplication
vTemp = CVar(pvUDTValue)
UDTMemberGetValue = oApp.RecordField(vTemp, psMemberName)
End Function
Public Sub UDTMemberSetValue(ByRef pvUDTValue As Variant, _
ByVal psMemberName As String, _
ByRef pvMemberValue As Variant)
Dim oApp As TLI.TLIApplication
Dim vTemp As Variant
Set oApp = New TLI.TLIApplication
vTemp = CVar(pvUDTValue)
oApp.RecordField(vTemp, psMemberName) = pvMemberValue
pvUDTValue = vTemp
End Sub
-
Jun 29th, 2022, 09:25 AM
#6
Re: Iterating through UDT members ?
Originally Posted by dz32
so I guess you can get the udt values by name with tli if in ActiveXdll
Well, if you think about it, they've got to be in there, because Intellisense can get them while we're developing against an AX.dll resource. There almost certainly represented in there with some kind of embedded TypeLib, but it might take some of The Trick's work to figure out how to get them out from code. There are TypeLib extractors out there. I suppose we could extract the TypeLib and then examine that.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Jun 29th, 2022, 10:08 AM
#7
Thread Starter
Addicted Member
Re: Iterating through UDT members ?
CreateObject("TLI.TLIApplication") raises error ActiveX component can't create object.
Can't register tlbinf32.dl in x64 bit.
-
Jun 29th, 2022, 10:38 AM
#8
Re: Iterating through UDT members ?
Correct it’s a 32bit dll only
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|