Skip to main content
gamedev.net
🔒 Locked

callback problems

Started by eldee Sep 30, 2002 at 4:01 PM 4 replies 8k views
Original Post
eldee
eldee
C:\CPP\LineTest\CTess.cpp(41) : error C2664: 'gluTessCallback' : cannot convert parameter 3 from 'void (__cdecl *)(void)' to 'void (__stdcall *)(void)'
 
what exactly does that mean? i understand that it's unable to convert the 3rd parameter from what it is to what it should be.. but what is __cdecl * and __stdcall *? i've never messed with callback functions until today, so forgive my stupidity.. and this isnt my code btw- i ripped it right off of this tutorial the line of code it's hanging on is this: gluTessCallback(tobj, GLU_TESS_VERTEX, (GLvoid (*) ( )) &vertexCallback); check out the link above and you can see the code i'm using.. plus an explaination of what it's supposed to do. i've tried contacting the author but no reply. anybody know how i can fix it? -eldee ;another space monkey; [ Forced Evolution Studios ]

::evolve:: 'In C we had to code our own bugs. In C++ we can inherit them.' [edited by - eldee on September 30, 2002 8:38:35 PM]

Alpha_ProgDes
Alpha_ProgDes
quote:

Oluseyi how come this works:

int ( *Position::f )();
Position x;
f = x.abc();
f();

but not this:

int(*f)();

class is Position.

Position x;

(Position)(*f)()=x.abc();

just wondering.



the responses were:

quote:

Original post by Oluseyi

Alpha_ProgDes:
Because the signature of abc() is Position::abc(). Class members are different than non-class members (their calling convention is different - _thiscall vs _stdcall [C++] or _cdecl [C]).



...and...

quote:

Original Post by Fruny

C++ functions are ''cdecl'' just like C''s, Pascal''s (and Win32 API) are ''stdcall''. C++ only added the complication of name mangling. Of course, what you say is true of the member functions.



hope this helps any....
Beginner in Game Development?  Read here. And read here.  
Jan Wassenberg
Jan Wassenberg
Those specify calling convention (params pushed from right to left or the other way round, name mangling/decoration, who cleans up stack etc).

Declare your function with __stdcall.

HTH
Jan
E8 17 00 42 CE DC D2 DC E4 EA C4 40 CA DA C2 D8 CC 40 CA D0 E8 40E0 CA CA 96 5B B0 16 50 D7 D4 02 B2 02 86 E2 CD 21 58 48 79 F2 C3
eldee
eldee
okay, since i have no idea what i''m messing with here, i''ll just
naturally assume i''m doing something totaly wrong, but here is
my code:

  
void __stdcall CALLBACK vertexCallback(GLvoid *vertex)
{
GLdouble *ptr;

ptr = (GLdouble *) vertex;
glVertex3dv((GLdouble *) ptr);
glColor3dv((GLdouble *) ptr + 3);
}

int CTess::Init(GLvoid)
{
// Create a new tessellation object

tobj = gluNewTess();

// Set callback functions *** NOTE: i get errors on all 3 of these lines

gluTessCallback(tobj, GLU_TESS_VERTEX, (GLvoid (*) ( )) &vertexCallback);
gluTessCallback(tobj, GLU_TESS_BEGIN, (GLvoid (*) ( )) &glBegin);
gluTessCallback(tobj, GLU_TESS_END, (GLvoid (*) ( )) &glEnd);

return(1);
}


and the errors i get when trying to compile:
C:\CPP\LineTest\CTess.cpp(23) : error C2664: ''gluTessCallback'' : cannot convert parameter 3 from ''void (__cdecl *)(void)'' to ''void (__stdcall *)(void)''
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\CPP\LineTest\CTess.cpp(24) : error C2664: ''gluTessCallback'' : cannot convert parameter 3 from ''void (__cdecl *)(void)'' to ''void (__stdcall *)(void)''
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\CPP\LineTest\CTess.cpp(25) : error C2664: ''gluTessCallback'' : cannot convert parameter 3 from ''void (__cdecl *)(void)'' to ''void (__stdcall *)(void)''
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.
Creating browse info file...

TestBed.exe - 3 error(s), 0 warning(s)




-eldee
;another space monkey;
[ Forced Evolution Studios ]

::evolve::

''In C we had to code our own bugs. In C++ we can inherit them.''

Jan Wassenberg
Jan Wassenberg
1) CALLBACK is #defined as __stdcall, so one will do
2) you''re casting the function back to __cdecl in your gluTessCallback call. The cast should also include __stdcall: (GLvoid (__stdcall *) ()).
3) you sure you want glColor after glVertex?
E8 17 00 42 CE DC D2 DC E4 EA C4 40 CA DA C2 D8 CC 40 CA D0 E8 40E0 CA CA 96 5B B0 16 50 D7 D4 02 B2 02 86 E2 CD 21 58 48 79 F2 C3
Qw3r7yU10p!
Qw3r7yU10p!
Do you have to cast the function? I thought the function signature had to match the callback signature. That means you don''t have to cast anything.

I would assume that if it complains when you don''t cast then your callback function is the wrong signature.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.