Solved

How to implement a Interface in VB6 ?

Posted on 2001-06-04
15
839 Views
Last Modified: 2011-08-18
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
Comment
Question by:rng
  • 5
  • 3
  • 3
  • +3
15 Comments
 
LVL 15

Expert Comment

by:robbert
Comment Utility
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
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
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
 

Author Comment

by:rng
Comment Utility
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
 
LVL 1

Expert Comment

by:morgan_peat
Comment Utility
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
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
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
 
LVL 2

Expert Comment

by:WalterM
Comment Utility
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
 
LVL 1

Expert Comment

by:morgan_peat
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:rng
Comment Utility
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
 
LVL 2

Expert Comment

by:WalterM
Comment Utility
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
 

Author Comment

by:rng
Comment Utility
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
 
LVL 2

Expert Comment

by:WalterM
Comment Utility
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
 
LVL 1

Expert Comment

by:morgan_peat
Comment Utility
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
 

Author Comment

by:rng
Comment Utility
I already try the DLL approach, but it is the same error...
What can I do..??

Raymond
0
 

Author Comment

by:rng
Comment Utility
No one can solve my question here.

Raymond
0
 

Accepted Solution

by:
ComTech earned 0 total points
Comment Utility
Time to close this abandoned question.

ComTech
CS @ EE
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now