473,394 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

problem with callback

I'm trying to write a callback function, I've done it before,
but this time I seem to be having problems...

I define the following...

typedef int (* ENUMINTERFACE)(char* szIP);
void enumInterfaces(ENUMINTERFACE pFn);
int InterfaceEnumProc(char* szIP);

then at some point in my code I call
enumInterfaces(InterfaceEnumProc);

I get the compilation error
'cannot convert parameter 1 from int(char*) to int(_cdecl*)(char*)

whats the correct form for declaring callbacks.

Mark
Jul 26 '05 #1
5 1783
Mark wrote:
I'm trying to write a callback function, I've done it before,
but this time I seem to be having problems...

I define the following...

typedef int (* ENUMINTERFACE)(char* szIP);
void enumInterfaces(ENUMINTERFACE pFn);
int InterfaceEnumProc(char* szIP);

then at some point in my code I call
enumInterfaces(InterfaceEnumProc);

I get the compilation error
'cannot convert parameter 1 from int(char*) to int(_cdecl*)(char*)
This "_cdecl" business is apparently added by your compiler. You might
want to consider asking in a newsgroup that deals with your compiler...
whats the correct form for declaring callbacks.


This is explained in the FAQ 5.8.

V
Jul 26 '05 #2
Mark wrote:
I'm trying to write a callback function, I've done it before,
but this time I seem to be having problems...

I define the following...

typedef int (* ENUMINTERFACE)(char* szIP);
void enumInterfaces(ENUMINTERFACE pFn);
int InterfaceEnumProc(char* szIP);

then at some point in my code I call
enumInterfaces(InterfaceEnumProc);
try:
enumInterfaces( & InterfaceEnumProc )
I get the compilation error
'cannot convert parameter 1 from int(char*) to int(_cdecl*)(char*)

whats the correct form for declaring callbacks.

Mark

Jul 26 '05 #3
Mark wrote:
I'm trying to write a callback function, I've done it before,
but this time I seem to be having problems...

I define the following...

typedef int (* ENUMINTERFACE)(char* szIP);
void enumInterfaces(ENUMINTERFACE pFn);
int InterfaceEnumProc(char* szIP);

then at some point in my code I call
enumInterfaces(InterfaceEnumProc);

I get the compilation error
'cannot convert parameter 1 from int(char*) to int(_cdecl*)(char*)


The compiler expects the callback function to be a 'C' function, rather
than a C++ function. You've either defined it (or the typedef) in a 'C'
code block -or- the enumInterfaces() expects its param to be a 'C'
function (this is the case with most 3rd-party and Windows libs that
use callback functions - they must be 'C' functions).

This would be a valid callback function defined within a C++ module:

extern "C" int InterfaceEnumProc(char * szIP) { /* code here */ }
Jul 26 '05 #4
On Tue, 26 Jul 2005 18:23:03 +0000 (UTC), "Mark"
<ms******@REMOVETHISBITbtinternet.com> wrote:
I define the following...


For what it's worth, your testcase compiles with no errors or warnings
on all C++ compilers I have access to, and appears to be correct code
otherwise.

Are you sure you aren't omitting important details?

As part of the debugging process, and before asking questions, it is
helpful to create a so-called "minimal complete testcase." This way
you can have a clear idea in your mind of exactly what is failing, and
be sure that the problem actually is where you think it is, before
proceding further with debugging (by asking questions on Usenet).
Aaron W. LaFramboise

Jul 27 '05 #5
* Mark:
I'm trying to write a callback function, I've done it before,
but this time I seem to be having problems...

I define the following...

typedef int (* ENUMINTERFACE)(char* szIP);
void enumInterfaces(ENUMINTERFACE pFn);
int InterfaceEnumProc(char* szIP);

then at some point in my code I call
enumInterfaces(InterfaceEnumProc);

I get the compilation error
'cannot convert parameter 1 from int(char*) to int(_cdecl*)(char*)

whats the correct form for declaring callbacks.


"__cdecl" is a Microsoft extension that denotes a machine code level calling
convention.

You have somehow managed to declare ENUMINTERFACE using that calling
convention.

I suspect you have fixed the code a bit before presenting it here, omitting
something relevant.

Btw. it's not a good idea to use all uppercase for non-macro names.

All uppercase should be reserved for macro names.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 27 '05 #6

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

Similar topics

3
by: Tomaz Rotovnik | last post by:
Hi I created very simple dll (vc++) which has three functions (start, stop and initialization). it starts capturing sound from soundblaster and when the buffer is filled with the data, dll calls...
1
by: Mohamed Fysal | last post by:
I have written a Regular DLL with many Export Functions and one CALLBACK fun ction . The callback function declared in the .cpp file of the Regular DLL is as fol lows: typedef BOOL...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
0
by: Anton | last post by:
I have a c# application, which calls a dll (which I made, so I can modify the source code), passes there several parameters. The Dll contains a thread pool. In the entry function which is called...
3
by: ryan.mitchley | last post by:
Hi all I have a class (cPort) that is designed to receive objects and, depending on the type, call a handler (callback) in any descendant of a cProcessBlock class. Callback functions take a...
8
by: Chris Cap | last post by:
I am getting some strange behavior when using RaiseCallbackEvent. I have a form that implements ICallbackEventHandler. During the client callback, a session variable is set that is used on the...
1
by: gzannd | last post by:
I have a problem with submitting a form to a PHP page through a dynamically created IFRAME in IE7. This code works fine in Firefox. However, IE7 submits an empty form--the correct PHP page is...
6
by: per9000 | last post by:
An interesting/annoying problem. I created a small example to provoke an exception I keep getting. Basically I have a C-struct (Container) with a function-pointer in it. I perform repeated calls...
2
by: NannMaw | last post by:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Server Error in '/WebSite1' Application. -------------------------------------------------------------------------------- Invalid postback or callback argument. ...
4
by: Immortal_Nephi | last post by:
You have written several global functions inside header code. Then, you create either static library or dynamic linked library. All global functions can be reuseable to the main() function when...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.