Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi from ANSI_STRING to PAnsichar (https://www.delphipraxis.net/142261-ansi_string-pansichar.html)

mohfa 24. Okt 2009 20:46


from ANSI_STRING to PAnsichar
 
if i've this ANSI_STRING type :
Delphi-Quellcode:
type
PANSI_STRING = ^ANSI_STRING;
  ANSI_STRING = record
    Length: Word;
    MaximumLength: Word;
    Buffer: PAnsiChar;
  end;
How could i pass its Value ( ANSI_STRING ) to a PAnsiChar ?

thank you

mkinzler 24. Okt 2009 20:48

Re: from ANSI_STRING to PAnsichar
 
Use Buffer

mohfa 24. Okt 2009 21:08

Re: from ANSI_STRING to PAnsichar
 
But how about the Length and MaximumLength ?

himitsu 24. Okt 2009 21:09

Re: from ANSI_STRING to PAnsichar
 
ANSI_STRING to String/PChar
Delphi-Quellcode:
var A: PANSI_STRING;
  S: AnsiString;
  P: PAnsiChar;

SetString(S, A.Buffer, A.Length);

P := PAnsiChar(S);
ANSI_STRING are not terminated with #0


[add]
Length = current length of the string
MaximumLength = maximum size of the buffer

see at MSDN-Library durchsuchenANSI_STRING

mohfa 25. Okt 2009 14:03

Re: from ANSI_STRING to PAnsichar
 
Thank you himitsu . i think i'm confused here :

What i wanted is :

i use the ANSI_STRING in a C project declared as follows :

Code:
typedef struct _SCANNER_REPLY {

       BOOLEAN SafeToOpen;
       ANSI_STRING FileName;
} SCANNER_REPLY, *PSCANNER_REPLY;
Only to print out the Current FileName exmp : c:\mytextfile.txt

so the result in c :
Code:
NTSTATUS status;
SCANNER_REPLY replyMessage;
status = RtlUnicodeStringToAnsiString(&replyMessage.FileName, &FileI->Name, TRUE);
   
   if (NT_SUCCESS( status )) {
        DbgPrint("Current File: %s\n", replyMessage.FileName.Buffer);
/*
 this will Print Out the Current FileName ** Current File: \Device\HarddiskVolume1\myfile.txt **
*/
        RtlFreeAnsiString(&replyMessage.FileName);
      }
and in Delphi i declared as follows :
Delphi-Quellcode:
_SCANNER_REPLY = record
SafeToOpen: BOOLEAN;
FileName:ANSI_STRING ; // ANSI_STRING is declared as in my 1st thread
end;
SCANNER_REPLY = _SCANNER_REPLY;
PSCANNER_REPLY = ^_SCANNER_REPLY;
But when i used your methode in your last reply P will print out the Whole FileName content Buffer , But i only need to print out the filename as in C result

any suggestion for that ?


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:43 Uhr.

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