DirectX for Delphi 2-4

Latest update: Version 2.0xn (6-Sept-99)!

Version Changes:

Click here

Version 1.8 is the last release of the converted DirectX 5 units for Delphi 2, 3 and 4.
Version 2.0 is DirectX 6.0 for Delphi 2, 3, 4 and the new version 5.
You can download an adaption of Hori's DX 5 Media SDK units here.

I have completed the conversion of DirectMusic from DirectX 6.1
The rest of the DX-units will be updated to 6.1 during the next time
(there are verry few changes, but I have to go through all files, make updates,
remove the Delphi2 syntax and copy everthing from one API (like Direct3D) into one unit per API).

New file structure:

With the next point release, I will group all headers into one unit per API:
DirectDraw.pas  = DDraw.h + DVP.h + MultiMon.h
Direct3D.pas    = D3D.h + D3DTypes.h + D3DCaps.h
Direct3DRM.pas  = D3DRM.h + D3DRMDef.h + D3DRMObj.h + D3DRMWin.h + DXFile.h + RMXFGUID.h + RMXFTmpl.h
DirectInput.pas = DInput.h
DirectPlay.pas  = DPlay.h + DPLobby.h
DirectSound.pas = DSound.h
DirectMusic.pas = DLS1.h + DMDLS.h + DMError.h + DMKSCtrl.h + DMusicC.h + DMusicF.h + DMusicI.h
DirectSetup.pas = DSetup.h
Please e-mail me your opinions !

Known problems:


DInput and Delphi 2: I have made a workaround, which should solve the problems with D2's internal error(s).

Delphi 2 and 3/4 COM syntax:

In future versions (DX 6.1 and 7.0) I will not support Delphi2 COM-syntax anymore !


All units can be used with Delphi 2, 3 and 4. Because Delphi 3/4 has a new syntax for COM-interfaces, I have implemented a mechanism that allows you to choose between the old Delphi 2 and the new Delphi 3/4 COM-syntax. (See Delphi documentation for more information about COM-interfaces) If the compiler-symbol D2COM is defined in the file COMSWITCH.INC (included by all units), then the old syntax (which is compatible with Delphi 2 and 3/4) is used. Else you need Delphi 3 or 4 to compile the units. You can use the AddCOM and ReleaseCOM functions of DXTools for version-independent COM managment.

UNICODE and ANSI strings:

Some DirectX-objects can handle UNICODE and ANSI strings. The names of interfaces and records that use (PWideChar) UNICODE-strings end with a 'W' and their ( PAnsiChar) ANSI-pendants with an 'A'. You can select UNICODE as default stringtype by defining the compiler-symbol UNICODE in the file STRINGSWITCH.INC. If UNICODE is not defined, then ANSI is the default stringtype. The default stringtype is used, when you use interface and record-names that don't end with A or W. (In some cases that's different to the original headers, which use only 'Name' and 'NameA', where 'Name' is the UNICODE version)

Delphi look and feel typenames:

I have modyfied the names of records, enumerated-, and other types, so that they look like 'default Delphi' typenames.
Here is a list with representative examples:

 CDelphi
Record typesD3DCOLORVALUETD3DColorValue
Pointer typesLPD3DCOLORVALUEPD3DColorValue
Enumerated typesD3DLIGHTTYPETD3DLightType
Enumerated valuesD3DLIGHT_SPOTD3DLIGHT_SPOT *
ConstantsD3DENUMRET_OKD3DENUMRET_OK *
InterfacesLPDIRECTDRAW2IDirectDraw2
Procedural typesD3DVALIDATECALLBACKTD3DValidateCallback

* no changes

Parameters passed as pointer-types in the C-headers got converted to var/const-parameters, if nil won't be passed as value.
procedure foo(Arg: PRect)     // C-style
procedure foo(var Arg: TRect) // Pascal-style used in the conversion

Note that you have to pass the first field of an array in many cases where the C-version expects the address of a buffer !

Helper unit DXTools:

The unit DXTools gives you some useful tools that make DirectX-coding a little bit more handy. The procedure which you will use very often is DXCheck. It takes a HResult value returned by a DX-call as argument, and raises an exception with a short description of the error if necessary. DDCheck, D3DCheck, ... will do this only for a particular DirectX API. The procedure InitRecord fills a record with zero, and writes the recordsize into the first DWord. ReleaseCOM releases Delphi 2 and 3/4 COM-interfaces (and sets the pointer to nil), even when they are not initialised. ReleaseCOMe does the same, but raises an excepten if the interface is not initialised. DXTools has also some matrix-functions for 3D applications: ProjectionMatrix and ViewMatrix calculate homogenius-matrices for your virtual camera.

Copyrights and JEDI:

You may use the conversion like freeware :-)

I am a member of the JEDI-Project (a non-profit organisation that adapts Microsoft API's for Delphi), therefore these units are the official JEDI-DirectX API.

Contact me !

It would be great to get some feedback from you. Tell me what you think about the conversion, if there are problems and what could be done better.
Thanks in advance for your bug-reports :-)

My E-Mail address is: ungerik@bigfoot.com

Download:

You can download the files DirectX5.zip and DirectX6.zip (>100kB) from my Delphi Graphics Homepage

Credits:

I want to thank
Blake Stone for his initial DX3 conversion, which was the base for my first steps,
David Sisson for his generic conversions with PERL,
Hiroyuki Hori whose DX5 conversion was helpful in some cases,
Arne Schäpers,
the JEDI team and and many other guys for bug-reports and fixes.

Have fun,
         Erik Unger.