library.inc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. {
  2. Free Pascal port of the OpenPTC C++ library.
  3. Copyright (C) 2001-2003 Nikolay Nikolov ([email protected])
  4. Original C++ version by Glenn Fiedler ([email protected])
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. }
  17. Constructor TDirectXLibrary.Create;
  18. Var
  19. DirectDrawCreate : TDirectDrawCreate;
  20. IID_IDirectDraw2 : GUID;
  21. Begin
  22. { defaults }
  23. m_lpDD := Nil;
  24. m_lpDD2 := Nil;
  25. m_library := 0;
  26. Try
  27. LOG('loading ddraw.dll');
  28. m_library := LoadLibrary('ddraw.dll');
  29. If m_library = 0 Then
  30. Raise TPTCError.Create('could not load ddraw.dll');
  31. LOG('importing DirectDrawCreate');
  32. DirectDrawCreate := TDirectDrawCreate(GetProcAddress(m_library, 'DirectDrawCreate'));
  33. If DirectDrawCreate = Nil Then
  34. Raise TPTCError.Create('could not get address of DirectDrawCreate');
  35. LOG('creating lpDD');
  36. DirectXCheck(DirectDrawCreate(Nil, @m_lpDD, Nil));
  37. With IID_IDirectDraw2 Do
  38. Begin
  39. Data1 := $B3A6F3E0;
  40. Data2 := $2B43;
  41. Data3 := $11CF;
  42. Data4[0] := $A2;
  43. Data4[1] := $DE;
  44. Data4[2] := $00;
  45. Data4[3] := $AA;
  46. Data4[4] := $00;
  47. Data4[5] := $B9;
  48. Data4[6] := $33;
  49. Data4[7] := $56;
  50. End;
  51. LOG('querying lpDD2');
  52. DirectXCheck(m_lpDD^.lpVtbl^.QueryInterface(m_lpDD, @IID_IDirectDraw2, @m_lpDD2));
  53. Except
  54. On error : TPTCError Do
  55. Begin
  56. { close }
  57. close;
  58. { rethrow }
  59. Raise TPTCError.Create('could not initialize ddraw', error);
  60. End;
  61. End;
  62. End;
  63. Destructor TDirectXLibrary.Destroy;
  64. Begin
  65. close;
  66. Inherited Destroy;
  67. End;
  68. Procedure TDirectXLibrary.close;
  69. Begin
  70. If m_lpDD2 <> Nil Then
  71. Begin
  72. LOG('releasing lpDD2');
  73. m_lpDD2^.lpVtbl^.Release(m_lpDD2);
  74. m_lpDD2 := Nil;
  75. End;
  76. If m_lpDD <> Nil Then
  77. Begin
  78. LOG('releasing lpDD');
  79. m_lpDD^.lpVtbl^.Release(m_lpDD);
  80. m_lpDD := Nil;
  81. End;
  82. If m_library <> 0 Then
  83. Begin
  84. LOG('closing ddraw.dll');
  85. FreeLibrary(m_library);
  86. m_library := 0;
  87. End;
  88. End;