473,378 Members | 1,478 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,378 software developers and data experts.

Problem with __cdecl

I m using a library function which need to be passed a function as
parameter.
If i declare the function as
int (void *, int, char **, char **)
it throws an error
cannot convert parameter from 'int (void *,int,char ** ,char ** )' to
'int (__cdecl *)(void *,int,char ** ,char ** )'

If the same function is moved out of the class or declared static
it works fine.
But i don't want the function to be declared static or moved out of the
class because i m using non static members of the class
I just mentioned the subject according to error.
Any solutions to this problem

Jul 22 '05 #1
6 4891
I m using a library function which need to be passed a function as
parameter.
If i declare the function as
int (void *, int, char **, char **)
it throws an error
cannot convert parameter from 'int (void *,int,char ** ,char ** )' to
'int (__cdecl *)(void *,int,char ** ,char ** )'

If the same function is moved out of the class or declared static
it works fine.
But i don't want the function to be declared static or moved out of the
class because i m using non static members of the class
I just mentioned the subject according to error.
Any solutions to this problem


I member function of a class, if that is what you are trying to pass, is of
a different type than a regular (non-class) function or a static member
function.

If the library function is something like

typedef int (*CALLBACK)(void *,int,char ** ,char ** );
void takes_callback(CALLBACK *pf, void *,int,char ** ,char ** );

then you cannot you a member funciton as a callback....
class Sample {
public:
//. . .
int sample_func(void *,int,char ** ,char ** );
private:
// . . .
};
//. . .
takes_callback(&sample_func, vp, 5, &pchar, &pchar);

....because sample_func is of type pointer to member of Sample (and
taking void *,int,char ** ,char ** ). That is, it is of type
int (Sample::*)(void *,int,char ** ,char ** );
and not of type
int (*)(void *,int,char ** ,char ** );
Jul 22 '05 #2
Is there any way to cast int (Sample::*)(void *,int,char ** ,char ** );
into int (*)(void *,int, char **, char **);
thanks,

Jul 22 '05 #3
A member function is essentially different than a stand-alone function
in that it always receives an implicit parameter, this, in its stack
frame. You could probably cast away the differences to the point that
the compiler will be happy but you will wind up crashing your program
in a rather spectacular way when your stack becomes corrupted as the
call-back is made. You are better off adjusting your architecture to
the limitations of the call-back mechanism than kicking against the
pricks.

Regards,

Jon Trauntvein

Jul 22 '05 #4

"Sagar Choudhary" <sa*************@gmail.com> wrote in message
news:11*********************@c13g2000cwb.googlegro ups.com...
I m using a library function which need to be passed a function as
parameter.
If i declare the function as
int (void *, int, char **, char **)
it throws an error
cannot convert parameter from 'int (void *,int,char ** ,char ** )' to
'int (__cdecl *)(void *,int,char ** ,char ** )'

If the same function is moved out of the class or declared static
it works fine.
But i don't want the function to be declared static or moved out of the
class because i m using non static members of the class
I just mentioned the subject according to error.
Any solutions to this problem


If you want to pass it as a dynamic function... the function in the library
needs to be declared int(T::Function *)(void *,int,char**,char**)

So I don't think its gonna work. I'm thinking its something to do with how
the class uses functions i.e. first parameter in the member function is
actually a pointer to the object tho is not shown

Course I also think the world is flat....

Cheers,
Iguana.
Jul 22 '05 #5

"Iguana" <ha*****@f2s.com> wrote in message
news:cq**********@news.freedom2surf.net...

"Sagar Choudhary" <sa*************@gmail.com> wrote in message
news:11*********************@c13g2000cwb.googlegro ups.com...
I m using a library function which need to be passed a function as
parameter.
If i declare the function as
int (void *, int, char **, char **)
it throws an error
cannot convert parameter from 'int (void *,int,char ** ,char ** )' to
'int (__cdecl *)(void *,int,char ** ,char ** )'

If the same function is moved out of the class or declared static
it works fine.
But i don't want the function to be declared static or moved out of the
class because i m using non static members of the class
I just mentioned the subject according to error.
Any solutions to this problem


If you want to pass it as a dynamic function... the function in the
library needs to be declared int(T::Function *)(void *,int,char**,char**)

So I don't think its gonna work. I'm thinking its something to do with
how the class uses functions i.e. first parameter in the member function
is actually a pointer to the object tho is not shown

Course I also think the world is flat....

Cheers,
Iguana.


Expand the thread first you say?

What a clever idea! ;)

Iguana
Jul 22 '05 #6
On Tue, 21 Dec 2004 20:37:53 -0800, Sagar Choudhary wrote:
I m using a library function which need to be passed a function as
parameter.
If i declare the function as
int (void *, int, char **, char **)
it throws an error
cannot convert parameter from 'int (void *,int,char ** ,char ** )' to
'int (__cdecl *)(void *,int,char ** ,char ** )'

If the same function is moved out of the class or declared static
it works fine.
But i don't want the function to be declared static or moved out of the
class because i m using non static members of the class
I just mentioned the subject according to error.
Any solutions to this problem


As stated by others, you can't pass a member function where a non-member
function is required.

However, these callback mechanisms often provide a means to pass "user
data" when registering the callback which is then passed to your function
when called. I can't tell from your function signature (because the
argument names have been stripped), but the first "void*" parameter may be
such a thing. (Just guessing..) If so, use a static method, pass the
object you wish to use as the user data, and cast it back from the void*
in the callback to invoke a member function on that object.

HTH

- Jay

Jul 22 '05 #7

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

Similar topics

3
by: vinu_gt | last post by:
Hi All, I had a question about stdcall and cdecl calling convention related to Visual Studio 6.0 I have a console project and in Project->setting->C++->Code Generation The "calling...
1
by: Joannes Vermorel | last post by:
I am currently trying to port a small open source scientfic library written in C++ to .Net. The code (including the VS solution) could be found at http://www.vermorel.com/opensource/selfscaling.zip...
4
by: Brett | last post by:
Hi, I'm having trouble converting an old project to visual studio C++ .net v7.1.3088 I've updated one of the header files to use #include <iostream>, and used the std namspace. After...
13
by: kamaraj80 | last post by:
Hi I am using the std:: map as following. typedef struct _SeatRowCols { long nSeatRow; unsigned char ucSeatLetter; }SeatRowCols; typedef struct _NetData
5
by: kwijibo28 | last post by:
Hi all, I was wondering if there is a standard definition for the calling convention like __cdecl and __stdcall. I've search the c++ standard document and there is no mention of __cdecl or...
2
by: Pugal | last post by:
hi what is the difference between _stdcall and __cdecl, is the stack release issue much important.. and why other languages like java are not worrying about these things.. any idea.. -Pugal
0
by: Arne Adams | last post by:
Hi all, i have a managed c++ dll using both managed and unmanaged code and an unmanaged application that calls the unmanaged code of the managed dll. I did follow...
3
by: Rene | last post by:
Hello to all! For a long time I have been "fighting" a problem compiling an OpenGL program which uses GLUT. First I have put a question in a Watcom group (I want to use this compiler) to which I...
6
by: Ole Nielsby | last post by:
VC has a __cdecl specifier which allows functions and methods to be called with varying parameter count. (I understand this is the default for functions in general but in VC, instances use...
1
by: elke | last post by:
Hi, I want to use an unmanaged dll in C# .net and I'm having some troubles witch a function that should return an array. I'm new at this, so I don't know what I'm doing wrong. Here is some...
1
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...
0
isladogs
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.