Jump to content

COM with VBA - help needed


Recommended Posts

Hi,

 

Yesterday I made my first trials to access the DVBViewer COM interface from VBA (I'm using MS Access, because I'm used to it).

 

I used already some ActiveX controls in other VBA applications but in this cases there was always a VBA template which I could use.

 

Because the DVBViewer COM interface is documented from the view of a Delphi program with Units, I have problems to translate this to VBA.

 

In the object catalog of the VBA editor I see all the classes that are documented in the DVBViewer COM descripton, but I can only access the following classes:

 

DVBViewer

DVBViewerEvents

MessageEvents

Teletextmanager

 

Wenn I try to make an instance of any other class, I get a "methode or data object not found".

 

I generate the instance with a statement like:

 

Set oDVB = New DVBViewerServer.DVBViewer

 

Some lines of sample code would be very helpfull.

 

Sorry for this very basic ActiveX and VBA questions <_<

 

Thx, dgdg

Edited by dgdg
Link to comment
Guest Lars_MQ

You only do a getobject for the IDVBViewer Interface. This ist your starting point.

Dim myDVBViewer As DVBViewer
Set myDVBViewer = GetObject(, "DVBViewerServer.DVBViewer")

 

Everything now is done over the myDVBViewer object. Compare it with the Word or Excel COM-Objects. You get the application opject and everything you need is derived from it.

 

You want the OSD?

dim OSD AS IDVBOSD
Set OSD = myDVBViewer.OSD
OSD.dosomething

or call directly

myDVBViewer.OSD.doesomething

The first approach should be preferred for multiple calls to the OSD, the second one is ok, if you only call one function/property of the OSD, but with several of this kind of call performance degrades extremly.

 

This works with nearly all interfaces. Something special are the Eventhelper.

A Short example in WordVBA:

 

MainCode:

Dim DVBViewer As IDVBViewer
Dim MyEvents As New Klasse1

Private Sub Document_Open()
  HookItUp
End Sub

Private Sub HookItUp()
  Set DVBViewer = GetObject(, "DVBViewerServer.DVBViewer")
  Set MyEvents.FVideotext = DVBViewer.Videotext
  Set MyEvents.FDVBEvents = DVBViewer.Events
End Sub

Klasse1:

Public WithEvents FVideotext As DVBViewerServer.Teletextmanager
Public WithEvents FDVBEvents As DVBViewerServer.DVBViewerEvents

Private Sub FDVBEvents_OnChannelChange(ByVal ChannelNr As Long)
 If Not FDVBEvents Is Nothing Then
Selection.InsertAfter ChannelNr
 End If
End Sub

Private Sub FVideotext_onDataArrive(ByVal PageNr As Long, ByVal SubPageNr As Long)
 If Not FVideotext Is Nothing Then
Selection.InsertAfter FVideotext.GetPage(PageNr, SubPageNr)
 End If
End Sub

Don't get scared cause the docs look delphi. Everything is explained, the types can be mapped directly into VB types (even this does VB for you, if you use the Objectcatalogue and code completion).

Link to comment

Ok, Thanks a lot !

That was the missing introduction. Till now I used "New" for the ActiveX but with GetObject it's easier.

 

I tested some methodes and it works fine.

 

But one special question. What is wrong with this code ?

 

  Dim myDVBViewer As IDVBViewer
 Dim OSD As IDVBOSD

 Set myDVBViewer = GetObject(, "DVBViewerServer.DVBViewer")
 Set OSD = myDVBViewer.OSD

 OSD.ShowInfoinTVPic("Hello DVBViewer", 3000)

 

I get an error in the last line ("=" is missing) ? The MS Access object catalog and the code completion are telling me, that ShowInfoinTVPic is a procedure (Sub). Something wrong with the parameters ?

 

 

EDIT: I found the solution right now. I have to use CALL.

 

 

Thx, dgdg

Edited by dgdg
Link to comment
Guest Lars_MQ

OSD.ShowInfoinTVPic("Hello DVBViewer", 3000)

That's the way to call a function in VB. to call a sub (or procedure called in the docu) you must use:

OSD.ShowInfoinTVPic "Hello DVBViewer", 3000

or put a call in front of it.

Link to comment

I did some C coding in meantime. I have to switch back to the VBA notation now. <_<

 

I think when I fully understand the DVBViewer COM interface I will switch to the Borland C++ Builder.

VBA ist only for testing.

 

Thx, dgdg

Edited by dgdg
Link to comment

Hi,

@dgdg:

can you post your vba test project?

I have some fundamental problems with the COM Interface and VB6 <_<.

 

mfg Steffen

Link to comment
  • 2 weeks later...

Ok - next step :bye:

 

I switched to Borland C++ Builder 4 because from VBS I can not use the Windows API (and I do not want to start MS Access each time to execute mit VBA scripts :bounce:)

 

I managed to include the DVBViewer type library in my C++ project and now I see all the types like IDVBOSDDispT etc. in die class tree.

 

But now I have the same problem as in VBA and VBS. I do not know how to access the COM object.

What's the C++ Builder equivalent for this VBS code:

 

Set myDVBViewer = GetObject(, "DVBViewerServer.DVBViewer")
Set OSD = myDVBViewer.OSD
call OSD.ShowInfoinTVPic("Hello DVBViewer", 3000)

 

Who can give ma a short example ?

 

Thx, dgdg

Edited by dgdg
Link to comment

mhm

@ dgdg i tried get your code sample working with vb6 and get the following error: "User-defined type not defined" on "Dim myDVBViewer As IDVBViewer"

whats wrong?

 

mfg Steffen

Link to comment
@ dgdg i tried get your code sample working with vb6 and get the following error: "User-defined type not defined" on "Dim myDVBViewer As IDVBViewer"

 

I kenne VB6 nicht, aber in MS Access muss man die DVBViewer COM Bibliothek vorher unter Extras -> Verweise aktivieren.

 

Dann sind die Typen bekannt.

 

Gruß, dgdg

Link to comment

@dgdg: Danke das wars :bye:

Nur gibt es diese Option unter VB6 unter Projekt -> Verweise.

 

Danach hat noch en bissle gehabert :bounce: Ich frag mich die ganze Zeit was der zweite Error nur bedeuten soll, bis... vl sollte ich mal den DVBViewer starten :bye: Jetzt gehts. juhu!!

 

mfg Steffen

Link to comment
Danach hat noch en bissle gehabert :bye: Ich frag mich die ganze Zeit was der zweite Error nur bedeuten soll, bis... vl sollte ich mal den DVBViewer starten :) Jetzt gehts. juhu!!

 

Mit CreateObject statt GetObject wird der DVBViewer automatisch gestartet.

 

Gruß, dgdg

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...