From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Callback from DLL

Hello,

 

I am making a wrapper DLL for SDK, that is utilizing a callback registration possibility. I have problems.

 

These are the function prototypes described in the .h file of the SDK.

 

One function is the Callabck prototype function.

Second, is the definition of the registering function.

 

Here they are:

 

typedef void (__cdecl * CmtCallbackFunction)(int32_t instance, int32_t callbackType, void* param, void* userParam);

 

XsensResultValue cmtRegisterCallback(const int32_t instance, CmtCallbackFunction func, CmtCallbackType type, void* userParam);

 

Using these function prototypes, I made callback routine:

 

void FireEvent( int instance, int CallBackType, void *param, void *UserEvent )
{
    MgErr result;
    //int *param1;
    result = PostLVUserEvent( ( LVUserEventRef )UserEvent, param );
    Sleep(0);
}

 

And callback registration code

 

XsensResultValue result;
//void *param = NULL;
CmtCallbackFunction FuncPtr = &FireEvent;
result = cmtRegisterCallback( instance, FuncPtr, CMT_CALLBACK_ONMESSAGERECEIVED, ( void* )UserEvent );

 

The whole function called from labview

 

int CreateInstance2( const char *SerialNumber, LVUserEventRef UserEvent )
{
    int instance = -1;
    instance = cmtCreateInstance( SerialNumber );
    if( instance != -1 )
    {
        XsensResultValue result;
        //void *param = NULL;
        CmtCallbackFunction FuncPtr = &FireEvent;
        result = cmtRegisterCallback( instance, FuncPtr, CMT_CALLBACK_ONMESSAGERECEIVED, ( void* )UserEvent );
        Sleep(0);
    }
    return instance;
}

 

In labview, I create the UserEvent, pass it to the library, register the userevent in wait structure.

 

When debugging the DLL, the FireEvent routine gets called, obviously, the PostLVUserEvent results in Error of argument.

The Event refnum is wrong.

I do not know how to pass the refnum to the routine. I thought, that it gets passed through the UserEvent parameter, but it does not 😞

 

Please help.

 

 

 

0 Kudos
Message 1 of 3
(2,455 Views)

So the correct way to register was like this :

 

result = cmtRegisterCallback( instance, FuncPtr, CMT_CALLBACK_ONMESSAGERECEIVED, ( void* )*UserEvent );

 

Smiley Frustrated

 

I had there a missing asterisk.

0 Kudos
Message 2 of 3
(2,443 Views)

Do you  resolve it ?

I have meet  the same question.I want to use call back with dll in labview.My question as below

http://forums.ni.com/t5/LabVIEW/Question-about-timeSetEvent/m-p/2266246#M717433

0 Kudos
Message 3 of 3
(2,378 Views)