Need help exporting std::string from dll 
Author Message
 Need help exporting std::string from dll

I am having trouble exporting std::string from a dll.  I have seen
solutions for exporting vector, but not for string, and I am missing the
similarity.  Any help here would be greatly appreciated.

Here is my example:

#define DLL_EXPORT
#ifdef DLL_EXPORT
#  define LIBSPEC __declspec(dllexport)
#else
#  ifdef DLL_IMPORT
#    define LIBSPEC __declspec(dllimport)
#  endif
#endif
#include <string>
using std::string;

class LIBSPEC Foo
{
public:
  Foo()                        {                  }
  Foo(const string& st)
    :
      myString(st)             {                  }

 ~Foo()                        {                  }

  const string& rep() const    { return myString; }

private:
  string myString;

Quote:
};

I get the following error:
E:\MyStuff\Developer Studio\myApps\stringDll\stringDll.cpp(26) : warning
C4251: 'myString' : class 'std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char>>' needs to have
dll-interface to be used by clients of class 'Foo'
Linking...
   Creating library Debug/stringDll.lib and object Debug/stringDll.exp

stringDll.dll - 0 error(s), 1 warning(s)



Fri, 27 Apr 2001 03:00:00 GMT  
 Need help exporting std::string from dll
Hi Jordan,

use a forward declaration for string to put it into your DLL ...

class __declspec(dllexport) std::string;



Sat, 28 Apr 2001 03:00:00 GMT  
 Need help exporting std::string from dll

Quote:

> I am having trouble exporting std::string from a dll.  I have seen
> solutions for exporting vector, but not for string, and I am missing the
> similarity.  Any help here would be greatly appreciated.

Check this page:
http://support.microsoft.com/support/kb/articles/q168/9/58.asp?FR=0

/Jonas U



Mon, 30 Apr 2001 03:00:00 GMT  
 Need help exporting std::string from dll
Joerg:
thanks very much for the reply.  When I use the forward declaration as
you suggest, I get the following error:

error C2242: typedef name cannot follow class/struct/union

Quote:

> Hi Jordan,

> use a forward declaration for string to put it into your DLL ...

> class __declspec(dllexport) std::string;



Tue, 08 May 2001 03:00:00 GMT  
 Need help exporting std::string from dll
Hi Jordan,

sorry for my misinformation. VC5 has changed here significantly.

See the MS way to export / import templates in xstring at the end.
The problem for class string is that it is not a class itself, just a
typedef. MS is "exporting" instanciated templates in VC6 now with a
proprietary syntax extension for forward declarations:

export template class __declspec(dllimport) class_name<template args>;

Compiling the class itself you have to insure by defines, that the dllimport
is defined to a dllexport.
As you can see the code, MS is exporting the string class (better:
basic_string<char, char_traits<char>, allocator<char> >) now from their own
libs, sou you have always to import this class.

Quote:

>Joerg:
>thanks very much for the reply.  When I use the forward declaration as
>you suggest, I get the following error:

>error C2242: typedef name cannot follow class/struct/union


>> Hi Jordan,

>> use a forward declaration for string to put it into your DLL ...

>> class __declspec(dllexport) std::string;



Sun, 20 May 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. problem using std::string in exported class to be puit in a DLL

2. How to export a std::string from a DLL

3. std::string and DLL exports

4. using std::string and vector in DLL exported class

5. using std::string in my dll-exported class

6. export classes using std namespace (ex std::vector) in a DLL

7. BUG?:cl.exe error when exporting std::string default param

8. Exporting a class CONTAINING an std::string

9. convert non std::string to std::string

10. help exporting stl::string from dll

11. Exporting STL containers (specifically std::map) from DLL?

12. Exporting MMC Snap-In objects from DLL, need help on project setup

 

 
Powered by phpBB® Forum Software