Ahem ... Let me clarify some things:
C # Interop allows you to use functions discovered by the classic Win32 libraries as if they were .NET methods. These DLLs are usually written in C.
You can also write Win32 libraries in C ++. This is exactly the same as writing a Win32 DLL in C, with the only difference being ...
C ++ compilers mangle function names, as opposed to C. The mangling name includes information about the function parameter and returns types in the function name, which makes function overloading possible. Unfortunately, this means that your pretty function names, such as BlockAll (and maybe not as pretty as AddIPAddressToBlockedList ), are converted to ugly (or ugly) things. You do not want to use a function called ?UnblockAll@ @YAXXZ , you?
The name mangling is compiler dependent. Thus, writing Win32 DLL files in C ++ is not a good idea if you are not going to use it only from an executable file (or another DLL) compiled with the same version of the same compiler (in this case, the compiler Microsoft C ++).
If you want to make your life simple, use C rather than C ++ to export functions to your .NET application. C ++ has a wonderful function, extern "C" , which tells the compiler that it treats your code as C code using a C link (no binding). This allows you to write C wrappers around your C ++ functions.
EDIT:
Another possibility that I completely forgot is to use C ++ Interop (yes, you can use C ++ to write a .NET shell around your Win32 DLL), and only then use C # to call your .NET shell. Beware, you should, however, because C ++ / CLI (a C ++ extension that allows the use of .NET-specific semantics) is very far-fetched.
source share