www.digitalmars.com         C & C++   DMDScript  

D - More DLL questions

reply "Matthew Wilson" <dmd synesis.com.au> writes:
I'm wondering about the feasibility of creating small tight DLLs in D, and
am a bit surprised that a do-nothing DLL is 64KB.

I've messed around and basically wonder why the following, when compiled and
linked, doesn't form a recognisable Win32 DLL (regsvr32.exe complains
miserably).

  import windows;

  extern(Windows) BOOL DllMain(HINSTANCE hinst, ULONG reason, LPVOID
reserved)
  {
   return true;
  }

  extern(Windows) uint DllRegisterServer()
  {
   return 0;
  }

Any explanation gratefully received.

When I put in a call to gc_init on process-attach, it registers fine, not to
mention creating a Win32 DLL that is recognisable by the OS. I'm interested
in creating function only DLLs, and where no GC is required I don't want to
link in 60+KB. Any chance of this?

Thanks (and apologies if any of these questions are dumb or repeating
well-discussed issues covered in the last six months)

Matthew
Mar 14 2003
parent reply Burton Radons <loth users.sourceforge.net> writes:
Here's what I have.  The .d file is:

     import windows;

     extern(C) uint _acrtused_dll = (uint) &DllMain;

     extern(Windows) BOOL DllMain(HINSTANCE hinst, ULONG reason, LPVOID 
reserved)
     {
         return true;
     }

     extern(Windows) uint DllRegisterServer()
     {
         return 0;
     }

     extern(C)
     int foobar()
     {
         return 450;
     }

The .def file is:

     LIBRARY dll
     DESCRIPTION 'BLAH BLAH'
     EXETYPE NT
     CODE PRELOAD DISCARDABLE
     DATA PRELOAD SINGLE

     EXPORTS
     DllMain
     foobar

And the test file is:

     import windows;

     extern(C) int function() foobar;

     int main()
     {
         HANDLE library = LoadLibraryA("dll.dll");

         printf("Library %d\n", library);
         *(void**) &foobar = GetProcAddress(library, "foobar");
         printf("calling\n");
         int result = foobar();
         printf("done %d\n", result);
         return 0;
     }

The DLL produced is 3,100 bytes, and appears to be working properly.
Mar 14 2003
next sibling parent Deja Augustine <Deja_member pathlink.com> writes:
I may have missed it in the docs, but is there any way to redirect the path that
the .dll is written to?

For .exe files you can do:  
D:\dmd\bin>dmd.exe d:\input\codefile.d d:\output\executable.exe
and it'll write the executable to the path given.

I haven't been able to figure out how to redirect .dlls.

-Deja
Mar 15 2003
prev sibling parent "Matthew Wilson" <dmd synesis.com.au> writes:
Thanks Burton.

From your example, it seems that the only thing I needed to what I had was
the __acrtused_dll decl/assignment. Obviously this is needed by the compiler
or the linker to ensure that the image is generated correctly.

3100 bytes; happy me. :)

Matthew

"Burton Radons" <loth users.sourceforge.net> wrote in message
news:b4um9s$106m$1 digitaldaemon.com...
 Here's what I have.  The .d file is:

      import windows;

      extern(C) uint _acrtused_dll = (uint) &DllMain;

      extern(Windows) BOOL DllMain(HINSTANCE hinst, ULONG reason, LPVOID
 reserved)
      {
          return true;
      }

      extern(Windows) uint DllRegisterServer()
      {
          return 0;
      }

      extern(C)
      int foobar()
      {
          return 450;
      }

 The .def file is:

      LIBRARY dll
      DESCRIPTION 'BLAH BLAH'
      EXETYPE NT
      CODE PRELOAD DISCARDABLE
      DATA PRELOAD SINGLE

      EXPORTS
      DllMain
      foobar

 And the test file is:

      import windows;

      extern(C) int function() foobar;

      int main()
      {
          HANDLE library = LoadLibraryA("dll.dll");

          printf("Library %d\n", library);
          *(void**) &foobar = GetProcAddress(library, "foobar");
          printf("calling\n");
          int result = foobar();
          printf("done %d\n", result);
          return 0;
      }

 The DLL produced is 3,100 bytes, and appears to be working properly.
Mar 15 2003