Jump to content
  • Advertisement
Sign in to follow this  

Exporting STL container from DLL compiler warning - should I worry?

This topic is 4844 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Right, I've got this compiling, exporting, being imported and used as a dll happily:
// most of SoundMetadata.h

class SOUNDDIRECTOR_API SoundMetadata
		typedef ::std::map<::std::string, ::std::string, ::std::less<::std::string> > SoundMetadata_MapType; 

		std::string fileName;
		std::string filePath;
		std::string error;

		std::string artist;
		std::string album;
		std::string title;
		std::string comment;	//stores comment as is, even after parsing
		std::string genre;
		std::string date;		//year
		unsigned int track;		
		std::string email;		//parsed from comment
		std::string website;	//parsed from comment

		SoundMetadata_MapType extendedMetaData;

		static std::string ToString(int val, unsigned short width = 0, char fill = ' ', std::ios::fmtflags flags = std::ios::fmtflags(0) );
		static std::string ExtractPath(const std::string filename);
		static std::string ExtractFileName(const std::string filename);
		static std::string ExtractExtension(const std::string filename);

		const static SoundMetadata EmptySoundMetadata;


		std::string		GetFileName() const {return fileName;};		
		std::string		GetFileExtension() const {return ExtractExtension(fileName);};		
		std::string		GetFilePath() const	{return filePath;} ;
		std::string		GetFullFilePath() const	;

		std::string		GetError() const	{return error;} ;
		std::string		GetArtist() const {return artist;};		
		std::string		GetAlbum() const	{return album;} ;
		std::string		GetTitle() const	{return title;} ;
		std::string		GetComment() const	{return comment;} ;	//Raw unparsed comment
		std::string		GetGenre() const	{return genre;} ;
		std::string		GetDate() const		{return date;} ;
		unsigned int	GetTrack() const	{return track;} ;
		std::string		GetEmail() const	{return email;} ;
		std::string		GetWebsite() const	{return website;} ;

		void SetFileName(std::string fileName) {this->fileName = fileName;};		
		void SetFilePath(std::string filePath) {this->filePath = filePath;} ;
		void SetFullFilePath(std::string fullFilePath);

		void SetError(std::string error) {this->error = error;} ;

		void SetArtist(std::string artist) {this->artist = artist;};		
		void SetAlbum(std::string album) {this->album = album;} ;
		void SetTitle(std::string title) {this->title = title;} ;

		//Raw unparsed comment.  Parses as set.
		//Parse email and website from comment in to this object instance
		//	.:(KEY):. [(VALUE)]  
		void SetComment(std::string comment) ;

		void SetGenre(std::string genre) {this->genre = genre;} ;
		void SetDate(std::string date) {this->date = date;} ;
		void SetTrack(unsigned int track) {this->track = track;} ;
		void SetEmail(std::string email) {this->email = email;} ;
		void SetWebsite(std::string website) {this->website = website;} ;

		void Clear(void)


		void ParseComment();
		void SetCommentPair(std::string key, std::string value);

Now that "SoundMetadata_MapType extendedMetaData;" bit is what is causing: "...SoundDirector\include\SoundMetaData.h(37): warning C4251: 'pde::SoundMetadata::extendedMetaData' : class 'std::map<_Kty,_Ty,_Pr>' needs to have dll-interface to be used by clients of class 'pde::SoundMetadata' with [ _Kty=std::string, _Ty=std::string, _Pr=std::less<std::string> ] " It is a private member so not used directly by anyone on the outside of the class anyway. http://support.microsoft.com/kb/168958/EN-US/ reckons you cannot export map classes. I've not come across any problems using it, but I'm guessing that could be a fluke. Is the only way to use a map to abstract one further and only export an interface type abstract class, and hide away usage of the map in an unexported class? [edit] Well the map bit actually isn't being used yet, which is probably why it is working happily [rolleyes]. Still I would be interested in knowing if you do have to hide away stl collections away from exported classes in a dll. [Edited by - paulecoyote on August 10, 2005 2:24:15 PM]

Share this post

Link to post
Share on other sites
Still I would be interested in knowing if you do have to hide away stl collections away from exported classes in a dll.

Might be the most sensible way to do it. The biggest problem, as I see it, (beyond the technical problem of flagging the nested classes as exported, as indicated in the KB article), is that the DLL can evolve independently from the program that links to it. Eventually, they may end up being compiled with incompatible settings, or incompatible versions of the standard library.

Which really means that the client code should only manipulate the maps through functions in the DLL, with the map being hidden behind an 'opaque pointer type' (like all thoses handles and that DX stuff - note how you get a pointer to some data structure, but mostly (exclusively?) use C-style non-member functions?): a type that is declared, but undefined, in the headers associated with the DLL, and to and from which you internally cast your map pointers.

Fugly? Yes. But the whole DLL shebang was designed for C, not really for C++.

Share this post

Link to post
Share on other sites
I've run into the same problem myself, but it's not really a problem - it's just an annoying message. The code gets compiled and put into the dll. Now the map is a private member, so their functions cannot be used by any classes outside or inheriting from the SoundMetadata class. I've done this before and it has worked well all the time :)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!