In the third-party developer dll, the prototype of the function is described:

extern "C" void __stdcall AnyFunction ()

  1. I need to make it static, I try to fit it into the class, I get an error - error C2059: syntax error: 'string', without extern "C" accepts, how to be?
  2. How to register the implementation of the method outside the class declaration is also not working!

Code:

class clssMy{ public: extern "C" static void __stdcall AnyFunction(); }; 

    1 answer 1

    The extern "C" modifier cannot be used for class methods.

    This is because extern "C" requires a link that is compatible with C (that is, without name mangling), and class methods need "decorated" names.

    And why do you need extern "C" in the classroom? You should not need this.

    • AnyFunction () is a DLL callback function, the library is written in C, so I want to make it static and put it in a class. Is this possible? - rejie
    • No :( It is because of problems with names. But you can make a separate function, outside the class, and declare it with extern "C."
    • It's a shame ... - rejie
    • @rejie: ​​why is a separate function not suitable for you? - VladD
    • Fits, just wanted to encapsulate everything in the class! - rejie