Extern function inside a class?

Gilles G. schaouette at free.fr
Sat Jun 23 02:55:03 PDT 2007


Hello,
I am writing a DLL using D. Iwould like to group the functions that I export together in a class which would also keep the data.
For example:
class DllManager
{
        this(){}
        ~this(){}
        invariant int dllVersion 1;
        MyObject[] objectList;
        extern(Windows) int GetDllVersion() { return dllVersion;}
        extern(Windows) int NewObject()
        {
                 objectList.length = objectList.length+1;
                 return objectList.length;
        }
}
But I wonder if this is possible, because there is no instance of the class DllManager available. What happens when the function NewObject is called by the main program?

I guess the good way to do this is:
class DllManager
{
        this(){}
        ~this(){}
        invariant int dllVersion 1;
        MyObject[] objectList;
        int GetDllVersion() { return dllVersion;}
        int NewObject()
        {
                 objectList.length = objectList.length+1;
                 return objectList.length;
        }
}
DllManager manager;
extern(Windows) int GetDllVersion() {return manager.getDllVersion(); }
extern(Windows) int NewObject() {return manager.NewObject();}

But it looks like I am forced to write all the external calls twice...

Anybody for a "cleaner" solution?
Thanks!



More information about the Digitalmars-d mailing list