Public Group

# 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.

## 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

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 on other sites
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 on other sites
Quote:
 Original post by stennyI 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...

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 12
• 18
• 10
• 14
• 10
• ### Forum Statistics

• Total Topics
632662
• Total Posts
3007702
• ### Who's Online (See full list)

There are no registered users currently online

×