[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 893
  • Last Modified:

How to implement a Interface in VB6 ?

Hi,

Actually, I am working on the Ole Automation in Nagivator now, however, I don't know how to implement the following interface in VB6 :

'''''''''''''''''''''''''''''''''''''''''
PROTOCOL.ODL

[ uuid(00000000-0000-0000-0000-000000000000), version(1.0) ]
library OleExampleProtocolHandler
{
   //  For the Windows 16-bit version, the following line should be
   //  importlib("stdole.tlb");
       importlib("stdole32.tlb");

       [ uuid(00000000-0000-0000-0000-000000000000) ]
       dispinterface IExampleProtocolHandler1
       {
               properties:

               methods:
                       [id(1)] short Initialize(BSTR pProtocol, BSTR pUrl);
                       [id(2)] void Open(BSTR pUrl);
       };

       [ uuid(00000000-0000-0000-0000-000000000000) ]
       coclass ExampleProtocolHandler1
       {
               [default] dispinterface IExampleProtocolHandler1;
       };
};
''''''''''''''''''''''''''''''''''''''''''
You can find more information at:
http://developer.netscape.com/docs/manuals/communicator/OLE/ole6obj.htm#protocolodl

I have added a reference to the netscape.tlb which found in the Netscape directory, and added a statement "Implements IExampleProtocolHandler1" in a class module. However, I can't see any functions in the dropdowns. Also, when I try to compile, VB point to the statement "Implements IExampleProtocolHandler1" and said :
Compile error: User-defined type not defined

Notes: My application is a ActiveX EXE.

Please tell me why I got that error ?
Also, give me a sample coding to implement the above interface.
Thanx!


Raymond
0
rng
Asked:
rng
  • 5
  • 3
  • 3
  • +3
1 Solution
 
robbertCommented:
Uhm, use non-technical terms, rng...
Do you want to know how to implement an interface in VB or how to reach specific goals?
0
 
AzraSoundCommented:
you will need to take the above idl code and compile a type library and use that in your project - i'm no guru on altering idl code to make it "vb friendly" however
0
 
rngAuthor Commented:
AzraSound:

Do u know what the "uuid(00000000-0000-0000-0000-000000000000)" should be in the PROTOCOL.ODL file ??
They can't all be the same in the PROTOCOL.ODL file, the uuid should relate to what ??


Raymond
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
morgan_peatCommented:
You say that you have added a reference to the type library.  Make sure of this by going to the Object Browser.  Make sure that the library is listed in the top left drop-down, and that the objects, methods & properties are visible.

You said that you put 'implements' at the top of your module.  Good.  Make sure that you get intellisense, and that your object is listed there.

After you have typed implements, you should find that the obejct is listed in the top dropdown (like you currently get Class_Initialize and Class_Terminate).

Just use the dropdowns to add all methods (you must implement ALL methods of an interface), and try to compile it then.
0
 
AzraSoundCommented:
not all type libs are "vb friendly", which i am guessing the Netscape tlb is not, and he is thus receiving the error using the Implements keyword (but do check the points made above just to be sure)


>>They can't all be the same in the PROTOCOL.ODL file

well a uuid (universal unique identifier), essentially the same as a guid (global unique identifier) should be the same on anyones machine granted that the component is the same version.  thus, the idea of being "universally unique".  is it really all 0's or did you just do that for example sake?  if you have the OLE viewer that comes with VS, you should be able to run it, find the Netscape tlb, and determine its uuid.  otherwise, i can post some code that you can run to get that value.
0
 
WalterMCommented:
A few remarks:

1. the three occurances of

   uuid(00000000-0000-0000-0000-000000000000)

in the PROTOCOL.ODL source file need to be replaced with three valid and different GUIDs, which you can generate
using the GUIDGEN.EXE tool that comes with Visual Studio.

--- Example PROTOCOL.ODL ---

[ uuid(E554D580-59C1-11d5-9DE1-0050043ED30F), version(1.0) ]
library OleExampleProtocolHandler
{
    //  For the Windows 16-bit version, the following line should be
    //  importlib("stdole.tlb");
        importlib("stdole32.tlb");

        [ uuid(E554D582-59C1-11d5-9DE1-0050043ED30F) ]
        dispinterface IExampleProtocolHandler1
        {
                properties:

                methods:
                        [id(1)] short Initialize(BSTR pProtocol, BSTR pUrl);
                        [id(2)] void Open(BSTR pUrl);
        };

        [ uuid(E554D584-59C1-11d5-9DE1-0050043ED30F) ]
        coclass ExampleProtocolHandler1
        {
                [default] dispinterface IExampleProtocolHandler1;
        };
};

--- End example PROTOCOL.ODL ---

After that, you must compile the ODL source code to a type library using either MIDL (comes with Visual Studio) or MkTypLib (comes with VB), which will generate a PROTOCOL.TLB file. Then this file must be referenced from the VB project, using Project/References/Browse... to point VB to it's location.

2. To implement the interface in a VB class, use:

   Implements ExampleProtocolHandler1

instead of

   Implements IExampleProtocolHandler1

(note the dropped 'I' prefix).

After typing in the above statement, the interface name "ExampleProtocolHandler1" will be appended to the left dropdown combo box above your code window. When you select it, the procedure dropdown combobox on the right will be loaded with the interface members, i.e. "Initialize" and "Open". By selecting these, VB will now insert the method signatures to your code window.

3. The interface as listed above is compatible with VB, so you don't need to change anything else than the GUIDs.

Michel
0
 
morgan_peatCommented:
Aaaaahhhhhh. Confusion all round.
I just had a look at the netscape hyperlink, and now know what you are on about.

In order to register an object for netscape automation, you don't have to implement any specific interface.  You just need to have your own interface with the same methods & parameters as listed in the <I>example</I> interface.

So, you could have a class called 'MyAutomationItf' and you would need the following methods:

Public Function Initialize(pProtocol As String, pUrl As String) As Integer
Public Sub Open(pUrl As String)

Then you use the netscape COleRegistry class to register your protocol handler (with its PROGID), and bob's your uncle.
0
 
rngAuthor Commented:
WalterM:

I already followed your comment to work on it, but netscape still said: "Unable to use OLE automated protocol Handler project1.class1"
Netscape does called my app, however, it seems cannot see my implementation of the interface.
Here is my implementation:

''''''''''''''''''''''''''''''''''''''''''
'''Class1.cls
Implements ExampleProtocolHandler1

Private Function ExampleProtocolHandler1_Initialize(ByVal pProtocol As String, ByVal pUrl As String) As Integer
    MsgBox pProtocol & pUrl
    ExampleProtocolHandler1_Initialize = 1
End Function

Private Sub ExampleProtocolHandler1_Open(ByVal pUrl As String)
    MsgBox pUrl
End Sub
''''''''''''''''''''''''''''''''''''''''''

Also, my project type is ActiveX EXE, does it affect ??


Raymond
0
 
WalterMCommented:
The actual implementation should never affect the object binding. As long as you adhere to the interface, which VB will enforce, the caller should be satisfied.

Have you registered your class within Netscape? Here's an excerpt from the Netscape site:

"External protocol handlers are applications external to Navigator that implement a special automation object that is identified to Navigator through Netscape.Registry.1's member RegisterProtocol. After an automation object has been registered with Navigator, Navigator can tell the external protocol handler to open a URL with a particular protocol or access type, such as HTTP, Gopher, FTP, news, mailto, and others."

The RegisterProtocol function is described here:

http://developer.netscape.com/docs/manuals/communicator/OLE/ole3reg.htm

In the case of your example above, the pRegistryName parameter would be "Project1.Class1"

Michel
0
 
rngAuthor Commented:
WalterM:

I already registered my app as a protocol handler successfully, and Netscape does called my app.
However, after it called my app, it always say "Unable to use OLE automated protocol Handler project1.class1"

I dunno why..

Also, my project type is ActiveX EXE, does it affect ??


Raymond
0
 
WalterMCommented:
Sorry Raymond, I'm out of options ;-(

Unfortunately, the Netscape error message is not very descriptive.

The problem indeed might be that the class needs to be in an apartment-threaded DLL, but I wouldn't know for sure - I haven't been able to find anything about this in the Netscape docs.

Have you tried the DLL approach already?

Michel
0
 
morgan_peatCommented:
I did find a C++ sample (using MFC) listed in the Netscape Client API FAQ:
http://developer.netscape.com/support/faqs/ncapi/ncapi.html

It's called nstest.zip.

Had a look at the code, and everything that Raymond did is right.  Registering a DLL with Netscape.Registry.1 returns True, but then netscape can't run it.

The docco says that you need an automation server.  I thought that ActiveX EXE's WERE automation servers, but now I'm not so sure.

'Fraid you either need to program in MFC, or get a MFC guru to translate the code into VB......
0
 
rngAuthor Commented:
I already try the DLL approach, but it is the same error...
What can I do..??

Raymond
0
 
rngAuthor Commented:
No one can solve my question here.

Raymond
0
 
ComTechCommented:
Time to close this abandoned question.

ComTech
CS @ EE
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 5
  • 3
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now