www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Export static data

reply Dan <Dan.R.Stevens gmail.com> writes:
Is there a way to export static data from a DLL written in D?

I'd like to write some extension DLLs for a program, but they need to have
certain static data exports to be recognized. I've been able to export
functions, but no data appears in the export table of the DLL.

In MSVC 6 I can do it as follows:
extern "C" __declspec(dllexport) ModDesc DescBlock = { ... };


Another issue I had was with the name decoration. I need to be able to export
an "InitProc". The closest I was able to get was "_InitProc" and "INITPROC". Is
there a way to drop the leading underscore?
Aug 21 2009
parent reply Jarrett Billingsley <jarrett.billingsley gmail.com> writes:
On Fri, Aug 21, 2009 at 11:10 AM, Dan<Dan.R.Stevens gmail.com> wrote:
 Is there a way to export static data from a DLL written in D?

 I'd like to write some extension DLLs for a program, but they need to have
certain static data exports to be recognized. I've been able to export
functions, but no data appears in the export table of the DLL.

 In MSVC 6 I can do it as follows:
 extern "C" __declspec(dllexport) ModDesc DescBlock = { ... };
extern(C) export ModDesc DescBlock = { ... };
 Another issue I had was with the name decoration. I need to be able to export
an "InitProc". The closest I was able to get was "_InitProc" and "INITPROC". Is
there a way to drop the leading underscore?
As far as I know, not within the language. DMD for some reason thinks that all Windows functions are preceded by an underscore when that is clearly not the case. You might be able to do something using a .def file (linker script), but I've only had experience linking external symbols in, not with exporting internal symbols.
Aug 21 2009
next sibling parent div0 <div0 users.sourceforge.net> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jarrett Billingsley wrote:
 On Fri, Aug 21, 2009 at 11:10 AM, Dan<Dan.R.Stevens gmail.com> wrote:
 Is there a way to export static data from a DLL written in D?

 I'd like to write some extension DLLs for a program, but they need to have
certain static data exports to be recognized. I've been able to export
functions, but no data appears in the export table of the DLL.

 In MSVC 6 I can do it as follows:
 extern "C" __declspec(dllexport) ModDesc DescBlock = { ... };
extern(C) export ModDesc DescBlock = { ... };
 Another issue I had was with the name decoration. I need to be able to export
an "InitProc". The closest I was able to get was "_InitProc" and "INITPROC". Is
there a way to drop the leading underscore?
As far as I know, not within the language. DMD for some reason thinks that all Windows functions are preceded by an underscore when that is clearly not the case. You might be able to do something using a .def file (linker script), but I've only had experience linking external symbols in, not with exporting internal symbols.
Yeah just use a def file. This is start of def file I used to sort out a lib for opengl, put the name you want first and what you've got second ========= ; opengl32.dll has __stdcall functions but doesn't follow the std call ; name mangling convention. so we need to sort the mess out. LIBRARY opengl32 EXETYPE NT SUBSYSTEM WINDOWS EXPORTS _glAccum 8 = glAccum ========= Use the def file with implib to create a client .lib.
 implib name.lib name.def
http://www.digitalmars.com/ctg/implib.html - -- My enormous talent is exceeded only by my outrageous laziness. http://www.ssTk.co.uk -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iD8DBQFKjt3yT9LetA9XoXwRAg+DAKCYhzL/N5By2tJyaEUAubv6yVrwCACeK6Xh GaO49d0uEMZJJFg+Fm9C5ak= =3i5d -----END PGP SIGNATURE-----
Aug 21 2009
prev sibling parent Sergey Gromov <snake.scaly gmail.com> writes:
Fri, 21 Aug 2009 12:01:48 -0400, Jarrett Billingsley wrote:

 On Fri, Aug 21, 2009 at 11:10 AM, Dan<Dan.R.Stevens gmail.com> wrote:
 Another issue I had was with the name decoration. I need to be able
 to export an "InitProc". The closest I was able to get was
 "_InitProc" and "INITPROC". Is there a way to drop the leading
 underscore?
As far as I know, not within the language. DMD for some reason thinks that all Windows functions are preceded by an underscore when that is clearly not the case. You might be able to do something using a .def file (linker script), but I've only had experience linking external symbols in, not with exporting internal symbols.
All Windows functions are __stdcall, and that implies a name mangling scheme, _name SizeOfArguments. This is Microsoft's mangling scheme, it is respected in their .obj files and import libraries. But they decided not to follow it in system DLL exported symbol names for some reason. You overcome this peculiar design decision with .def files both with Microsoft toolchain and with DMD.
Aug 22 2009