You are not logged in.

OlimilO

Intermediate

  • "OlimilO" is male
  • "OlimilO" started this thread

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

1

Wednesday, August 5th 2009, 1:00pm

Extracting Enums out of COM, OCX, ActiveX-dll, Typelibrary

Hi,

The following tiny program can extract Enum-constants out of any COM-typelibrary.
It does not use Jabaco it uses VB.net. But it can be useful for creating sourcecodes towards Jabaco.
I am sure there are other and more complex programs that can maybe do the same or a similar thing, e.g. search at vbaccelerator.com

All what you need is a Button and a TextBox on a Form.
I is not very convenient in fact it is rather primitive.

What you have to do:
* in VS you have to link the COM-library with the menu item "Poject"->"Add Reference".
* then you have to select the enum in your sourcecode:

Jabaco Source

1
2
3
4
5
6
7
8
'no it's VB.net 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
   Dim MyEnum As MSComDlg.PrinterOrientationConstants '<- first select your Enum !!  
   
   Call EnumToTextBox(MyEnum, "", TextBox1, False) 
   TextBox1.SelectAll() 
   TextBox1.Copy() 
End Sub


Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Private Sub EnumToTextBox(ByVal aEnum As [Enum], _
                          ByVal EnumName As String, _
                          ByVal aTB As TextBox, _
                          Optional ByVal bInclName As Boolean = True, _
                          Optional ByVal bHex As Boolean = False, _
                          Optional ByVal iIndent As Integer = 3)
   
   Dim aSB As New System.Text.StringBuilder
   Dim tSB As New System.Text.StringBuilder
   Dim StrArrNames() As String
   Dim StrArrValues() As Integer
   Dim i As Integer
   
   If EnumName Is Nothing Or EnumName.Length = 0 Then
       EnumName = aEnum.GetType.Name
   End If
   
   aSB.Append("Public Enum ").Append(EnumName).Append(vbCrLf)
   StrArrNames = [Enum].GetNames(aEnum.GetType)
   StrArrValues = [Enum].GetValues(aEnum.GetType)
   
   For i = 0 To StrArrNames.Length - 1
      tSB = New System.Text.StringBuilder
      If bHex Then
         tSB.Append("&H").Append(Hex(CLng(StrArrValues(i))))
      Else
         tSB.Append(StrArrValues(i))
      End If
      If iIndent > 0 Then
         aSB.Append(Space(iIndent))
      End If
      If bInclName Then aSB.Append(EnumName).Append("_")
      aSB.Append(StrArrNames(i)).Append(" = ").Append(tSB.ToString).Append(vbCrLf)
   Next
   aSB.Append("End Enum").Append(vbCrLf)
   aTB.Text = aSB.ToString
End Sub


OlimilO

Rate this thread
WoltLab Burning Board