Help with ActiveX

I’m trying to learn about using ActiveX components in XOJO. I’m not a skilled programmer so I don’t know what I am doing or talking about, but I figure I would play with it and see what happens.

I have read that XOJO is not fully COM compliant, but that means nothing to me in terms of what can or cannot be done using ActiveX in XOJO. So I have looked at a VB example using ActiveX references from a program called SolidWorks Enterprise PDM. It is a document management system.

When inserting the ActiveX component into XOJO, I select the References tab and select PDMWorks Enterprise 2011 Type Library. At this point, a module called EDMLib shows in the right pane with classes, Enumerations, and Structures.

The first problem that I run into is that there are 2 structures that declare variables as a “Date” data type.

So my initial questions are:

  1. Is this a sign that I am running into XOJO not being fully COM compliant and it is pointless to continue, or is this just a bump that I can learn to overcome or perhaps it is a mountain that requires great effort?
  2. If this is a bump that can be overcome, how do you overcome this? I read that in VB the Date data type is 8 bytes, would something like this work:

change the declaration moDate As Date to
moDate As Int64

This change does allow me to get a program to compile and sort of work, but it has other problems. I may ask about those problems later depending on the answers to these 2 questions.

Just to be more complete, here are the contents of the two structures using the “Date” data type:

EdmBomVersion

meType As EdmLib.EdmBomVersionType
mlVersion As Integer
moDate As Date
mbsTag As CString
mbsComment As CString

EdmHistoryItem

meType As EdmLib.EdmHistoryType
moDate As Date
mlVersion As Integer
mlUserID As Integer
mlFileID As Integer
mlFolderID As Integer
mbsItemName As CString
mbsUserName As CString
mbsComment As CString
moData As EdmLib.EdmCmdData

Thanks for your help

Actually OLE/COM dates are doubles. The integer part represents the number of days since Dec 31, 1899 while the fractional part represents the time. You can use our built-in COM.DATEToRBDate and COM.RBDateToDATE to convert between the two. In case it’s not obvious RBDate represents a Xojo Date, so COM.DATEToRBDate converts an OLE/COM Date type to a Xojo Date object.

Thanks for the reply William. Much appreciated.

So as I said previously, the short VB example will almost work, but it has errors and I don’t know how to debug these errors.

When I debug, the code goes into this code:

If mThis = Nil Then Raise New NilObjectException
Dim pVal_Param As Int16
Dim func As New IsNull_Get_Func1( mThis.Ptr( 0 ).Ptr( 28 ) ) // <-What does this mean?
Dim resultCode As Integer = func.Invoke( mThis, pVal_Param ) // <-this returns 1. Why?
If true then '0 = resultCode Then // I force true here to see what happens. Result->Program executes as expected.
Return COM.VARIANTBOOLToRBBoolean(pVal_Param)
Else
Raise New COM.COMException(“Failed on IsNull”, resultCode )
End If

  1. func.Invoke(mThis,pVal_Param) returns 1 but I don’t know why. How do I debug this?

  2. What does mThis.Ptr( 0 ).Ptr( 28 ) mean?

Here is the full code. It has the VB code commented out and has all error handling commented out. I’m just trying to get something to work.

'Imports EdmLib

'Public Class Form1

'Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'On Error GoTo ErrHandler

'Dim vault As EdmVault5
'vault = New EdmVault5
'vault.LoginAuto(“MyVaultName”, Me.Handle.ToInt32)

Dim vault As EdmLib.EdmVault5
vault = New EdmLib.EdmVault5
vault.LoginAuto(“EPDM_Vault”, self.Handle)

'Dim message As String
'Dim file As IEdmFile5
'Dim folder As IEdmFolder5
'folder = vault.RootFolder

'Get the vault’s root folder interface.

Dim message As String
Dim file As EdmLib.IEdmFile5
Dim folder As EdmLib.IEdmFolder5
folder = vault.RootFolder

'Get position of first file in the root folder.
'Dim pos As IEdmPos5
'pos = folder.GetFirstFilePosition
'If pos.IsNull Then
'message = “The root folder of your vault does not contain any files”
'Else
'message = “The root folder of your vault contains these files:” + vbLf
'End If

Dim pos As EdmLib.IEdmPos5
pos = folder.GetFirstFilePosition

If pos.IsNull Then
message = “The root folder of your vault does not contain any files”
Else
message = “The root folder of your vault contains these files:” + EndOfLine
While Not pos.IsNull
file = folder.GetNextFile(pos)
message = message + file.Name + EndOfLine
Wend
End If

'for all files in the root folder, append the name to the message.
'While Not pos.IsNull
'file = folder.GetNextFile(pos)
'message = message + file.Name + chr(10)
'Wend

'Show the names of all files in the root folder
MsgBox message

'We will get here if anything went wrong above.
'ErrHandler:
'Exception err
'If err IsA NilObjectException Then
''If vault Is Nothing Then
'MsgBox(“Could not create vault interface.”)
'Else
'Dim ErrName As String
'Dim ErrDesc As String
''vault.GetErrorString(Err.Number, ErrName, ErrDesc)
'MsgBox(“Something went wrong.” + EndOfLine + ErrName + EndOfLine + ErrDesc)
'End If

[quote=73008:@Duane Randall]Imports EdmLib

'Public Class Form1

'Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'On Error GoTo ErrHandler

'Dim vault As EdmVault5
'vault = New EdmVault5
'vault.LoginAuto(“MyVaultName”, Me.Handle.ToInt32)

Dim vault As EdmLib.EdmVault5
vault = New EdmLib.EdmVault5
vault.LoginAuto(“EPDM_Vault”, self.Handle)[/quote]
Well, assuming this component supports dual interfaces (which I suspect it does since it works in VB), then you could just use the OLEObject like so:

Dim vault As New OLEObject(“EdmLib.EdmVault5”)
vault.LoginAuto(“MyVaultName”, Me.Handle)