On Wed, 04 Apr 2007 15:22:17 +0100, "2b|!2b==?" <ro**@your.box.comwrote:
>I have a C++ library partitioned by namespaces. I want to export some of
the functions in one of the namespace - how do I do it.
Assuming I have the macro MYAPI_EXPORTS #defined to be a declspec import
or export (as appropriate ...
This is what the lib looks like:
MyNamespace
{
//To be exposed
void Foo();
const std::vector<std::string>& Foobar(const std::string);
....
//Not to be exposed
int MyPrivateBit();
void YetAnotherPrivateBit();
....
};
where do I insert my macro MYAPI_EXPORT above, so I can export the
functions I want from the DLL ?
Unlike classes, you can't export namespaces, but you don't want to do that
anyway. You just need to put your macro at the start of the declarations
you do want to export, e.g.
MyNamespace
{
//To be exposed
MYAPI_EXPORT void Foo();
MYAPI_EXPORT const std::vector<std::string>& Foobar(const
std::string);
....
//Not to be exposed
int MyPrivateBit();
void YetAnotherPrivateBit();
....
};
Note that if you don't explicitly instantiate and export vector<string>,
the DLL client will instantiate it itself. (This may also apply to string,
except I think the DLL version of the C++ RTL exports it.) Also, Foobar
should probably take a const string& instead of a const string.
--
Doug Harrison
Visual C++ MVP