I'm fairly certain this isn't possible from what I've read, and tried. Although for ease and continuity in code I would like to ask here.
Is it possible to export a function along with its namespace container?
For example:
namespace Continuity
{
int Foo(void);
}
Standard usage would be: Continuity::Foo();
I want to be able to export this function to use in a DLL, however I want to keep it in the namespace structure so that I can use the same usage in the DLL.
You asked:
Is it possible to export a function along with it's namespace container example:
Yes, it is possible.
Use:
namespace Continuity
{
DLL_EXPORT int Foo(void);
}
Where DLL_EXPORT
is #define
d to either __declspec(dllexport)
or __declspec(dllimport)
appropriately.
In the project where you build the DLL, you'll need:
#define DLL_EXPORT __declspec(dllexport)
In projects where you use the DLL, you'll need:
#define DLL_EXPORT __declspec(dllimport)
Make sure not to use extern "C" when declaring the function otherwise the namespace is not used for linking the function. You may then have 2 dlls with the same function in 2 different namespaces but only one function will be called randomly based on the order the functions are loaded.
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