I’m writing a C/C++ DLL and want to export certain functions which I’ve done before using a .def file like this
LIBRARY 'MyLib' EXPORTS Foo Bar
with the code defined as this, for example:
int Foo(int a); void Bar(int foo);
However, what if I want to declare an overloaded method of Foo() like:
int Foo(int a, int b);
As the def file only has the function name and not the full prototype I can’t see how it would handle the overloaded functions. Do you just use the one entry and then specify which overloaded version you want when passing in the properly prototyped function pointer to LoadLibrary() ?
Edit: To be clear, this is on Windows using Visual Studio 2005
Edit: Marked the non-def (__declspec) method as the answer…I know this doesn’t actually solve the problem using def files as I wanted, but it seems that there is likely no (official) solution using def files. Will leave the question open, however, in case someone knows something we don’t have overloaded functions and def files.
In the code itself, mark the functions you want to export using __declspec(dllexport). For example:
If you do this, you do not need to list the functions in the .def file.
Alternatively, you may be able to use a default parameter value, like:
This assumes that there exists a value for b that you can use to indicate that it is unused. If -1 is a legal value for b, or if there isn’t or shouldn’t be a default, this won’t work.
Edit (Adam Haile): Corrected to use __declspec as __dllspec was not correct so I could mark this as the official answer…it was close enough.
Edit (Graeme): Oops – thanks for correcting my typo!