The function in dll has the prototype below
void Foo(int arg1, int& arg2);
The question is, how to declare the function prototype in C?
Is the declaration legal?
void Foo(int, int*);
A DLL is a library that contains code and data that can be used by more than one program at the same time. For example, in Windows operating systems, the Comdlg32 DLL performs common dialog box related functions. Each program can use the functionality that is contained in this DLL to implement an Open dialog box.
Yes, it will work. Just make sure you reference the library in your c++ library and link them together. In some cases, this is not possible, e.g. if there is a considerable existing codebase written in C, that needs to be extended with new functionality (which is to be written in C++).
Is the declaration legal?
It is, but it doesn't declare the same function. If you need a C API, you cannot use a reference. Stick to a pointer, and make sure the function has C linkage:
extern "C" void Foo(int, int*) {
// Function body
}
If you cannot modify the DLL code, you need to write a C++ wrapper for it that exposes a proper C API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With