Stdcall over-ride visual studio?

In xp 32bit, this line does not compile with the problem, but in Vista with a 64-bit line:

m_FuncAddr = ::GetProcAddress (somthing); 

gives the following error:

error C2440: '=': cannot convert from 'FARPROC' to 'int (__cdecl *) (void)'

GetProcAddress is defined as

 WINBASEAPI FARPROC WINAPI GetProcAddress (somthing) 

And m_FuncAddr like

 int (WINAPI *m_FuncAddr)(); 

From what I understand, both are stdcall's.

To avoid a mistake, I had to put

 m_FuncAddr = (int (__cdecl *)(void))::GetProcAddress(somthing); 

My question is:

If both m_FuncAddr and GetProcAddress have an agreement to call stdcall, why should I "revoke" it with cdecl?

Is it possible that the VS project parameter "default calling convention (which is set in cdecl) exceeded the assignment statute above?

Thanks in advance!

[change]

Clergy question:

On one side of the equation (say, side 1) we have

 int __stdcall * m_FuncAddr 

On the other hand (side 2)

 INT_PTR far __stdcall GetProcAddress 

So, how is it that I should throw side 2 with cdecl if both are stdcalls? Or am I not getting anything?

+4
source share
2 answers

The return type must be INT_PTR (64-bit value in 64-bit strings). You should not throw this error - the compiler is trying to tell you that something is wrong.

From WinDef.h:

 #ifdef _WIN64 typedef INT_PTR (FAR WINAPI *FARPROC)(); 

So the m_FuncAddr declaration should be:

 INT_PTR (WINAPI *m_FuncAddr)(); 
+3
source

It is a coincidence that it compiles correctly in 32 bits; correct syntax:

 typedef int (WINAPI *FFuncType)(); FFuncType m_FuncAddr; m_FuncAddr = (FFuncType)::GetProcAddress (somthing); 

You need to explicitly pass the result :: GetProcAddress to the corresponding function signature. In 32-bit mode, FARPROC works with your signature, but probably not on the 64-bit version.

Edit: Yes, actually, looking at windef.h, the return type is INT_PTR on a 64-bit basis, so you got a compiler error. You will still need to point to the signature of the function, as described above, for any function that does not match the match with FARPROC, so you must do this as described above.

+2
source

All Articles