473,769 Members | 7,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing function addresses as parameters (Calling convention problems)

I want to pass the address of a function to a timeout type class so that
it can be used as a callback function.

The function I want to use as a callback is defined like...

void rf04::rc_proc(v oid)
{
}

The call to the the function that uses this functions' address is like...

rctimer=new Timeout(rf04::r c_proc);

But the compiler complains with ...

h:\work\telemet ry\rf04.cpp(81) : error C2664: 'Timeout::Timeo ut' :
cannot convert parameter 1 from 'void (void)' to 'void (__cdecl *)(void)'

I tried defining my callback function as

_CRTIMP void __cdecl rf04::rc_proc(v oid)

but then the compiler complained that I was not allowed to use dllimport
functions in this way.

Linux and g++ complains in a different way...

g++ -Wall -g -O -c rf04.cpp
rf04.cpp: In method `rf04::rf04 (char *)':
rf04.cpp:82: assuming & on `rf04::rc_proc'
rf04.cpp:82: no matching function for call to `Timeout::Timeo ut (void
(rf04::*) ())'
timeout.h:19: candidates are: Timeout::Timeou t (void (*) (), unsigned
int = 1000)
timeout.h:29: Timeout::Timeou t (const Timeout &)
make: *** [rf04.o] Error 1

I'm at bit of a loss to understand what is going on. I never really
understood #pragma and stuff like that, but I suspect it's siomething to
do with that.

If my call back function was a global function and not part of a class
then the code compiles and runs OK.

Can anyone give me some clues on this.

Thanks.
Jul 22 '05 #1
1 1580
Mike wrote:
I want to pass the address of a function to a timeout type class so that
it can be used as a callback function.

The function I want to use as a callback is defined like...

void rf04::rc_proc(v oid)
{
}

The call to the the function that uses this functions' address is like...

rctimer=new Timeout(rf04::r c_proc);

But the compiler complains [...]


This is covered in the FAQ. Please see the section on pointers to
members.

V
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
2809
by: Joel | last post by:
Hi all, Forgive me if I've expressed the subject line ill. What I'm trying to do is to call a c++ function given the following: a. A function name. This would be used to fetch a list of function descriptors for the overloaded functions of that name. A function descriptor would contain the address of the function to be called, and a description of the parameters that it must take. b. A list of parameters. This would be compared to the...
6
3529
by: Adrian | last post by:
I am trying to pass the address of a C++ function into a Fortran routine to enable the Fortran routine to call this C++ function. I have to do it this way as our build process does not allow circular dependencies of DLL's. Does anyone know how to do this, I have tried everything in my book. I have a C++ function GetP: DllExport void GetP()
7
23555
by: Newbie_sw2003 | last post by:
Where should I use them? I am giving you my understandings. Please correct me if I am wrong: MACRO: e.g.:#define ref-name 99 The code is substituted by the MACRO ref-name. So no overhead. Execution is faster. Where will it be stotred?(Is it in bss/stack/?) FUNCTION:
0
1546
by: Richard Buckshaw | last post by:
Mimick the older C/ pascal dll parameter passing convention? - VB Class Mod? Hello, I have been attempting to write a VB class that would expose its stuff to an older (ok, legacy application) program which can load and call exported functions from the old style dlls. With little documentation to go on, my legacy app defines
8
572
by: kurtcobain1978 | last post by:
-------------------------------------------------------------------------------- I need to do the exactly same thing in VB.NET. Load a unmanaged C DLL dynamically and then call a function in which I pass the callback function as an argument. My C function being called callback as type _cdecl. Does anybody have any ideas?
1
1832
by: matthew breedlove | last post by:
I have a Managed VC++ WinForms app in VC8 calling a member function of a class in a native DLL. My managed code is similar to this: System::Void btnTest_Click(System::Object^ sender, System::EventArgs^ e) { Receiver r; std::vector<char> v; v.push_back('A');
11
407
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I can use dlopen/whatever to convert the function name into a pointer to that function, but actually calling it, with the right number of parameters, isn't easy. As far as I can see, there are only two solutions: 1) This one is portable. If...
10
1817
by: ypjofficial | last post by:
Hello All, since the programs' stack is shared among all the function inside the program, I was just doing some R&D to see whether the same stack space is used for the variables inside the different functions are not. below is my code //program start void fun1() {int i;
11
2741
by: Felix Kater | last post by:
Hi, I can compile and run this code (see below) which twice calls the function f, first with too less, second with too much arguments. But is it legal and free of memory leaks and other problems? Of course, I presume that inside f I don't access i in case it was called via g. int f(int i){ /* ... */ return 0; }
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10214
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9996
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3963
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.