Converting simple C++ example to C, to use existing DLL
I'm attempting to use an existing .dll file from within my C code. My coworker who created this .dll has a simple example written in C++ that uses this file, which example code I'm able to use with no problems.
However, I'm now attempting to "translate" his C++ code for use in my own C code, and so far have been getting long lists of compiler errors (understandably) because I'm attempting to use his C++ syntax within my C file. After searching online & on this forum, I haven't yet encountered the information I need, in order to convert his C++ code into a C syntax that will compile.
This is his example code:
Code:
int a = 5, b = 2;
typedef int (*sumPointer)(int a, int b); // Shorthand to make other lines shorter
HINSTANCE dll; // Pointer to the .dll
sumPointer sum; // Pointer to "sum" function within the .dll
dll = LoadLibrary("RC.dll");
sum = (sumPointer)GetProcAddress(dll, "sum");
sum(a,b);
Once I can get this simple example working within my C code, I'll be able to apply this same principle to the real .dll & function calls that I need to use. (I'm aware that the comment indicators above need to be changed to C format, for starters.)
I appreciate any suggestions you have that will allow me to properly implement the above code in C. Thanks!
Additional info: Compiler errors
In case it's useful, I'll paste below the list of compiler errors I get, when I attempt to create a mex file using my current C code (with corrected comment indicators) and a related .lib file:
controller_CMEXsfcn.c(230) : error C2065: 'HINSTANCE' : undeclared identifier
controller_CMEXsfcn.c(230) : error C2146: syntax error : missing ';' before identifier 'dll'
controller_CMEXsfcn.c(230) : error C2065: 'dll' : undeclared identifier
controller_CMEXsfcn.c(231) : error C2275: 'sumPointer' : illegal use of this type as an expression
controller_CMEXsfcn.c(229) : see declaration of 'sumPointer'
controller_CMEXsfcn.c(231) : error C2146: syntax error : missing ';' before identifier 'sum'
controller_CMEXsfcn.c(231) : error C2065: 'sum' : undeclared identifier
controller_CMEXsfcn.c(233) : error C2065: 'dll' : undeclared identifier
controller_CMEXsfcn.c(233) : warning C4013: 'LoadLibrary' undefined; assuming extern returning int
controller_CMEXsfcn.c(234) : error C2065: 'sum' : undeclared identifier
controller_CMEXsfcn.c(234) : warning C4013: 'GetProcAddress' undefined; assuming extern returning int
controller_CMEXsfcn.c(234) : error C2065: 'dll' : undeclared identifier
controller_CMEXsfcn.c(234) : warning C4047: '=' : 'int' differs in levels of indirection from 'sumPointer'
controller_CMEXsfcn.c(236) : warning C4013: 'sum' undefined; assuming extern returning int