Click here to Skip to main content
15,922,894 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: function returning CRecordset Pin
scoroop7-May-05 0:34
scoroop7-May-05 0:34 
GeneralRe: function returning CRecordset Pin
David Crow7-May-05 7:59
David Crow7-May-05 7:59 
GeneralRe: function returning CRecordset Pin
scoroop7-May-05 8:20
scoroop7-May-05 8:20 
GeneralRe: function returning CRecordset Pin
David Crow7-May-05 10:47
David Crow7-May-05 10:47 
GeneralRe: function returning CRecordset Pin
scoroop7-May-05 11:28
scoroop7-May-05 11:28 
GeneralRe: function returning CRecordset Pin
David Crow9-May-05 2:17
David Crow9-May-05 2:17 
GeneralRe: function returning CRecordset Pin
scoroop9-May-05 5:49
scoroop9-May-05 5:49 
Generalpassing a callback function pointer to a DLL within an MFC application Pin
DKaiser6-May-05 6:47
DKaiser6-May-05 6:47 
I have programmed a DLL in order to encapsulate some code that is polling data from a USB peripheral unit. The user of the DLL must be able to define his own handler for that "Snapbutton" event.

To acheive this i am passing a function pointer to the DLL. The DLL then is calling back this function every time the event is detected on the peripheral unit.

This is working ok with the except that accessing MFC member functions does NOT always work. if i pass a pointer to the following function to my DLL i hear the beep every time the DLL calls the function but the checkbox is not set:


void CDemoDlg::SnapButtonHandler()<br />
{<br />
  m_check_snap.SetCheck(TRUE);	<br />
  Beep(4000,50);<br />
}<br />

i have tried this code in a minimalist MFC application and it worked well but within a more complex MFC application it didn't work.

i suppose that calling an MFC member function from outside the MFC framework causes some problems. does anybody have an idea how i could solve that problem?

here is the code loading the DLL and passing the function pointer to it:
<br />
//dialog window object<br />
CEM2800DLLDemoDlg dlg;<br />
<br />
//Global function assigned to the member function Snapbuttonhandler<br />
void HandleSnapButton() {dlg.SnapButtonHandler();}<br />
<big><br />
if i directly pass a pointer to a mfc member function to the DLL,<br />
i get an "illegal call of a non-static member function" error<br />
that is why i define that global function "HandleSnapButton"<br />
</big><br />
//function prototype with callback function pointer as a parameter<br />
typedef BYTE (CALLBACK* SetSnapButtonHandlerType) (void(*ptr)());	<br />
									<br />
//callback-pointer to DLL function "SetSnapButtonHandler"<br />
//SetSnapButtonHandlerType pSetSnapButtonHandler=NULL;<br />
<br />
//Load DLL and pass a pointer to callback function to the DLL<br />
void LoadSnapButtonDLL(void (*pHnd) ())<br />
{	<br />
 //load DLL<br />
 if (!hClcltr) hClcltr=LoadLibrary(szDLLName);<br />
<br />
 if (hClcltr)	<br />
 {	<br />
   //get process address<br />
   pSetSnapButtonHandler = (SetSnapButtonHandlerType)GetProcAddress(    <br />
   hClcltr,"SetSnapButtonHandler");<br />
<br />
   //if the process address could be retreived call the function <br />
  if (pSetSnapButtonHandler) pSetSnapButtonHandler(pHnd);}<br />
}<br />


The DLL is loaded and the callback function pointer is passed to the DLL by LoadSnapButtonDLL(&HandleSnapButton);

Has anybody an idea why the access to methods of the MFC member variables like m_check_snap.SetCheck(TRUE); within the callback function are without effect?

i must admit i am a still a beginner in C++ and MFC programming so i would be very thankful for every hint.


Danny Kaiser

GeneralRe: passing a callback function pointer to a DLL within an MFC application Pin
Chris Losinger6-May-05 7:45
professionalChris Losinger6-May-05 7:45 
GeneralSecurity Template Pin
arthivjii6-May-05 6:45
arthivjii6-May-05 6:45 
GeneralMoving Items in a virtual List-View Pin
Luy6-May-05 5:38
Luy6-May-05 5:38 
Questionhow to embed a dialog into the frame? Pin
steven_wong6-May-05 4:19
steven_wong6-May-05 4:19 
GeneralTexture mapping and color replacing with GDI Pin
DaViL836-May-05 3:40
DaViL836-May-05 3:40 
Generalown class Pin
_tasleem6-May-05 2:36
_tasleem6-May-05 2:36 
GeneralRe: own class Pin
benjymous6-May-05 2:42
benjymous6-May-05 2:42 
GeneralRe: own class Pin
_tasleem6-May-05 3:29
_tasleem6-May-05 3:29 
GeneralRe: own class Pin
benjymous6-May-05 3:32
benjymous6-May-05 3:32 
GeneralRe: own class Pin
_tasleem6-May-05 4:15
_tasleem6-May-05 4:15 
GeneralRe: own class Pin
_tasleem6-May-05 21:21
_tasleem6-May-05 21:21 
GeneralRe: own class Pin
ThatsAlok6-May-05 2:43
ThatsAlok6-May-05 2:43 
GeneralRe: own class Pin
David Crow6-May-05 3:48
David Crow6-May-05 3:48 
GeneralRe: own class Pin
ThatsAlok6-May-05 20:59
ThatsAlok6-May-05 20:59 
GeneralRe: own class Pin
_tasleem6-May-05 21:17
_tasleem6-May-05 21:17 
GeneralRe: own class Pin
ThatsAlok6-May-05 22:58
ThatsAlok6-May-05 22:58 
Generalhide dialog Pin
_tasleem6-May-05 2:29
_tasleem6-May-05 2:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.