LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

ActiveX client/server event interface ?

I have created an ActiveX server and client in LabWindows CVI 7.0 using the wizards. The server has two interfaces (one is dual the other is an event interface). The dual interface allows the client to talk to the server to perform an action this works fine. The other interface is an event interface which when a Toggle button is clicked on the UI panel of the server it calls the normal CVI call back which is also supposed to fire an event to my client to indicate the button was pressed and has a value change. The Dual interface works fine I am able to talk to the server. The difficulty I am having is with the event interface. The client is able to get a handle to the server and register for the event that is expected. See code below:
""
CAObjHandle MyActiveServer;

// Get the handle to the server
status = RayTryitServer_ActiveIRayExec (NULL, 1, LOCALE_NEUTRAL, 0,
&MyActiveServer);

status = RayTryitServer_IRayExecEventRegOnDebugFlag
(
MyActiveServer,
ExecServerCallback,
NULL,
1,
NULL
);
""
This all seems to run ok status = 0 indicating no errors.

However when the server tries to find out which
clients are registered to receive the events using the code fragment below:

""
CAServerObjHandle MyServer1;
CAObjHandle MyServer;
int Did_AddRef;
IID Interface_Ptr;
const IID *IID_Ptr;
void *This_Ptr;
..
..
..
status = CA_GetActiveObjectByProgIdEx ("RayTryitServer.RayServerObj", NULL, &IID_IRayExec, 1, LOCALE_NEUTRAL, 0, &MyServer);
status = CA_DisplayErrorInfo (MyServer, NULL, status, NULL);

IID_Ptr = &IID_IRayExec;
status = CA_GetInterfaceFromObjHandle (MyServer, IID_Ptr,
0, &Interface_Ptr, &Did_AddRef);
status = CA_DisplayErrorInfo (MyServer, NULL, status, NULL);

This_Ptr = (void *)&Interface_Ptr;

status = CA_ServerGetObjHandleFromIface (This_Ptr, &MyServer1);
status = CA_DisplayErrorInfo (MyServer, NULL, status, NULL);

..
...
..

if (SUCCEEDED (CA_ServerGetEventObjHandles (MyServer1, &IID_IRayExecEvent,
1, LOCALE_NEUTRAL, eventObjs, &numEventObjs)))
{
..
..
""

The first two calls seem to work status = 0 but I keep getting an invalid handle error when the "CA_ServerGetObjHandleFromIface " is called.

Therefore I never get a vaild CAServerObjHandle to call "CA_ServerGetEventObjHandles" with so the clients registered for the events can be called. What is the best way to obtain this "CAServerObjHandle". Do I need to pass it to the server somehow since the client actually started the server ? Must the client also use
a UI in order to be able to receive the events message from the server?
0 Kudos
Message 1 of 3
(3,278 Views)
Hi,

To get the clients registered to receive events from a server object, just call CA_ServerGetEventObjHandles. See the following sample program file for an example of how to raise events from a server object:
samples\activex\servers\SimpleEvents\SimpleEventsServer.c

Best regards,
Mohan
0 Kudos
Message 2 of 3
(3,278 Views)
The problem was obtaining the "CaServerObjHandle" to pass to the "CA_ServerGetEventObjHandles" routine. This routine in turn obtains handles to all clients registered to receive the events. The events can then be fired to each client. I found you need to add a callback to the ActiveX server object being created. This is part of the process of generating the ActiveX Automation server via the LabWindows ActiveX server wizard. One of the parameters passed to this call back which is implemented in your server code is the "CaServerObjHandle".
0 Kudos
Message 3 of 3
(3,278 Views)