473,757 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

exporting a C++ object in a DLL

I have a class that contains a std::map variable. I need to export the
class via a DLL. the class looks something like this:

class MyClass
{
public:
MyClass();
MyClass(const MyClass&);

private:
MyClass& operator=(const MyClass&);

typedef std::map<SomeKe y, SomethingElseTr easureChest ;

TreasureChest m_treasures;
};
Jul 1 '07 #1
15 7396
you can either __declspec(dlle xport) every member of the class that
you want to export, or __declspec(dlle xport) the class definition.

In the "dll user" code you should declare the class with
__declspec(dlli mport). There are standard ways to do that using
macros. See
http://www.codeproject.com/dll/SimpleDll2.asp

or
http://msdn2.microsoft.com/en-US/lib...4d(VS.80).aspx

Good Bye
QbProg

Jul 1 '07 #2


QbProg wrote:
you can either __declspec(dlle xport) every member of the class that
you want to export, or __declspec(dlle xport) the class definition.

In the "dll user" code you should declare the class with
__declspec(dlli mport). There are standard ways to do that using
macros. See
http://www.codeproject.com/dll/SimpleDll2.asp

or
http://msdn2.microsoft.com/en-US/lib...4d(VS.80).aspx

Good Bye
QbProg
See: http://support.microsoft.com/kb/168958

Relevant text: The only STL container that can currently be exported is
vector. The other containers (that is, map, set, queue, list, deque) all
contain nested classes and cannot be exported.

The article was last reviewed in September 2005 - I wanted to know if it
is now possible to export std::map from a DLL
Jul 2 '07 #3

"Grey Alien" <gr**@andromeda .comwrote in message
news:uY******** *************@b t.com...
>I have a class that contains a std::map variable. I need to export the
class via a DLL. the class looks something like this:
No you don't. Create an interface (class with pure virtual pointers),
derive the implementation from it, and share only the interface. You do
that by putting the interface definition in a public header file. No
__declspec(dlle xport) statement is needed.

Exporting C++ classes is very bad news. __declspec(dlle xport) should be
used only for 'extern "C"' functions.
>
class MyClass
{
public:
MyClass();
MyClass(const MyClass&);

private:
MyClass& operator=(const MyClass&);

typedef std::map<SomeKe y, SomethingElseTr easureChest ;

TreasureChest m_treasures;
};


Jul 2 '07 #4


Ben Voigt [C++ MVP] wrote:
"Grey Alien" <gr**@andromeda .comwrote in message
news:uY******** *************@b t.com...
>>I have a class that contains a std::map variable. I need to export the
class via a DLL. the class looks something like this:


No you don't.
Yes I do. I know what I want.

Create an interface (class with pure virtual pointers),
derive the implementation from it, and share only the interface. You do
that by putting the interface definition in a public header file. No
__declspec(dlle xport) statement is needed.
You are assuming that the DLL will be consumed by a C++ client. That is
not the case. Besides, how can you possibly use code in another
compilation unit if you don't link into it (either statically or
dynamically).?
>
Exporting C++ classes is very bad news. __declspec(dlle xport) should be
used only for 'extern "C"' functions.
Not necessarily true. In my case, I am taking care of the C++ "name
mangling" - through various policies and procedures (didn't include info
because it is orthogonal to my original question).
>
>>class MyClass
{
public:
MyClass();
MyClass(const MyClass&);

private:
MyClass& operator=(const MyClass&);

typedef std::map<SomeKe y, SomethingElseTr easureChest ;

TreasureChest m_treasures;
};



Jul 2 '07 #5
Grey Alien wrote:
You are assuming that the DLL will be consumed by a C++ client. That is
not the case. Besides, how can you possibly use code in another
compilation unit if you don't link into it (either statically or
dynamically).?
Grey:

You want to export a class containing an std::map and it will not be
consumed by a C++ client?

Ben's advice might have seemed a little fierce, but basically I agree
with it. You will save yourself a lot of future headaches if you design
your class with a pure virtual interface (and methods using simple types).

--
David Wilkinson
Visual C++ MVP
Jul 2 '07 #6


David Wilkinson wrote:
Grey Alien wrote:
>You are assuming that the DLL will be consumed by a C++ client. That
is not the case. Besides, how can you possibly use code in another
compilation unit if you don't link into it (either statically or
dynamically) .?


Grey:

You want to export a class containing an std::map and it will not be
consumed by a C++ client?

Ben's advice might have seemed a little fierce, but basically I agree
with it. You will save yourself a lot of future headaches if you design
your class with a pure virtual interface (and methods using simple types).
Dave:

That may be the case, but the fact remains that the class whose methods
are invoked needs to contain a map member variable. At the moment, I'm
getting this annoying warning:

warning C4251: 'theManager::m_ signalMap' : class 'std::map<_Kty, _Ty>'
needs to have dll-interface to be used by clients of class 'theManager'

- which seems to imply that std::map can be exported - which contradicts
the (outdated) article on the MSN site. So do I heed the warning and
export the data type (preferred) or do ignore it (with potentially
disastrous consequences)?
Jul 2 '07 #7
Never mind, I found the solution here:
http://caseys.kcfilms.com/2006/01/us...ross_dll_b.php
Jul 2 '07 #8

"Grey Alien" <gr**@andromeda .comwrote in message
news:1t******** *************** *******@bt.com. ..
>

Ben Voigt [C++ MVP] wrote:
>"Grey Alien" <gr**@andromeda .comwrote in message
news:uY******* **************@ bt.com...
>>>I have a class that contains a std::map variable. I need to export the
class via a DLL. the class looks something like this:


No you don't.

Yes I do. I know what I want.

Create an interface (class with pure virtual pointers),
>derive the implementation from it, and share only the interface. You do
that by putting the interface definition in a public header file. No
__declspec(dll export) statement is needed.

You are assuming that the DLL will be consumed by a C++ client. That is
not the case. Besides, how can you possibly use code in another
compilation unit if you don't link into it (either statically or
dynamically).?
If your client isn't C++, the prohibition on __declspec(dlle xport) of
classes becomes absolutely instead of just a really good idea.

What do you mean by "don't link into it"? You are creating a DLL, right?
"dynamicall y linked library" If you create an interface, then the compiler
links the interface v-table to the implementations . The client only needs
the interface definition.

Jul 4 '07 #9

"Grey Alien" <gr**@andromeda .comwrote in message
news:pK******** *************** *******@bt.com. ..
>

David Wilkinson wrote:
>Grey Alien wrote:
>>You are assuming that the DLL will be consumed by a C++ client. That is
not the case. Besides, how can you possibly use code in another
compilation unit if you don't link into it (either statically or
dynamically). ?


Grey:

You want to export a class containing an std::map and it will not be
consumed by a C++ client?

Ben's advice might have seemed a little fierce, but basically I agree
with it. You will save yourself a lot of future headaches if you design
your class with a pure virtual interface (and methods using simple
types).

Dave:

That may be the case, but the fact remains that the class whose methods
are invoked needs to contain a map member variable. At the moment, I'm
getting this annoying warning:

warning C4251: 'theManager::m_ signalMap' : class 'std::map<_Kty, _Ty>'
needs to have dll-interface to be used by clients of class 'theManager'
- which seems to imply that std::map can be exported - which contradicts
the (outdated) article on the MSN site. So do I heed the warning and
export the data type (preferred) or do ignore it (with potentially
disastrous consequences)?
There is no contradiction, both are correct. std::map should not be
exported, and because of that, it should not be used by clients of
"theManager ". Since it is a private implementation detail, why would that
present a problem? Clients aren't using it.

Jul 4 '07 #10

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

Similar topics

3
3966
by: chetan | last post by:
Hi , myself Chetan Is There anybody could help me ? I am working on the project in c++ ,, I am in great confusion that should I export c++ member functions OR methods to create objects of that class OR previously cretaed objects .. So those can be used by users by using the header file ... of my " class "
0
3366
by: Otis Hunter | last post by:
I have been fighting with this for days and your expert help is needed! Below is the code I am executing which results with "Object doesn't support this property or method". The error is occuring on the "With Me.OLEObject" line. I am trying to extract a Word document(OLE object) from an Access database, for each record in the table, and save it as a Word Document. The 4th field of each record is a OLE object type. I may be getting...
2
3476
by: Regnab | last post by:
I've got my code working so that it'll count the number of columns in the table and move across (eg Range A-P and then range Q-W). Problem is when I get to the end of the single letters and get into AA etc. Have got an idea of how I could do it by using Chr() and having an ongoing counter which is divided by 26 when it goes past Z to work out location. However, I'd dearly like there to be an easier way. Any ideas? Another problem I'm...
8
6993
by: chippy | last post by:
Hi, I've a VB script that creates a Access object in a word doc. Here is the full script. It works for all but the Export. Which always fails with a 3011 error. If I do the same in Access as a straight Macro or script it works. Add it as an object and it won't work. HELP.
4
6186
by: Hitesh | last post by:
Hi, I have three datagrid control on my aspx page and one export to excel button, i want to export all the 3 datagrids contents in one excel file. how can i achive that? -- Thanks Hitesh
2
2310
by: pmud | last post by:
Hi, I am exporting data from an EDITABLE DATA GRID EXCEL. But the 1st column in data grid is Edit Column. I want to display all columns in Excel except for the Edit column. The following code which I am using allows exporting only from text data from data grid & not from Edit columns which are link buttons. How to leave this column while displaying data from data grid in Excel?
6
9354
by: Steve Richter | last post by:
I am getting error in a vbscript: ActiveX component cant create object: Excel.Application. The vbscript code is: Dim objExcel Set objExcel = CreateObject("Excel.Application") I am pretty sure it is a permission issue because the script works when I point the browser directly at the .htm file on the c: drive: c:\inetpub\wwwroot\DemoSite\VbScriptTest.htm
2
2415
by: bienwell | last post by:
Hi, I have a question about exporting data from datagrid control into Excel file in ASP.NET. On my Web page, I have a linkbutton "Export data". This link will call a Sub Function to perform exporting ALL data from the datagrid control. Exporting data works fine when I show all data on the datagrid control. I'd like to shows only 30 records on the datagrid control instead of ALL data using page navigation, and perform exporting...
3
6510
by: Bilgehan.Balban | last post by:
Hi, My observation was that a function with `inline' qualifier has file scope in C++ and it's symbol is not exported. Contrary to this, in C an `inline' function symbol is exported, unless it also has `static' or `extern' qualifiers. How could I achieve the C behaviour in C++, in that an inline function symbol is exported? I see that one way to do it is declaring the function in a class definition in a header file so that all files
2
19315
by: atlbearcat | last post by:
Here's one that's been bugging me for about a week now... I have a form that allows users to filter records, simple enough. But I want to give them the option to export the filtered records to Excel. I don't want to use the docmd.outputTo due to it won't filter the records, it puts all of the records in the file. I've looked around and found some code (actually that I'm already using), but the problem is that it outputs EVERYTHING on the...
0
10069
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9904
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9735
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7285
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6556
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5324
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2697
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.