If you need to call a C ++ subroutine from C code, then for a C ++ subroutine you must have a "C" link, which is executed by marking the function as extern "C" . This needs to be done on the C ++ side.
Put the following prototypes for Inp32() and Outp32() if you can change existing C ++ code. This should be in the header, which included any calls or defined the functions Inp32() or Outp32() - whether it be C or C ++ code:
#ifdef __cplusplus extern "C" { #endif short _stdcall Inp32(short PortAddress); void _stdcall Out32(short PortAddress, short data); #ifdef __cplusplus } #endif
This will mean that these functions have a C calling convention, and these functions will be called using C or C ++ code.
If you cannot change the code in C ++, you can create your own C-compatible wrappers for C ++ functions in your own C ++ module:
Header wrappers.h file:
// in wrappers.h // C-callable wrappers
And, implementation of wrappers.cpp:
// in wrappers.cpp file:
Now your C code can #include "wrappers.h" and call wrapper functions that simply call existing C ++ functions to do the job.
source share