DLLs and D

Matthew Allen mallen at creativelifestyles.com
Thu Feb 21 07:45:48 PST 2008


I am working on prototyping the conversion of my companies C++ assets to D language in order to break away from COM and make cross-platform complimation an easier process. I am currently working with Windows DLL and EXE.

I have a simple D DLL that has a class, two interfaces, and a class factory function. I am exporting the class factory function and the interfaces using the standard export keyword. I have an exe which attempts to create the class through the class factory function and casts the object to one of the interfaces. 

When I link the DLL to the exe it finds the definition for the class factory function but not the interfaces. My question is how do you link interfaces from a D DLL into a D Exe. Does anyone have an example of doing this or can someone point me in the right direction. My company would like to move to D and I need to get this working in order to do this.

I am creating a lib file from the DLL and linking statically to the EXE. I get a symbol undefined error for the IWindow interface.

Any help is really appreciated as the documention for creating DLL's is extremely limited and I have a small window of opportunity to get this working.

Example Code is below:

/*-----DLL Code Snippet------*/
module dllex;
export interface IWindow {
    int Create();
    int get_Window(out long hWnd);
}

export interface IHostWindowLite : IWindow {
    int get_Object(out Object HostedObject);
    int put_ObjectName(wchar* ObjectName);
    int get_ObjectName(wchar** ObjectName);

    int Control(long ParamID, long Param);
    int Inquire(long ParamID, out long Param);
}

class CHostWindowLite :
        public IWindow,
        public IHostWindowLite {
 ...
}

export Object getHostWindowLite(){
      return new CHostWindowLite();
}


/*----EXE Code Snippet----*/
import dllex;

Object obj = getHostWindowLite();
IWindow wnd = cast(IWindow) obj;
if(wnd)
       wnd.Create();



More information about the Digitalmars-d-learn mailing list