Archived

This topic is now archived and is closed to further replies.

eldee

callback problems

Recommended Posts

eldee    122
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]

Share this post


Link to post
Share on other sites
Alpha_ProgDes    6936
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....

Share this post


Link to post
Share on other sites
eldee    122
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.''

Share this post


Link to post
Share on other sites
Jan Wassenberg    999
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?

Share this post


Link to post
Share on other sites
petewood    819
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.

Share this post


Link to post
Share on other sites