By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,912 Members | 1,247 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,912 IT Pros & Developers. It's quick & easy.

problem with callback

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
* 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 discussion thread is closed

Replies have been disabled for this discussion.