How to find the calling convention of a third party dll?
Could any one explain me how to get to know the calling convention of a dll without getting and processing method names? Lets say our application is loading a third party dll a开发者_如何学JAVAnd in order to handle it, is there any effective ways to get to know the calling convention of a dll? (__stdcall, __cdecl, __fastcall)
If the symbol begins with a _
but has no @
, then it's __cdecl
. If it begins with _
and has a @
it's __stdcall
. If it begins with @
and has another @
, it's __fastcall
.
source
While trying to figure out why I was getting unresolved symbols when linking against a third-party dll I stumbled upon a (sort of) programmatic solution.
I wrote a small program against the Windows API using UnDecorateSymbolName
from Dbghelp.h
to decode the mangling scheme:
#include "Windows.h"
#include "Dbghelp.h"
#include "tchar.h"
int _tmain(int argc, _TCHAR* argv[])
{
CHAR out[512];
UnDecorateSymbolName(
// Mangled symbol
"?OFFReader@IO@OpenMesh@@YGAAV_OFFReader_@12@XZ",
out,
// Length of symbol
46,
UNDNAME_32_BIT_DECODE);
}
There are definitely prettier ways to do it. I just run it in a debugger and look at the contents of out.
Also worth noting, contrary to Ignacio's answer, the difference between the mangled names for the cdecl
methods in the dll and the stdcall
methods being looked for was YAAAV
vs. YGAAV
.
精彩评论