473,394 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Exporting methods from a dll that uses namespaces

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 ?
Apr 4 '07 #1
3 5203
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
Apr 4 '07 #2


Doug Harrison [MVP] wrote:
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, I already sorted this out - it was actually being caused by a
'visibility' or 'scope' problem due to where the declspec macro was defined.

Your statements however, intrigue me... How would I explicitly
instantiate and export vector<string>? care to give an example ?

Also, what is the side effect (i.e. gotcha) if the DLL client
instantiates the exported data type itself (what am I missing?)
Apr 4 '07 #3
On Wed, 04 Apr 2007 17:38:51 +0100, "2b|!2b==?" <ro**@your.box.comwrote:
>Your statements however, intrigue me... How would I explicitly
instantiate and export vector<string>? care to give an example ?
See:

How to export an instantiation of a Standard Template Library (STL) class
and a class that contains a data member that is an STL object
http://support.microsoft.com/kb/168958
>Also, what is the side effect (i.e. gotcha) if the DLL client
instantiates the exported data type itself (what am I missing?)
As long as they're compiled with the same settings, probably nothing beyond
code duplication, which you experience every time you use an inline
function anyway. The primary danger lies in static data, which will be
duplicated in every module that instantiates the template.

--
Doug Harrison
Visual C++ MVP
Apr 4 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ron_Adam | last post by:
In looking at ways to reduce the size of exe's created with py2exe, I've noticed that it will include a whole library or module even if I only need one function or value from it. What I would...
6
by: Stijn | last post by:
Hi there, I have the following problem. At the moment I am creating an application that interfaces with several hardware modules via USB. Each of these devices has its own functionality and I...
8
by: Alfonso Morra | last post by:
I am familiar with creating lean and mean WIN32 DLLS and exporting C functions via a DEF file (or cconv decorators), but I am wndering how I can export my C++ objects from my DLLs? Ideally, I...
3
by: SAL | last post by:
I’m fairly new to .NET. I’ve been developing in .NET for about 6 months. I have over 10 years experience with VB in general. Here’s what I have done so far: 1. Project is entirely .NET...
11
by: Mark | last post by:
Is that true you can't have a static method in VB.NET? Public Static Sub Initialize() -- ??? thanks Mark
17
by: Geoff | last post by:
How do other things layer on to xml? I mean like dtd, wsdl, soap, etc.? Thanks. -g
12
by: 2b|!2b==? | last post by:
I want to export my C++ classes in a DLL, using ordinal # - rather than by name. Will anyone care to enumerate through the steps required to do this? I am already failiar with exporting classes...
8
by: paquer | last post by:
I'd like to provide an Export Function from my forms, where the User can choose the File name & save location Although I cannot get the "Save As" dialog box to open properly from access. What is...
7
by: =?Utf-8?B?Z2s=?= | last post by:
I wonder how to export a call in vba from unmanaged vc++ Usually i can export function ...with stdcall In vb.net I can do that with com class. I would like to instantiate an object from vba. ie...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.