Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

callfunction in class

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
how can I make a memberfunction to be called as a callback.<br>I am writing a imageprocessing-program and grab the image from a webcam. I want to make the framecallbackfunction a memberfunction.
 
This was taken from MSDN online(msdn.microsoft.com) <br><br><FONT FACE=monospace><br>Callback Function Example<br>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.<br><br>Note&nbsp;&nbsp;Once registered, a callback function cannot be unregistered. Closing the queue, closes the callback function as well.<br><br>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<br><br>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.<br><br>To read a single message using a callback function <br><br>Write the callback function. <br>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. <br>Specify the message properties to be retrieved, retrieving only those properties that are needed. <br>Initialize the MQMSGPROPS structure on the heap. <br>Call MQReceiveMessage to read the message from the queue, making sure to free the MQMSGPROPS structure from within the callback function. <br>Call MQCloseQueue to close the queue, freeing all memory allocated for any pending MQReceiveMessage calls. Closing the queue, closes the callback function as well. <br>Code Example<br>The following example reads the first message of the queue using a callback function.<br><br>//////////////////////////////<br>// Receive callback function.<br>/////////////////////////////<br>&nbsp;<br>void APIENTRY ReceiveCallbackRoutine(<br>&nbsp;&nbsp;&nbsp;HRESULT hr,<br>&nbsp;&nbsp;&nbsp;QUEUEHANDLE hSource,<br>&nbsp;&nbsp;&nbsp;DWORD dwTimeout,<br>&nbsp;&nbsp;&nbsp;DWORD dwAction,<br>&nbsp;&nbsp;&nbsp;MQMSGPROPS* pMessageProps,<br>&nbsp;&nbsp;&nbsp;LPOVERLAPPED lpOverlapped,<br>&nbsp;&nbsp;&nbsp;HANDLE hCursor<br>&nbsp;&nbsp;)<br>&nbsp;{<br>&nbsp;&nbsp;if (FAILED(hr))<br>&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;// Error handler for Callback routine.<br>&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;else<br>&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;// Process message.<br>&nbsp;&nbsp;}<br>&nbsp;}<br><br>//////////////<br>// Open Queue<br>//////////////<br>&nbsp;<br>HRESULT hr;<br>QUEUEHANDLE hQueue;<br>&nbsp;<br>hr = MQOpenQueue(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;szwFormatNameBuffer,&nbsp;&nbsp;&nbsp;&nbsp;// Format Name of the queue to be opened<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MQ_RECEIVE_ACCESS,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Access rights to the Queue<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// No receive Exclusive<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&hQueue&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// OUT: handle to the opened Queue<br>);<br>&nbsp;<br>if (FAILED(hr))<br>{<br>&nbsp;// Error handler for MQOpenQueue.<br>}<br>&nbsp;<br>&nbsp;<br>MQMSGPROPS * pmsgprops;<br>MQPROPVARIANT *paVariant;<br>MSGPROPID * paPropId;<br>DWORD dwcPropId = 0;<br>&nbsp;<br>//<br>//&nbsp;&nbsp;The output parameters to an asynchronous call to MQReceiveMessage <br>//&nbsp;&nbsp;should be kept intact until the operation completes, you should <br>//&nbsp;&nbsp;not free or reuse them until the operation is complete.<br>//<br>pmsgprops = new MQMSGPROPS;<br>paVariant = new MQPROPVARIANT[ 10];<br>paPropId = new MSGPROPID[ 10];<br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>//////////////////////////////////////////////////<br>// Prepare the message properties to be retrieved.<br>/////////////////////////////////////////////////<br>&nbsp;<br>&nbsp;<br>// Set the PROPID_M_BODY property.<br>paPropId[dwcPropId] = PROPID_M_BODY;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//PropId<br>paVariant[dwcPropId].vt = VT_VECTOR¦VT_UI1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Type<br>paVariant[dwcPropId].caub.cElems = MSG_BODY_LEN ;&nbsp;&nbsp;&nbsp;&nbsp;//Value<br>paVariant[dwcPropId].caub.pElems = new unsigned char[ MSG_BODY_LEN];<br>&nbsp;<br>&nbsp;dwcPropId++;<br>&nbsp;<br>////////////////////////////////<br>// Initialize the MQMSGPROPS structure<br>///////////////////////////////<br>pmsgprops-&gt;cProp = dwcPropId;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Number of properties<br>pmsgprops-&gt;aPropID = paPropId;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Ids of properties<br>pmsgprops-&gt;aPropVar = paVariant;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Values of properties<br>pmsgProps-&gt;aStatus&nbsp;&nbsp;= NULL;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//No Error report<br>&nbsp;<br>&nbsp;<br>///////////////////////////////////////////////<br>//&nbsp;&nbsp;Receive the message using callback function<br>//&nbsp;&nbsp;ReceiveCallbackRoutine.<br>///////////////////////////////////////////////<br>&nbsp;<br>hr = MQReceiveMessage(<br>&nbsp;&nbsp;&nbsp;&nbsp;hQueue,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Handle to the Queue<br>&nbsp;&nbsp;&nbsp;&nbsp;5 * 60 * 1000,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Max time (msec) to wait<br>&nbsp;&nbsp;&nbsp;&nbsp;MQ_ACTION_RECEIVE,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Action<br>&nbsp;&nbsp;&nbsp;&nbsp;pmsgprops,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Properties to retrieve<br>&nbsp;&nbsp;&nbsp;&nbsp;NULL,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// No OVERLAPPED structure<br>&nbsp;&nbsp;&nbsp;&nbsp;ReceiveCallbackRoutine,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Callback function<br>&nbsp;&nbsp;&nbsp;&nbsp;NULL,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// No Cursor<br>&nbsp;&nbsp;&nbsp;&nbsp;NULL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// No transaction<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br>&nbsp;<br>if (FAILED(hr))<br>&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;Error handler for MQReceiveMessage.<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>Built on Wednesday, January 05, 2000<br></font><br> <p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
 
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'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top