Jump to content
  • Advertisement
Sign in to follow this  
stenny

Calling Conventions, I think

This topic is 3744 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey GDNet, I was programming with DLLs, tried to compile a release version, and errors popped up everywhere. Luckily I found it had to do with calling conventions (never heard of them before). However, just placing __cdecl (the default CC set up for my project) in front of all my functions doesn't work. The next error that's thrown up, is coming from this block of code:
#define NCOLOR DWORD
#define NCOLOR_ARGB(a, r, g, b) ((DWORD)( (((a)&0xff) << 24) | (((r)&0xff) << 16) | (((g)&0xff) << 8) | ((b)&0xff) ))

// given: NCOLOR m_clrClear in class ND3D
// class ND3D is in ND3D.dll, which is loaded using LoadLibrary

HRESULT __cdecl ND3D::SetClearColor(UINT nRed, UINT nGreen, UINT nBlue)
{
        // the following line throws up the error
        //  Access violation writing location 0x000000cc.
	m_clrClear	= D3DCOLOR_ARGB(255, nRed, nGreen, nBlue);

	return S_OK;
}


What's wrong? This error doesn't throw up when compiling for debug mode (Visual Studio c++ 2005 EE). Infact, whole the calling conventions problem doesn't pop up in debug mode. Can anyone help me out? /Stijn

Share this post


Link to post
Share on other sites
Advertisement
We need your exact compiler errors, both with and without the cdecl. "Errors popped up everywhere" is seriously lacking on the "useful and relevant detail" side.

Besides, what you have there is a member function, for which you should be ideally using __thiscall.

Share this post


Link to post
Share on other sites
Quote:
Original post by stenny
I was programming with DLLs, tried to compile a release version, and errors popped up everywhere. Luckily I found it had to do with calling conventions (never heard of them before).

This is very unlikely. Changing calling conventions probably just masked the real problem, or caused the compiler to generate other errors with higher priority. In 99.9% of all cases, you will never need to manually specify calling conventions when working with DLLs. Especially not on member functions. Unless you somehow want to interface with DLLs written in another language or generated by another compiler. Which is pretty much impossible anyway when using C++, due to name mangling and decoration.

It is much more likely that you haven't correctly used __declspec(dllimport), __declspec(dllexport) and maybe extern "C".

And of course, you have to actually post the errors you got...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!