×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

callfunction in class

callfunction in class

callfunction in class

(OP)
how can I make a memberfunction to be called as a callback.
I am writing a imageprocessing-program and grab the image from a webcam. I want to make the framecallbackfunction a memberfunction.

RE: callfunction in class

This was taken from MSDN online(msdn.microsoft.com)


Callback Function Example
This example uses a callback function (fnReceiveCallback is not NULL) to read the first message in a queue. In this case, the message is read by MQReceiveMessage and the returned message properties (and error codes) are handled by the registered callback function.

Note  Once registered, a callback function cannot be unregistered. Closing the queue, closes the callback function as well.

When using a callback function, it is very important to allocate the memory for the MQMSGPROPS structure on the heap. Not on the stack. In addition, always free MQMSGPROPS within the callback function

When multiple asynchronous MQReceiveMessage calls are outstanding, several callbacks are registered; upon arrival of a message, the first registered callback is called. Internally, MSMQ uses the WaitForMultipleObjects API which is limited to 64 objects per process.

To read a single message using a callback function

Write the callback function.
Call MQOpenQueue to open the queue with receive or peek access. If the queue is opened with receive access, the application can still peek at the messages in the queue.
Specify the message properties to be retrieved, retrieving only those properties that are needed.
Initialize the MQMSGPROPS structure on the heap.
Call MQReceiveMessage to read the message from the queue, making sure to free the MQMSGPROPS structure from within the callback function.
Call MQCloseQueue to close the queue, freeing all memory allocated for any pending MQReceiveMessage calls. Closing the queue, closes the callback function as well.
Code Example
The following example reads the first message of the queue using a callback function.

//////////////////////////////
// Receive callback function.
/////////////////////////////
 
void APIENTRY ReceiveCallbackRoutine(
   HRESULT hr,
   QUEUEHANDLE hSource,
   DWORD dwTimeout,
   DWORD dwAction,
   MQMSGPROPS* pMessageProps,
   LPOVERLAPPED lpOverlapped,
   HANDLE hCursor
  )
 {
  if (FAILED(hr))
   {
    // Error handler for Callback routine.
   }
  else
  {
   // Process message.
  }
 }

//////////////
// Open Queue
//////////////
 
HRESULT hr;
QUEUEHANDLE hQueue;
 
hr = MQOpenQueue(
     szwFormatNameBuffer,    // Format Name of the queue to be opened
     MQ_RECEIVE_ACCESS,      // Access rights to the Queue
     0,                      // No receive Exclusive
     &hQueue                 // OUT: handle to the opened Queue
);
 
if (FAILED(hr))
{
 // Error handler for MQOpenQueue.
}
 
 
MQMSGPROPS * pmsgprops;
MQPROPVARIANT *paVariant;
MSGPROPID * paPropId;
DWORD dwcPropId = 0;
 
//
//  The output parameters to an asynchronous call to MQReceiveMessage
//  should be kept intact until the operation completes, you should
//  not free or reuse them until the operation is complete.
//
pmsgprops = new MQMSGPROPS;
paVariant = new MQPROPVARIANT[ 10];
paPropId = new MSGPROPID[ 10];
 
    
//////////////////////////////////////////////////
// Prepare the message properties to be retrieved.
/////////////////////////////////////////////////
 
 
// Set the PROPID_M_BODY property.
paPropId[dwcPropId] = PROPID_M_BODY;                //PropId
paVariant[dwcPropId].vt = VT_VECTOR¬¶VT_UI1;         //Type
paVariant[dwcPropId].caub.cElems = MSG_BODY_LEN ;    //Value
paVariant[dwcPropId].caub.pElems = new unsigned char[ MSG_BODY_LEN];
 
 dwcPropId++;
 
////////////////////////////////
// Initialize the MQMSGPROPS structure
///////////////////////////////
pmsgprops->cProp = dwcPropId;     //Number of properties
pmsgprops->aPropID = paPropId;        //Ids of properties
pmsgprops->aPropVar = paVariant;      //Values of properties
pmsgProps->aStatus  = NULL;           //No Error report
 
 
///////////////////////////////////////////////
//  Receive the message using callback function
//  ReceiveCallbackRoutine.
///////////////////////////////////////////////
 
hr = MQReceiveMessage(
    hQueue,                     // Handle to the Queue
    5 * 60 * 1000,              // Max time (msec) to wait
    MQ_ACTION_RECEIVE,          // Action
    pmsgprops,                  // Properties to retrieve
    NULL,                       // No OVERLAPPED structure
    ReceiveCallbackRoutine,     // Callback function
    NULL,                       // No Cursor
    NULL                        // No transaction
              );
 
if (FAILED(hr))
   {
     //  Error handler for MQReceiveMessage.
    }

Built on Wednesday, January 05, 2000

Karl
kb244@kb244.com

Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)
http://www.brainbench.com/transcript.jsp?pid=629151

RE: callfunction in class

You can't make a regular member function a callback because you can't pass a 'this' (all regular member functions have a hidden first argument 'this'). You can get around this by making the member function static. Static member functions have no 'this'.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close