providing call back function to windows API

hello,

can I provide a C++ class member function to windows API? should I specify the calling convention?
if it is not possible, currently i am passing a standalone function to be called back, but how can I access my main window's CDialog variable correctly? passing a pointer to the CDialog there is fine and I can access member variables, but invoking ui element member class crash the application. do i need some kind of synchronization protect?
can I provide a C++ class member function to windows API?
It is possible, but it wouldn't be a class member, it would be a class per "Windows object". And operating systems have many objects.

Maybe you mean having some class that encapsulates a Windows object and mapping a member of that class onto a Windows function. I dunno.

should I specify the calling convention?
It depends on what you're doing, but I'd guess no.

i am passing a standalone function to be called back, but how can I access my main window's CDialog variable correctly?
Callbacks tend to have a context pointer of type void* that passes thru something. You should pass a pointer to the CDialog in that pointer.

do i need some kind of synchronization protect?
Maybe, but it won't be a multi-threaded sync object, it'll be some kind of reference counter as the callback can be further up the call stack in the same thread.
oh sorry I forgot to mention that it is a MFC app.

yes i am using that void* param variable, I passed (DWORD) this when I setup the call back.

inside the call back, touching any ui element in the CDialog crash the app. i think i missed something important.
Perhaps if you are more specific. You haven't really given much to go on.
answering my own question,
function should be declared as CALLBACK, will point to the correct calling convention defined by the system

and my callback function had a bug that crash the app after a few run.

thanks for your help
Topic archived. No new replies allowed.