Solved

How to implement a Interface in VB6 ?

Posted on 2001-06-04
15
867 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
  • +3
15 Comments
 
LVL 15

Expert Comment

by:robbert
ID: 6153885
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
ID: 6154172
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
ID: 6155179
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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 1

Expert Comment

by:morgan_peat
ID: 6155527
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
ID: 6155869
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
ID: 6156081
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
ID: 6156253
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
 

Author Comment

by:rng
ID: 6157373
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
ID: 6159178
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
ID: 6159221
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
ID: 6159736
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
ID: 6159891
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
ID: 6160005
I already try the DLL approach, but it is the same error...
What can I do..??

Raymond
0
 

Author Comment

by:rng
ID: 6203725
No one can solve my question here.

Raymond
0
 

Accepted Solution

by:
ComTech earned 0 total points
ID: 7024504
Time to close this abandoned question.

ComTech
CS @ EE
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

688 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