Exporting from a Static Library

Here's the situation: I'm using Visual C++ 6.0 on a Win32 Static Library Project.  I have a few classes inside it and one template class.  How would it be possible to export them all through the library? I've been researching for a couple days now but everything I found applied to dynamic libraries and not static libraries.  The template class which is used by one of the classes in the library is only needed for char type so only that version of it needs to be exported.  Also, is it possible to put these classes into a namespace?  I haven't really tried that yet but since I'm posting here, the best programming resource I've ever seen so far, I figure you guys would know already.
XerpherAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_corey_Commented:
You want it to compile the static lib in and not have the program auto-load the dll from compiling with the .lib?  Why don't you create a dll project and use the .lib it creates for you?

Also, the namespace problem can easily be solved by the header you use in the source from which you are calling the functions in the library.
0
efnCommented:
For the classes, there's not much to it.  You just have to build the library and set the client project to link it in.  You don't have to mess with __declspecs like you do with a DLL.

I don't think you can export a template, though.  You can wrap the one instantiation you need in another class, but for the client to use it as a template, the compiler will want to see the source code.  So you could export the template at the source level.

And yes, it should be possible to put the classes in a namespace.

--efn
0
XerpherAuthor Commented:
@ _corey_
  If I did that then I would need to send out the dll with the program, right? I don't want that.

@ efn
  So I need to make a big header file with all everything I want exported and put it in the program project?  So there's no solution without having to make a big header file?... and that template class is only needed for one of the classes inside the library, so how would I wrap the one instantiation I need in another class?
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

efnCommented:
> So I need to make a big header file with all everything I want exported and put it in the program project?  So there's no solution without having to make a big header file?

No, you don't have to make a big header file.  You do somehow have to get the classes you want to use declared in the software that will use them.  It's a good idea to use header files, because then you can have the declaration in just one place.  But if you want just to put the declarations in the client code, that will work, too--the compiler doesn't care, it's just worse for maintenance.  And you don't have to use one big header file for the whole library.  You can use multiple smaller files, such as one for each class.

>  and that template class is only needed for one of the classes inside the library, so how would I wrap the one instantiation I need in another class?

Declare a wrapper class in a header file that does not mention the template class.  Use the template class only in the implementation of the wrapper class.  The wrapper class can have the same interface and use the template class to implement it.

This will work if each function can temporarily conjure up a template object to do its job and then get rid of it.  However, you may need a more permanent template object corresponding to the wrapper object.  In this case, you can use the "pimpl idiom."  "pimpl" is short for "pointer to implementation."  The way it works is that you have two wrapper classes, say "Wrapper" and "WrapperImpl."  In the header file for Wrapper, you just declare WrapperImpl as a class, don't #include its header file.  Wrapper has all the interface functions and a private member that is a pointer to a WrapperImpl.  The Wrapper constructor dynamically allocates a WrapperImpl and saves its address in the pointer member.  All the functions of Wrapper just call corresponding functions in WrapperImpl to get their jobs done.

Then Wrapper has no reference to the template, so it can be exported from the library, and WrapperImpl, not being exported, can use the template freely, including having a template object as a member.

--efn
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
XerpherAuthor Commented:
So theres no way to use the classes in the lib without having to redeclare them in the project that uses the lib?  I guess thats more of what I was hoping for.

If not I'll try that "pimpl" you suggested.
0
efnCommented:
I'm not sure what you mean by "redeclare."  The compiler has to see a declaration of a class for code to use the class, whether you are using a library or not.  The usual approach is to have one header file that declares a class, included in both the client code and the class implementation code.

--efn
0
XerpherAuthor Commented:
Yea... by " without having to redeclare " I meant just link to the library and start using whats in it :-p

Alright, thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.