Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Withevents not working with Type Library

Status
Not open for further replies.

datavalue

Programmer
Nov 8, 2002
12
CA
I am working on a VB project where a Server .tlb file written in C++ by somebody else will enable me to determine when something happens on the server. The problem is that the typelib file that I try to use wont allow me to use the keyword withevents. I tried the following :
Private Withevents mDataServer as DataServerLib.DataServer

I get the error message 'Compile Error: Object Library Feature Not Supported'.

I am trying to access an event called Notify on the server dll.

How can I do this?

I think the answer involves creating a Lib file and implementing the ISetCallBackEvent function but my knowledge of VB and Google goes a bit hazy at this point.

So far I have:

DataServer.tlb (the thing I'm trying to access)

DataServerLib (a VBP ActiveX DLL I've built) with the following class in:
DataServerInterface (an interface I've typed in of all the dummy properties, methods and events provided in the tlb)
ICallbackEvents (2 subs in it)

(Which lead me onto another issue :
In the ObjectBrowser for the typelib file there is a read only property 'Data' with the following definition :
Property Data(nRow As Long, nColumn As Long) As String
How do I declare the property for this in VB?

I tried the following:

Public Property Get Data() As String
End Property
Public Property Let Data(ByVal nRow As Long, ByVal nColumn As Long)
End Property

But it wont compile.

Am I on the right track with all this or am I barking up the wrong tree.

Is it possible to get an event notification without using the WithEvents keyword?
 
To answer your last question first, not that I know of in VB. If you want to create a VB DLL that supports events, there are 4 steps:

1. In your dll, declare the event using the Event keyword.
2. In your dll, raise the event somewhere, using raiseevent.
3. In your client, use the withevents keyword
4. In your client, write an event handler.

I don't know C++ well, but I know that you can write dll's and ocx's that don't support this construct. Obviously, since a lot of VB controls don't require the withevents keyword to support events.

HTH

Bob
 
Thanks for sharing your knowledge Bob.

It is possible to get event notifications using callbacks. I believe the server dll has to provide a function to receive the method to be called back. I've worked around the problem as I wasn't allowed to change the server dll. And I didn't have the budget.

 
Yes it is, with VB5 and above. You might want to read up on the AddressOf operator. Also, there's a great example in MSDN involving a Coffee Pot application that should give you some helpful information.

Basically, you have a method on the server that calls a proc on the client. The method takes as an argument the address of the proc that the client wants it to call. The client calls the server method, passing the address of the desired callback proc using the AddressOf operator. The server calls same when appropriate. A little fancy wrinkle is to define an interface in the server and implement it in the client.

HTH

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top