samedi 14 novembre 2020

Passing a callback as an instance method instead of a static method

I currently have a function called IoTHubDeviceClient_LL_SendEventAsync the 3rd parameter of this method takes in a function pointer and its definition looks like this

typedef void(*IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK)(IOTHUB_CLIENT_CONFIRMATION_RESULT result, void* userContextCallback);

Now I can use the IoTHubDeviceClient_LL_SendEventAsync function properly if I define a static function as shown in the class below and not making it an instance of the class

class Foo
{
   void test()
   {
      IoTHubDeviceClient_LL_SendEventAsync(DHandle, Mhandle, MyCallback, Null);
   }
}
static void MyCallback(IOTHUB_CLIENT_CONFIRMATION_RESULT result, void* userContextCallback)
{.....}

My question is how can I pass in an instance method instead of a static method. I would like to do something like this

class Foo
{
   void test()
   {
      IoTHubDeviceClient_LL_SendEventAsync(DHandle, Mhandle, MyCallback, Null); //<---3rd parameter fails
   }
   void MyCallback(IOTHUB_CLIENT_CONFIRMATION_RESULT result, void* userContextCallback)
   {.....}
}

Any suggestions ?

Aucun commentaire:

Enregistrer un commentaire