Cancelling _declspec(dllexport)
Just for simplification...
Code:
class _declspec(dllexport) Whatever
{
public:
int some_func1 ();
int some_func2 ();
int some_func3 ();
[...]
int some_func20 ();
private:
int some_var;
};
Using _declspec(dllexport) in the above way provides a convenient way to export all the functions in a class without needing to export them all individually but IIUC it exports everything - even some_var
Is there some convenient way to export a class's functions but to exclude its member variables?
Re: Cancelling _declspec(dllexport)
From https://docs.microsoft.com/en-us/cpp...?view=msvc-160
it says that "all its member functions and static data members are exported". So from this I'd take it that non-static member variables wouldn't be exported ???
Re: Cancelling _declspec(dllexport)
Ah, that might explain it.... In the actual code, the variable gets declared like this:-
Code:
static thread_local SharedPtr _tempo_map_p;
but apparently, a variable declared with thread_local isn't also allowed to have DLL linkage. I'll need to ask the original author if there's some reason why it needed to be static.
Re: Cancelling _declspec(dllexport)
An interesting problem... apparently anything using thread_local can be declared as either static or extern - but if it's a class member, it's only allowed to be static - and if the class itself is _declspec(dllexport) this results in it getting exported. But the catch 22 is that anything declared as thread_local in a DLL, isn't allowed to be exported!!!
So AFAICT the only option is to declare all the class members individually using _declspec(dllexport) but exclude this one :cry:
Presumably... declaring the whole class as _declspec(dllexport) exports everything (even private members?) It'd be nice if there's some way to exclude specific members (e.g. the private ones).
Re: Cancelling _declspec(dllexport)
Another idea... does VC++ support anonymous classes or structs (I've a feeling some compilers do). I'm just wondering if something like this could work...
Code:
class Whatever
{
protected:
// These two wouldn't get exported
static int some_var;
int some_func1 ();
class _declspec(dllexport) {
public:
// But these would get exported as members of class Whatever
int some_func2 ();
int some_func3 ();
}
};
Re: Cancelling _declspec(dllexport)
Have you tried it? I haven't done it this way before - but I gave up with .dlls some years ago!
PS. This compiles but with a warning re non-standard extension re nameless struct/union
Code:
class Whatever
{
public:
// These two wouldn't get exported
static int some_var;
int some_func1() { return 1; }
class _declspec(dllexport) {
public:
// But these would get exported as members of class Whatever
int some_func2() { return 2; }
int some_func3() { return 3; }
};
};
int main()
{
Whatever w;
w.some_func1();
//w.some_func2(); // Error - Not a member
}
This compiles OK:
Code:
class Whatever
{
public:
// These two wouldn't get exported
static int some_var;
int some_func1() { return 1; }
class _declspec(dllexport) {
public:
// But these would get exported as members of class Whatever
int some_func2() { return 2; }
int some_func3() { return 3; }
}exp;
};
int main()
{
Whatever w;
w.some_func1();
w.exp.some_func2();
}
Re: Cancelling _declspec(dllexport)
Many thanks 2kaud - I'm just shutting down for the night but I'll give that a try tomorrow!
Re: Cancelling _declspec(dllexport)
Yes you're right - the anonymous class needs to be instantiated, rather than just declared... how annoying!!
I don't know if their posts are public or private but I've flagged this up on the Microsoft Developer forum to see if they've got any ideas.
BTW - in a situation like this...
Code:
class Whatever
{
public:
__declspec(dllexport) Whatever();
__declspec(dllexport) ~Whatever();
__declspec(dllexport) int some_func1();
};
Is it strictly necessary to export the destructor (given that the user's code can't call it) ?