mr5
mr5

Reputation: 588

When to use __declspec(dllexport) in C++

I am making this DLL project and do not include any of compiler-specific macros.

The importer(.exe) files compiles clean and no error generated after importing methods in my DLL file. They are on different projects but same solution.

Do I mess up things here because of not using any of those calling convention?

My DLL files are in a namespace and implemented in OOP manner.

But sometimes or most of the times, the .lib does not generated so I got to switch the setting of my DLL to LIB and copy the generated .lib file and turn it back again to DLL file again.

And I don't even know if the library I am using is a .dll or .lib file.

Someone explains it to me clearly?

EDIT

I will add some situations where I am really confuse on when to use it.

suppose to be I have these:

namespace
{

    class Base abstract
    {

    public:
        Base()
        {
            //initialize base components
        }
        virtual void func() = 0;

    public:

        //interface
    };

    class Derive : public Base
    {

    public:
        Derive();
        void func() override;

    private:

        //interface

    };

}

Should I use declspec(dllexport) here:

I see on other header files, they add extern into it. Do I need it here?

This will ruin all of my code syntaxes

answers please....

Upvotes: 3

Views: 8150

Answers (1)

QuentinUK
QuentinUK

Reputation: 3077

It sounds as if you are linking in your library files that should be in the dll. So you are not using the dll's at all. Everything is going into the exe file.

Microsoft require the __declspec(dllexport) in the dll and __declspec(dllimport) in the exe. It gets complicated so there are macros to sort it out.

CLASS_DECLSPEC

The complier then sorts out which one of the __declspec's to use.

See:http://msdn.microsoft.com/en-us/library/8fskxacy(v=vs.80).aspx

Upvotes: 3

Related Questions