How to use the same DLL in interact. session and in the code

Dear Rooters,

Probably my question is simple and I am sure that a good solution exist.
Windows XP and MVS 2005 are used with ROOT 5.12.0.
I create a dll library (libevents.dll) as it described and can load it from the interactive session using
gSystem->Load(“libevents.dll”) and use my class from it.
Now I want to create a stand-alone code using the class existing in libevents.dll to read the same data. Previosly using MVS 2003 I changed project to create the static library and linked it with the main code. It was not suitable but it worked. Now it works also but the size of the static library is huge. It is approximately in 10 times greater then it was with MVS 2003. Also when I change project DLL->LIB information about additional libraries is lost and it must be restored if I return project to DLL production. If I export the names from DLL by the standard way then it probably will not loaded from the interactive session.

Thus is it possible creating of the DLL library in one project that it will be used in the interactive session and will be loaded with stand-alone code. Or what you may recommend.

Thanks in advance,
Andrey

Hi Andrey,

When you build the dll (libevents.dll), a lib file is also created (libevents.lib). You have to link your application with this lib file.

Cheers,
Bertrand.

Hi Bertrand,

If I create DLL for the ROOT session then project probably does not export any names. In fact the LIB file is created but it does not help for the stand-alone code. It was included but linker does not resolve external class names presented in DLL and which could be used in the ROOT session.

Probably I must modify the MVS project but I do not know how.

Sincerely Yours,
Andrey

Hi Andrey,

Well, if it is a MSVC project, you have to explicitly define the exported symbols with __declspec( dllexport ). See MSVC doc :

You can declare C++ classes with the dllimport or dllexport attribute. These forms imply that the entire class is imported or exported. Classes exported this way are called exportable classes.

The following example defines an exportable class. All its member functions and static data are exported:

#define DllExport   __declspec( dllexport )

class DllExport C
{
   int i;
   virtual int func( void )
   { return 1; }
};

Note that explicit use of the dllimport and dllexport attributes on members of an exportable class is prohibited.

Then symbols will be resolved (exported in libevents.lib) and still accesible through gSystem->Load(“libevents.dll”)

Cheers,
Bertrand.

Hi Bertrand,

I wrote that DLL must be used in stand-alone code and in the ROOT dialog session. It means, your example must be modified as

#define DllExport __declspec( dllexport )

class DllExport C
{
int i;
virtual int func( void )
{ return 1; }
ClassDef(C,0)
};

and add linkdef.h header as usual

#ifdef CINT
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;

#pragma link C++ class C;

#endif

After that the command

rootcint -f Cdef.cpp -c C.h linkdefC.h

end with error:

link requested for unknown class C linkdefC.h(6)

If DLLexport is excluded from the class definition rootcint works without error.

Sincerely Yours,
Andrey

Hi Bertrand,

Fortunately, I checked a simple modification of your example and it works.

The example was changed as

#define DllExport __declspec( dllexport )

#ifdef CINT
class C
#else
class DllExport C
#endif
{
int i;
virtual int func( void )
{ return 1; }
ClassDef(C,0)
};

I applied the same modification to my code and it works.

Many thanks to you,
Andrey

Hi Andrey,

More generic (and cleaner) solution:

#ifdef CINT
#define DllExport
#else
#define DllExport __declspec( dllexport )
#endif

class DllExport C
{
int i;
virtual int func( void )
{ return 1; }
ClassDef(C,0)
};

class DllExport C2
{
int i;
virtual int func( void )
{ return 2; }
ClassDef(C2,0)
};

Cheers,
Bertrand.

Hi Bertrand,

You are surely right. It is more obvious example.

Sincerely Yours,
Andrey