SetEventHandlerForObject

 

Description

It sets up an event handler for an automation object.

Syntax

int SetEventHandlerForObject( Object * pObj, LPCSTR lpcszEventName, Function * pOCFunc )

Parameters

pObj
[input]pointer to an existing COM object reference which must have been initialized.
lpcszEventName
[input]event name (it can retrieved from the object library for the given object)
pOCFunc
[input] pointer to a Function object which has been intialized with an existing Origin C function.

Return

0 if the event handler was set up successfully, 2 if an events COM interface cannot be retrieved from the object, 3 if the event name was wrong.

Examples

EX1

// This is the event handler which catches the event. The prototype must agree
// with the event's declaration, which can be found out by inspecting
// the object library for each particular object.
void    MyEventHandler()
{
    printf("Event hanled\r\n");
}
void    SetEventHandlerForObject_ex1()
{
    // Declare a function object (the function MyEventHandler must
// have been defined before)
    Function        fnEventHandler(MyEventHandler);
    
    Object obj = CreateObject("SomeObject.SomeObject");
    
    int        iRet;
    // This sets up the event handler. It tells the object obj: Call the function
    // MyEventHandler when event "SomeEvent" happens.
    iRet = SetEventHandlerForObject(&obj, "SomeEvent", &fnEventHandler);
    if (0 == iRet)
        out_str("Event handler set up successfully.");
}

See Also

header to Include

origin.h

Reference