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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

function pointer problem

Status
Not open for further replies.

timmiepoo

Programmer
Jan 15, 2003
1
US
i'm attempting to wrap some API calls in a COM server so i can call it from the web, and i'm having some problems with a function pointer. one of the API calls that i'm making expects a "C-style" function pointer as an argument. the problem is that the callback function i want to use is now a member of my CoClass. so when i try to pass a pointer to the function i get this compiler error:

cannot convert from 'int (__thiscall CTask::*)(long,int,int,int,int,const char *)' to 'int (__cdecl *)(long,int,int,int,int,const char *)'
There is no context in which this conversion is possible

i tried some googling and came up with this: . i considered all 3 of the solutions listed. one does not work because unless i am mistaken, i cannot use static functions in my CoClass (am i wrong about that?). two and three do not work because i can't create a global instance of my CoClass.

i have tried various methods of casting my function pointer in an attempt to make this work. so far i've had no success. i'm beginning to wonder if this is even possible. can anyone tell me (1) if this is possible, and if so (2) how do i do it? any hints or suggestions will be greatly appreciated. thank you!
 
You can certainly use static functions in your CoClass, what makes you think that you can't? I have had similair problems like you with the windows API. I do not know which API you're calling and what the prototype of the c-style method that needs to be send in is, but usually you can get around this problem by using static variables (for instance building an object map, like MFC does with its wrappers around the windows functions) or by sending in a parameter which holds a pointer to the object (like for instance when spawning another thread).
Greetings,
Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top