Einzelnen Beitrag anzeigen

Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.685 Beiträge
 
Delphi 11 Alexandria
 
#1

String und PChar frage

  Alt 21. Aug 2022, 09:51
Ich war auf der Suche nach einem Dialog der sich selbst schließen kann und bin hier im Forum auf das gestoßen:
Delphi-Quellcode:
const
  MB_TIMEDOUT = 32000;

function MessageBoxTimeOut(hWnd: HWND; lpText: PChar; lpCaption: PChar; uType: UINT; wLanguageId: WORD; dwMilliseconds: DWORD): Integer; stdcall; external user32 name {$IFDEF UNICODE}'MessageBoxTimeoutW'{$ELSE}'MessageBoxTimeoutA'{$ENDIF};
function MessageBoxTimeOutA(hWnd: HWND; lpText: PAnsiChar; lpCaption: PAnsiChar; uType: UINT; wLanguageId: WORD; dwMilliseconds: DWORD): Integer; stdcall; external user32 name 'MessageBoxTimeoutA';
function MessageBoxTimeOutW(hWnd: HWND; lpText: PWideChar; lpCaption: PWideChar; uType: UINT; wLanguageId: WORD; dwMilliseconds: DWORD): Integer; stdcall; external user32 name 'MessageBoxTimeoutW';
ein paar themen weiter hat himitsu das daraus gemacht:
Delphi-Quellcode:
const LibLang = {$IFDEF UNICODE}'W'{$ELSE}'A'{$ENDIF}; // wenn man das öfters mal braucht
function MessageBoxTimeOut(OwnerWindow: HWND; const Text, Caption: string;
  MType: LongWord; LanguageID: Word; Milliseconds: LongWord): Integer; stdcall;
  external user32 name 'MessageBoxTimeout' + LibLang;
function MessageBoxTimeOutA(OwnerWindow: HWND; const Text, Caption: AnsiString;
  MType: LongWord; LanguageID: Word; Milliseconds: LongWord): Integer; stdcall;
  external user32;
function MessageBoxTimeOutW(OwnerWindow: HWND; const Text, Caption: {$IFDEF UNICODE}UnicodeString{$ELSE}WideString{$ENDIF};
  MType: LongWord; LanguageID: Word; Milliseconds: LongWord): Integer; stdcall;
  external user32;
Ich frage mich an dieser Stelle warum es funktioniert das ein PChar mit einem string ausgetauscht werden kann.
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat