I'm writing a Windows Forms application in C++.NET.
I've defined function F which takes 2 arguments a & b.
I need to use the pointer of F inside another function G & I can't
figure out how to do it properly.
Here's what I have :
U32 (*pf) (HANDLE, LPVOID); //declaring the function pointer
U32 __stdcall F (HANDLE a, LPVOID b) //defining F
{
......
return 0;
}
pf = F; //assigning the address of F to pf
//....(inside a Windows Form)...
G(...,pf(a,b),...); //using the function pointer inside of G
The compiler tells me at the pf = F line :
error C2501: 'pf' : missing storage-class or type specifiers
error C2373: 'PixelinkE::pf' : redefinition; different type modifiers
error C2440: 'initializing' : cannot convert from 'U32 (__stdcall
*)(HANDLE,LPVOID)' to 'int'
It seems that it doesn't like the way that pf is defined..
Is this the correct way to declare & use a function pointer or are there
better ways ?
Thanks,
ak 5 1701
AK wrote: U32 (*pf) (HANDLE, LPVOID); //declaring the function pointer
U32 __stdcall F (HANDLE a, LPVOID b) //defining F
pf is not compatible with F, because they're using different calling
conventions. pf is __cdecl, F is __stdcall. Try
U32 (__stdcall *pf) (HANDLE, LPVOID);
Tom
Using __stdcall for both pointer & function doesn't change the errors
removing __stdcall from both doesn't help either..
"Tamas Demjen" wrote: AK wrote: U32 (*pf) (HANDLE, LPVOID); //declaring the function pointer
U32 __stdcall F (HANDLE a, LPVOID b) //defining F
pf is not compatible with F, because they're using different calling conventions. pf is __cdecl, F is __stdcall. Try
U32 (__stdcall *pf) (HANDLE, LPVOID);
Tom
> Here's what I have : U32 (*pf) (HANDLE, LPVOID); //declaring the function pointer
U32 __stdcall F (HANDLE a, LPVOID b) //defining F { ......
return 0; }
pf = F; //assigning the address of F to pf
I believe last expression is in the some function's body, otherwise it's
invalid.
If you want to declare and initialize static variable you have to write
U32 (__stdcall *pf) (HANDLE, LPVOID) = F;
or
typedef U32 (__stdcall * func_pointer) (HANDLE, LPVOID);
func_pointer pf = F;
--
Vladimir Nesterovsky
e-mail: vl******@nesterovsky-bros.com
home: http://www.nesterovsky-bros.com
That does the job - I needed to define pf as a static variable.
Thanks for the help,
ak
"Vladimir Nesterovsky" wrote: Here's what I have :
U32 (*pf) (HANDLE, LPVOID); //declaring the function pointer
U32 __stdcall F (HANDLE a, LPVOID b) //defining F { ......
return 0; }
pf = F; //assigning the address of F to pf
I believe last expression is in the some function's body, otherwise it's invalid. If you want to declare and initialize static variable you have to write
U32 (__stdcall *pf) (HANDLE, LPVOID) = F;
or
typedef U32 (__stdcall * func_pointer) (HANDLE, LPVOID); func_pointer pf = F; -- Vladimir Nesterovsky e-mail: vl******@nesterovsky-bros.com home: http://www.nesterovsky-bros.com
"=?Utf-8?B?QUs=?=" <AK@discussions.microsoft.com> wrote in message news:<C9**********************************@microso ft.com>... I'm writing a Windows Forms application in C++.NET. I've defined function F which takes 2 arguments a & b. I need to use the pointer of F inside another function G & I can't figure out how to do it properly.
Here's what I have :
U32 (*pf) (HANDLE, LPVOID); //declaring the function pointer
U32 __stdcall F (HANDLE a, LPVOID b) //defining F { ......
return 0; }
pf = F; //assigning the address of F to pf
//....(inside a Windows Form)...
G(...,pf(a,b),...); //using the function pointer inside of G
The compiler tells me at the pf = F line : error C2501: 'pf' : missing storage-class or type specifiers error C2373: 'PixelinkE::pf' : redefinition; different type modifiers error C2440: 'initializing' : cannot convert from 'U32 (__stdcall *)(HANDLE,LPVOID)' to 'int'
It seems that it doesn't like the way that pf is defined.. Is this the correct way to declare & use a function pointer or are there better ways ?
Thanks, ak
Hi
There are two different problems:
The function pointer should be forward declared in the Form header file:
extern U32 (__stdcall *pf) (HANDLE, LPVOID);
Notice the "extern" keyword and the "__stdcall" keyword.
The assigment in the cpp file should be:
U32 (__stdcall *pf) (HANDLE, LPVOID) = F;
Alon Fliess
[VC++ MVP] This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Satish Chimakurthi |
last post by:
Hi all,
My question is surely a basic one, but somehow, I am not able to figure it out.
I have a python file "satish.py" as follows:
*satish.py*
def main():
y()
|
by: Randell D. |
last post by:
Folks,
I'm sure this can be done legally, and not thru tricks of the trade - I
hope someone can help.
I'm writing a 'tool' (a function) which can be used generically in any
of my projects. ...
|
by: Edlueze |
last post by:
Greetings:
I have two functions and I would like to pass the ParamArray gathered
from one function to the other function. For the purposes of this post,
let's say that they are calculating...
|
by: Pushkar Pradhan |
last post by:
I want a function to execute another function, which I pass to it,
sometimes it may be mm_6r6c_6r6c, mm_2r2c_2r2c, ... etc. thus this style.
double exec_basecase(void (*func)(double *a, double...
|
by: denizvb |
last post by:
Hai programmers,
Do you know
How to write a function inside another function in c
|
by: krishnasamy |
last post by:
Hi,
I am retrieving the image from DLL through vc++ dll. Actually Image is retrieving in Callback function of main function. When I writing that image file inside of the Callback function then...
|
by: jbanas |
last post by:
In MS Access i have a function that is calculating the distance between two locations using the latitude and longitudes for two points assuming the earth is flat and the lat and long are...
|
by: dries |
last post by:
Hello lads,
I'd like to do the following in C:
1. The user writes a function with predefined arguments and return value in a separate file.
2. The program is compiled as my written 'main'...
|
by: soni2926 |
last post by:
hi,
is it possible to pass a function into another function as a
parameter? Say i have these:
function SaveMe(text)
{...}
function SaveMeNow(text)
{...}
|
by: HighlightReel44 |
last post by:
I need help writing a program which will display a menu with options Square, Cube, Fourth Power and Quit. Accept S,C,F,Q from the user non case sensitive. Use integers between 0 and 100 and...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |