using the ARX wizard, Create DBX project and then add Custom Object(Just follow the "Setp 6-Custom Entities" in ObjectArx Tutorial).
the auto generated code:
///////
....
class DLLIMPEXP AsdkEmployee : public AcDbEllipse {
public:
ACRX_DECLARE_MEMBERS(AsdkEmployee) ;
protected:
static Adesk::UInt32 kCurrentVersionNumber ;
.....
////////
here i take the static variable kCurrentVersionNumber for example, if i want to obtain the value, I add a function getVersion() to return the value:
//////
static Adesk::UInt32 getVersion()
{
return kCurrentVersionNumber;
}
/////
Now, in another ARX project, I want to use the AsdkEmployee class in that DBX. first include the header file, add the lib dependency, invoke the static function:
///
int ver = AsdkEmployee::getVersion();
...
///
link error:
1>acrxEntryPoint.obj : error LNK2001: unresolved external symbol "protected: static unsigned long AsdkEmployee::kCurrentVersionNumber" (?kCurrentVersionNumber@AsdkEmployee@@1KA)
if i modify
#define DLLIMPEXP
into
#define DLLIMPEXP __declspec(dllimport)
build success
But see the comments:
#ifdef EMPLOYEE_MODULE
#define DLLIMPEXP __declspec(dllexport)
#else
//----- Note: we don't use __declspec(dllimport) here, because of the
//----- "local vtable" problem with msvc. If you use __declspec(dllimport),
//----- then, when a client dll does a new on the class, the object's
//----- vtable pointer points to a vtable allocated in that client
//----- dll. If the client dll then passes the object to another dll,
//----- and the client dll is then unloaded, the vtable becomes invalid
//----- and any virtual calls on the object will access invalid memory.
//-----
//----- By not using __declspec(dllimport), we guarantee that the
//----- vtable is allocated in the server dll during the ctor and the
//----- client dll does not overwrite the vtable pointer after calling
//----- the ctor. And, since we expect the server dll to remain in
//----- memory indefinitely, there is no problem with vtables unexpectedly
//----- going away.
#define DLLIMPEXP
#endif
Is there any mistake in the above steps? if i want to access STATIC variable from ARX project, what should i do?