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

C / C++ / MFC

 
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 
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 
in general, you can't pass pointers to non-static member functions because non-static member functions require an object to operate on.

static member functions don't need an object (that's why they get to be called static).

there are tricks around that let you simulate a function call via function pointer on a non-static member function, but all i've seen are just clever ways of packaging the function call and a pointer to an object together in some other object. there are articles here on CodeProject that describe those approaches.

but, here's what i do: in our libraries, i always define the callbacks with an extra void * (or UINT32) parameter, ex:
typedef BOOL (CALLBACK* COMPLETION_CB_PTR)(int percentDone, void * pCBData);

then i do something like this:
void CMyObject::Foo()
{
  // call a function in the DLL that stores the address of the callback, and the callback data.
  // the callback data here is just the address of 'this' (the current object)
  DLLCallbackSetupFunction(cbFunction, this);
}
 
// this is what the DLL will call
BOOL CALLBACK cbFunction(int pctDone, void *pCBData)
{
    // cast that cbData pointer back to an object of type CMyObject,
    // and then we can use that object without trouble.
    CMyObject * pObj = (CMyObject*)pCBData;
    pObj->Bar(pctDone);
}
 
// and then cbFunction calls this:
void CMyObject::Bar(int iPctDone)
{
... whatever
}

you just need to make sure the DLL passes the cbData back to the callback function:
// in the DLL
...
void *g_pCBData;
COMPLETION_CB_PTR g_pCB;
...
DLLCallbackSetupFunction(COMPLETION_CB_PTR pCB, void *pCBData)
{
  g_pCB = pCB;
  g_pCBData = pCBData;
}
 
then, something calls the callback
if (g_pCB)
{ 
  (g_pCB)(iPctDone, g_pCBData);
}

-c


Cleek | Image Toolkits | Thumbnail maker

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 
GeneralRe: hide dialog Pin
benjymous6-May-05 2:38
benjymous6-May-05 2:38 

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.