Re: export static public member

Tech-Archive recommends: Speed Up your PC by fixing your registry



On Wed, 3 Jan 2007 11:07:00 -0800, WJ <WJ@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

I have a class defined in project A, and I used AFX_EXT_CLASS to export them.

The AFX_EXT_CLASS macro has a major problem in that headers from multiple
DLLs cannot use it simultaneously. See this message for the proper way to
use __declspec(dllexport|dllimport):

http://groups.google.com/group/microsoft.public.dotnet.languages.vc/msg/9c40e8ab9410eeb1

This class also has some static public member variables.

In project B, I use this class and the public static member variables. I got
link error of unresolved externals of the static public member variables.

(I know public member is bad, but I am working on some old projects)

This works:

// Real code would use a macro instead of the __declspec

struct __declspec(dllexport) X
{
static int exported_int;
};

int X::exported_int;

*****

C>cl -LD a.cpp
C>dumpbin /exports a.dll

ordinal hint RVA name

1 0 00001000 ??4X@@QAEAAU0@ABU0@@Z
2 1 0000ACC0 ?exported_int@X@@2HA

What are you doing differently?

--
Doug Harrison
Visual C++ MVP
.



Relevant Pages

  • Re: Iterate through member variables of a class
    ... >> Is there a way to iterate through member variables of different names, ... > One thing I do know that's wrong is the public member variables in both ...
    (comp.lang.cpp)
  • Re: dlls need reregistration
    ... you immediately assumed that he was creating his DLLs ... > the DLLs could have been created in whatever language, ... make sure the compatible component is updated each time ... you add a new public member. ...
    (microsoft.public.vb.com)
  • Re: dlls need reregistration
    ... you immediately assumed that he was creating his DLLs ... > the DLLs could have been created in whatever language, ... make sure the compatible component is updated each time ... you add a new public member. ...
    (microsoft.public.vb.general.discussion)