• Welcome to Theos PowerBasic Museum 2017.

OLE containers in PB 10.x

Started by Stan Helton, March 05, 2015, 04:48:49 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Stan Helton

I'm working on a VB6 to PB10 Translator. Of course the treatment of VB objects is the biggest hurdle I have to overcome. At the moment I have two questions that I think have already been solved.

1) It is accepted that an OLE container is required to use many of the OCX controls and there are a lot of references to José's OLECON.inc. I have been unable to locate this file. Is it still available, and if so, where can I find it?

2) I have spent completely unreasonable amounts of time pouring over the PB 9 and PB 10 documentation. It leaves the impression that IDISPATCH with Late Binding should handle everything required to use the OLE objects. What have I missed?

Thank you for any discussion and apologies if I'm asking stupid questions, but these are the questions bugging me right now.
StanHelton

José Roca

#1
Quote
1) It is accepted that an OLE container is required to use many of the OCX controls and there are a lot of references to José's OLECON.inc. I have been unable to locate this file. Is it still available, and if so, where can I find it?

OLECON.inc is part of my Windows API headers package and requires the use of my headers because the PB ones don't have any support for COM programming. If you don't want to use my headers, then you may need to use another OLE container, such Microsoft's ATL.DLL.

You can find my headers here: http://www.jose.it-berater.org/smfforum/index.php?topic=4985.0

Be aware that not all VB6 controls will work with my container or ATL.DLL.

Quote
2) I have spent completely unreasonable amounts of time pouring over the PB 9 and PB 10 documentation. It leaves the impression that IDISPATCH with Late Binding should handle everything required to use the OLE objects. What have I missed?

Should work with translated VB6 code, since VB6 can't use low-level interfaces that inherit directly from IUnknown.


Stan Helton


Frederick J. Harris

Quote
Should work with translated VB6 code, since VB6 can't use low-level interfaces that inherit directly from IUnknown.

I'd have to review that issue Jose, but my understanding is that vb6 can make direct calls through a custom interface, or of course through IDispatch too.  I'm pretty sure I've done it.

Frederick J. Harris

Yes, VB4-6 works with simple IUnknown based interfaces.  Check out post #11 at this recent thread in the PowerBASIC Forums and there I have posted a PowerBASIC COM example that demonstrates using events and getting them to work in VB6...

http://www.powerbasic.com/support/pbforums/showthread.php?t=58902

When the 'new' keyword is used to instantiate an object in VB6 you'll get direct VTable access through IUnknown.  Same as with PowerBASIC actually.  Here is that VB6 code...


Option Explicit
Private WithEvents pMyMath As CMyMath
Attribute pMyMath.VB_VarHelpID = -1
Private Sub Form_Load()
  Set pMyMath = New CMyMath
End Sub
Private Sub Form_Click()
  Call pMyMath.DoMath
End Sub
Private Sub pMyMath_ReportProgress(ByVal iProgress As Long)
  Me.Print CStr(iProgress) & "% Done With Calculation!"
End Sub
Private Sub Form_Unload(Cancel As Integer)
  Set pMyMath = Nothing
End Sub


Alternately, if an object supports IDispatch, or is a dual interface, then the CreateObject() VB function accesses it through 'late binding'; from VB help on CreateObject()...


' Declare an object variable to hold the object
' reference. Dim as Object causes late binding.
Dim ExcelSheet As Object
Set ExcelSheet = CreateObject("Excel.Sheet")






José Roca

#5
VB6 doesn't support pure IUnknown interfaces. It calls them using the calling convention that in the PB compilers is called IAutomation, that also inherits from IUnknown, but does not return an HRESULT as the result of the method (using this interface, in PB the HRESULT is returned by OBJRESULT). Therefore, many methods will work, but others don't. What if you need to pass the last parameter by reference? You can't with VB6 because it will assume that this parameter is the return value of the method.