Okay, here's how I did it:
1) Downloaded the Clootie graphics libs from
http://clootie.narod.ru/. I just
downloaded the C++ builder DX92 libs and DLLs files.
2) Placed the libs in my libs folder, placed the
DLLs (two of them) in the same folder as my program. Renamed d3dx92ab.dll
to d3dx9.dll (otherwise it complains).
4) At the bottom of d3d9.d, removed the block of
code with the "Direct3DInit()" and "Direct3DCreate9()" functions. Replaced
them with
extern (Windows) export
IDirect3D9 Direct3DCreate9(UINT SDKVersion);
6) Some functions, like D3DXCreateSprite(), already
have the "extern(Windows) export" in front of them. For these, I just had
to add a declaration in the .def file like for Direct3DCreate9.
7) Most functions, like D3DXCreateTexture(), have
definitions like the following:
HRESULT
function(
IDirect3DDevice9
pDevice,
UINT
Width,
UINT
Height,
UINT
MipLevels,
DWORD
Usage,
D3DFORMAT
Format,
D3DPOOL
Pool,
IDirect3DTexture9* ppTexture)
D3DXCreateTexture;
This simply defines a function pointer to be
used with GetProcAddress. Since we're importing the functions rather than
explicitly loading the DLL, the declaration needs to be changed
to:
extern(Windows)
export HRESULT D3DXCreateTexture(
IDirect3DDevice9
pDevice,
UINT
Width,
UINT
Height,
UINT
MipLevels,
DWORD
Usage,
D3DFORMAT
Format,
D3DPOOL
Pool,
IDirect3DTexture9*
ppTexture);
Then the appropriate declaration can be added
in the .def file. (This is why I asked how to call an unmangled function -
the functions in the directx libs are unmangled, and I can't seem to get the D
compiler to look for an unmangled C function. So we have to use the .def
file to translate.)
Then I just used the functions as in
C++.
I suppose it would be simpler to use
extern(C) instead, which would eliminate the need for the "@4" or whatever in
the .def file function definitions. But they still need the preceeding
underscore.
There have been several bindings to DirectX
and Direct3D before, but as far as I know, never to D3DX, simply because.. well,
it seems to be unusually difficult. There is still, AFAIK, no way to
statically link D3DX in anything but MS C++ compilers.
But oh well - MS itself said that it is going
to move D3DX out into a DLL in future versions of DX, so we're ahead of the
times, I guess ;)