Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Pointer auf Record (https://www.delphipraxis.net/96614-pointer-auf-record.html)

Gargamel 27. Jul 2007 13:30


Pointer auf Record
 
Hallo

Delphi-Quellcode:
PD3DCaps9 = ^TD3DCaps9;
  _D3DCAPS9 = record
    (* Device Info *)
    DeviceType: TD3DDevType;
    AdapterOrdinal: DWord;
    MaxTextureWidth, MaxTextureHeight: DWord;
End
Dazu gibt es noch einen Pointer

Delphi-Quellcode:
pd3dcaps : Pointer;      // pointer to the current D3DCAPS9

Wie komme ich jetzt an den Wert der Variable MaxTextureWidth?


Vielen Dank

mkinzler 27. Jul 2007 13:34

Re: Pointer auf Record
 
Ersetze dies mal durch

Delphi-Quellcode:
var pd3dcaps: PD3DCaps9;
...
p3dcaps^.MaxTextureWidth

Gargamel 27. Jul 2007 13:57

Re: Pointer auf Record
 
Vielen Dank. Leider funktioniert es nicht.
Sorry, ich hatte vergessen, folgendes zu erwähnen:

Ich kann nur so zugreifen

ev.pd3dcaps ( pd3dcaps ist vom Typ Pointer; ev ist eine Environment-Variable, welche alle nötigen Informationen enthält )

mkinzler 27. Jul 2007 14:02

Re: Pointer auf Record
 
Ich glaube nicht das as bei normalen pointern funktioniert. vielleicht mit Zuhilfenahme einer Hilfsvariablen:
Delphi-Quellcode:
var pd3dcaps: PD3DCaps9;
...
p3dcaps := ev.pd3dcaps;
p3dcaps^.MaxTextureWidth

sirius 27. Jul 2007 14:05

Re: Pointer auf Record
 
Keine Ahnung, was du da oben hast

Aber vielleicht so:
Delphi-Quellcode:
result:=DWORD(ppointer(cardinal(ev.pd3dcaps)+sizeof(TD3DDevType)+sizeof(DWORD))^);

Dax 27. Jul 2007 14:07

Re: Pointer auf Record
 
Delphi-Quellcode:
//Oder
PD3DCaps9(pd3dcaps)^.MaxTextureWidth

Oxmyx 27. Jul 2007 14:08

Re: Pointer auf Record
 
Ist das Problem lediglich, dass du einen untypisierten Zeiger hast? Dann geht es einfach mit
Delphi-Quellcode:
PD3DCaps9(pd3dcaps).MaxTextureWidth

Gargamel 27. Jul 2007 14:18

Re: Pointer auf Record
 
Ihr habt wirklich etwas "auf dem Kasten". Hat richtig prima funktioniert.

Vielen Dank

Gargamel 27. Jul 2007 14:36

Re: Pointer auf Record
 
Dadurch, dass ich jetzt darauf zugreifen kann, möchte ich logischerweise einige Informationen auslesen.
Bei MaxTextureWidth ist das relativ einfach.

Wie steht es aber mit TextureOpCaps?

DWORD TextureOpCaps; ( ist Bestandteil oben genannter Struktur )
Ich möchte also herausfinden, welche Texturoperationen mit der aktuell installierten Grafikkarte möglich sind.

Das steht dazu im MSDN:

TextureOpCaps
Combination of flags describing the texture operations supported by this device. The following flags are defined.

D3DTEXOPCAPS_ADD
The D3DTOP_ADD texture-blending operation is supported.
D3DTEXOPCAPS_ADDSIGNED
The D3DTOP_ADDSIGNED texture-blending operation is supported.
D3DTEXOPCAPS_ADDSIGNED2X
The D3DTOP_ADDSIGNED2X texture-blending operation is supported.
D3DTEXOPCAPS_ADDSMOOTH
The D3DTOP_ADDSMOOTH texture-blending operation is supported.
D3DTEXOPCAPS_BLENDCURRENTALPHA
The D3DTOP_BLENDCURRENTALPHA texture-blending operation is supported.
D3DTEXOPCAPS_BLENDDIFFUSEALPHA
The D3DTOP_BLENDDIFFUSEALPHA texture-blending operation is supported.
D3DTEXOPCAPS_BLENDFACTORALPHA
The D3DTOP_BLENDFACTORALPHA texture-blending operation is supported.
D3DTEXOPCAPS_BLENDTEXTUREALPHA
The D3DTOP_BLENDTEXTUREALPHA texture-blending operation is supported.
D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
The D3DTOP_BLENDTEXTUREALPHAPM texture-blending operation is supported.
D3DTEXOPCAPS_BUMPENVMAP
The D3DTOP_BUMPENVMAP texture-blending operation is supported.
D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
The D3DTOP_BUMPENVMAPLUMINANCE texture-blending operation is supported.
D3DTEXOPCAPS_DISABLE
The D3DTOP_DISABLE texture-blending operation is supported.
D3DTEXOPCAPS_DOTPRODUCT3
The D3DTOP_DOTPRODUCT3 texture-blending operation is supported.
D3DTEXOPCAPS_LERP
The D3DTOP_LERP texture-blending operation is supported.
D3DTEXOPCAPS_MODULATE
The D3DTOP_MODULATE texture-blending operation is supported.
D3DTEXOPCAPS_MODULATE2X
The D3DTOP_MODULATE2X texture-blending operation is supported.
D3DTEXOPCAPS_MODULATE4X
The D3DTOP_MODULATE4X texture-blending operation is supported.
D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
The D3DTOP_MODULATEALPHA_ADDCOLOR texture-blending operation is supported.
D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
The D3DTOP_MODULATECOLOR_ADDALPHA texture-blending operation is supported.
D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
The D3DTOP_MODULATEINVALPHA_ADDCOLOR texture-blending operation is supported.
D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
The D3DTOP_MODULATEINVCOLOR_ADDALPHA texture-blending operation is supported.
D3DTEXOPCAPS_MULTIPLYADD
The D3DTOP_MULTIPLYADD texture-blending operation is supported.
D3DTEXOPCAPS_PREMODULATE
The D3DTOP_PREMODULATE texture-blending operation is supported.
D3DTEXOPCAPS_SELECTARG1
The D3DTOP_SELECTARG1 texture-blending operation is supported.
D3DTEXOPCAPS_SELECTARG2
The D3DTOP_SELECTARG2 texture-blending operation is supported.
D3DTEXOPCAPS_SUBTRACT
The D3DTOP_SUBTRACT texture-blending operation is supported.

Sidorion 27. Jul 2007 15:48

Re: Pointer auf Record
 
Delphi-Quellcode:
If (<Konstante> And PD3DCaps9(pd3dcaps)^.TextureOpCaps = <Konstante>)..

Gargamel 27. Jul 2007 15:50

Re: Pointer auf Record
 
Ich habe es mittlerweile herausgefunden. Auf einem holländischen Forum ... :wall:


Trotzdem vielen Dank.

Noch eine kleine Frage zum Schluss: Gibt es eine Möglichkeit, den Namen der verwendeten Grafikkarte zu ermitteln?

markusj 27. Jul 2007 16:02

Re: Pointer auf Record
 
Mit Sicherheit, zum Bleistift über WMI. Ich habs zwar noch nie gemacht, aber dort gibt es eine Möglichkeit, alle Geräte aufzulisten, wenn ich mich nicht irre.

mfG
Markus

Muetze1 28. Jul 2007 14:54

Re: Pointer auf Record
 
wenn dir der Name vom Treiber reicht: schau dir das an Damit bekommste u.a. auch den Namen des angeschlossenen Monitors mit raus. (so lange er auch Windows bekannt ist)

Gargamel 28. Jul 2007 18:42

Re: Pointer auf Record
 
Hallo

Deinen Code habe ich in einer normalen VCL-Anwendung ausprobiert. Funktioniert einwandfrei.
Ich möchte aber den Code in einer DLL nutzen.

Der Monitorname wird korrekt übergeben. Allerdings beim Name der Grafikkarte kommt nicht viel.

Info.Devicename ist vom Typ array[0..31] of Char
Info.Devicestring vom Typ array[0..127] of Char

Ich muss ganz normale Strings zurückgeben.
Gibt es eine Lösung?


Vielen Dank

Muetze1 28. Jul 2007 19:54

Re: Pointer auf Record
 
Zitat:

Zitat von Gargamel
Info.Devicename ist vom Typ array[0..31] of Char
Info.Devicestring vom Typ array[0..127] of Char

Ich muss ganz normale Strings zurückgeben.
Gibt es eine Lösung?

Delphi-Quellcode:
Result := string(Info.DeviceString);
Du bist dir aber hoffentlich im klaren, dass dies in einer DLL Funktion wie Lotto spielen ist, da der String nur temporär ist und seine Gültigkeit mit verlassen der Funktion verliert?

Die reine Konvertierung habe ich dir ja aufgezeigt aber deine Stringübergabe von der DLL macht dir wohl eher einen Strich durch die Rechnung. Siehe dazu auch Luckie's Artikel

Gargamel 28. Jul 2007 20:21

Re: Pointer auf Record
 
Hallo

Die Stringübergabe aus der DLL heraus funktioniert. Ich habe schon einige Funktionen darin implementiert.
Deine Funktion habe ich soweit abgeändert, dass die gefundenen Werte global in einem Record gespeichert werden.

Hier ist der Quellcode:

Delphi-Quellcode:
// globale Variablen

rec_displaydevice = record
  DeviceName:string;
  DeviceString:string;
  Monitorname:String;
end;

var displaydevice:array[1..4] of rec_displaydevice;
var numberdisplaydevice:integer;


function get_NumberDisplayDevice:integer;
Var
  Cntr       : Cardinal;
  Info       : TDisplayDevice;
  AdapterName : PChar;
  OldPos     : Integer;
Const
  DISPLAY_DEVICE_ATTACHED_TO_DESKTOP = $00000001;
  DISPLAY_DEVICE_MULTI_DRIVER       = $00000002;
  DISPLAY_DEVICE_PRIMARY_DEVICE     = $00000004;
  DISPLAY_DEVICE_MIRRORING_DRIVER   = $00000008;
  DISPLAY_DEVICE_VGA                = $00000010;
Begin
  NumberDisplayDevice:=0;
  Cntr := 0;
  Info.cb := SizeOf(Info);

  While EnumDisplayDevices(Nil, Cntr, Info, 0) Do
  Begin
    NumberDisplayDevice:=NumberDisplayDevice+1;

    displaydevice[NumberDisplayDevice].DeviceName:=Info.DeviceName;
    displaydevice[NumberDisplayDevice].DeviceName:=Info.DeviceString;

    AdapterName := StrAlloc(SizeOf(Info.DeviceName));
    StrCopy(AdapterName, Info.DeviceName);
    EnumDisplayDevices(AdapterName, 0, Info, 0);


    displaydevice[NumberDisplayDevice].Monitorname:=Info.DeviceString;




    StrDispose(AdapterName);

    Inc(Cntr);
  End;

  result:=NumberDisplayDevice;
End;

Muetze1 28. Jul 2007 21:57

Re: Pointer auf Record
 
Bedeutet dies nun, dass die Probleme erledigt sind?

Gargamel 28. Jul 2007 22:05

Re: Pointer auf Record
 
Hallo

Leider nicht. Ich habe einen kleinen Test gemacht und die Werte in eine Textdatei geschrieben.
Da lief alles einwandfrei. Alle Werte sind absolut korrekt.

Nur ist die String-Übergabe über die DLL fehlerhaft. Andere Funktionen, die ebenfalls Strings übertragen,
funktionieren dagegen tadellos.

Keine Ahnung, wo da der Fehler liegt.

Muetze1 28. Jul 2007 22:16

Re: Pointer auf Record
 
Zitat:

Zitat von Gargamel
Keine Ahnung, wo da der Fehler liegt.

Ich denke, ich schon:

Delphi-Quellcode:
    displaydevice[NumberDisplayDevice].DeviceName:=Info.DeviceName;
    displaydevice[NumberDisplayDevice].DeviceName:=Info.DeviceString;  // <--- !!!

    AdapterName := StrAlloc(SizeOf(Info.DeviceName));
    StrCopy(AdapterName, Info.DeviceName);
    EnumDisplayDevices(AdapterName, 0, Info, 0);


    displaydevice[NumberDisplayDevice].Monitorname:=Info.DeviceString;
Dadurch wird der folgende Aufruf wegen EnumDisplayDevices für den Monitor falsch und dadurch kommt es zu weiteren Fehlern. Copy & Paste Fehler halt...

Gargamel 28. Jul 2007 22:30

Re: Pointer auf Record
 
Hallo

Die ersten 8 Zeichen werden dargestellt. Der Rest in "Müll".

Es wird angezeigt:

\\.\DISPpf
Radeon Xpf
Plug undpf

Hinter jeder der Zeilen sind noch 2 Zeichen in Form eines Rechtecks.

Muetze1 28. Jul 2007 22:48

Re: Pointer auf Record
 
Ok, und wie gibst du die in der o.g. Procedure ermittelten Array Inhalte zurück? Kannst du die entsprechende Funktion auch zeigen?

Gargamel 28. Jul 2007 23:35

Re: Pointer auf Record
 
Ich habe es geschafft.


Die Variablen im record habe ich von string in PChar geändert.

Delphi-Quellcode:
rec_displaydevice = record
  DeviceName:PChar;
  DeviceString:PChar;
  Monitorname:PChar;
end;

var displaydevice:array[1..4] of rec_displaydevice;

Das Kopieren in den Record geht jetzt so:

Delphi-Quellcode:
displaydevice[NumberDisplayDevice].DeviceName:=StrAlloc(32);
StrPCopy(displaydevice[NumberDisplayDevice].DeviceName,Info.DeviceName);

displaydevice[NumberDisplayDevice].DeviceString:=StrAlloc(128);
StrPCopy(displaydevice[NumberDisplayDevice].DeviceString,Info.DeviceString);

AdapterName := StrAlloc(SizeOf(Info.DeviceName));
StrCopy(AdapterName, Info.DeviceName);

EnumDisplayDevices(AdapterName, 0, Info, 0);

displaydevice[NumberDisplayDevice].Monitorname:=StrAlloc(128);
StrPCopy(displaydevice[NumberDisplayDevice].Monitorname,Info.DeviceString);

Ich kann nur hoffen, dass StrAlloc(32) bzw. StrAlloc(128) richtig ist, dadurch dass Info.DeviceName ein array[0..31] of Char bzw. Info.DeviceString ein array[0..127] of Char ist.


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:23 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz