cdesigner
asked on
Pointer to function
I have function
void Function (char* string);
I need get pointer (void*) to this function
how?
void Function (char* string);
I need get pointer (void*) to this function
how?
ASKER
but I have definition in header
typedef void (WINAPI *pFunction)(char *string);
and you method not compile....
error C2440: '=' : cannot convert from 'void (__stdcall CMyClassDlg::*)(char *)' to 'void (__stdcall *)(char *)'
typedef void (WINAPI *pFunction)(char *string);
and you method not compile....
error C2440: '=' : cannot convert from 'void (__stdcall CMyClassDlg::*)(char *)' to 'void (__stdcall *)(char *)'
How about you say what you're actually trying to do. It seems like you actually want a pointer to a _member_ function, which is different. You'll also have a problem passing a pointer to a member function to something which doesn't expect it, as the implied first parameter (this) will not be expected.
ASKER
how I can do?
function to need pointer :
void WINAPI Set (UINT Code, void *pFunc);
help please
function to need pointer :
void WINAPI Set (UINT Code, void *pFunc);
help please
ASKER
send me request for answer
I send you points
I send you points
gothick is right. The problem is that the function is a non-static member of a class. A pointer to a non-static member function is different than a pointer to a non-member function and there is no posibility to convert between them. You must make the member function a static member function or you must use a special type of pointer called a "pointer-to-member" This type of pointer is very different than other pointers and cannot be converted to a "regular" pointer.
It would help if we knew what you are trying to do.
It would help if we knew what you are trying to do.
You 're using Borland with non-borland extensions maybe . Try casting using (*pfunction) . For example , some borland modes require the cast of (DLGPROC) , (WNDPROC) etc in "special" function pointers.
ASKER
Now I understood my source , this other problem
>void Function (char* string);
> I need get pointer (void*) to this function how?
You can do this simply by
void (*fp) (char* string);
fp getpointer(void*)
{
fp = Function;
return fp;
}
If it is a C function and not a functon of C++ Class.
>how I can do?
> function to need pointer :
> void WINAPI Set (UINT Code, void *pFunc);
> help please
for this you should do like this
void WINAPI Set(UINT Code, (void (*fp) (char* string)) )
> I need get pointer (void*) to this function how?
You can do this simply by
void (*fp) (char* string);
fp getpointer(void*)
{
fp = Function;
return fp;
}
If it is a C function and not a functon of C++ Class.
>how I can do?
> function to need pointer :
> void WINAPI Set (UINT Code, void *pFunc);
> help please
for this you should do like this
void WINAPI Set(UINT Code, (void (*fp) (char* string)) )
ramshakal, have you read the question history?
ASKER
question answered by gothick
Should I repost my answer for you to grade?
ASKER
yes
send me answer
I send you points
send me answer
I send you points
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just "Function" should evaluate to a pointer to the function, e.g.
void Function(char* string);
....
void (*fptr)(char*); /* Declare fptr as a pointer to a function returning void */
/* and taking a char* parameter */
fptr = Function;
If you want it void*, then just cast it.