__FUNCDNAME__ returns incorrect decorated function name

922 Views Asked by At

Function signature is:

void __stdcall Test(char *,int)

__FUNCDNAME__ macro used within function returns decorated function name:

  • real function name inside image: ?Test@@YGXPADH@Z
  • __FUNCDNAME__ returns: ?Test@@YGXPADH@Z

When /clr option is on (Project > Properties > General > Common Language Runtime Support > /clr) __FUNCDNAME__ macro doesn't return real decorated function name:

  • real function name inside image: ?Test@@YGXPADH@Z
  • __FUNCDNAME__ returns: ?Test@@$$FYGXPADH@Z __FUNCDNAME__ macro doesn't return real decorated function name.

This makes it impossible to use the #pragma comment directive to export function from DLL directly from the code without name decoration:

// .h
/*__declspec(dllexport)*/ void __stdcall Test(char *p1, int p2);

// .cpp
void __stdcall Test(char *p1, int p2)
{
    #pragma message("Exporting function " __FUNCTION__ " [" __FUNCDNAME__ "]")
    #pragma comment(linker, "/EXPORT:" __FUNCTION__ "=" __FUNCDNAME__)
}

Returns linker error LNK1242 '?Test@@$$FYGXPADH@Z' is an invalid export symbol name.

0

There are 0 best solutions below