AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

from ANSI_STRING to PAnsichar

Ein Thema von mohfa · begonnen am 24. Okt 2009 · letzter Beitrag vom 25. Okt 2009
Antwort Antwort
mohfa

Registriert seit: 11. Feb 2007
97 Beiträge
 
Delphi 7 Enterprise
 
#1

from ANSI_STRING to PAnsichar

  Alt 24. Okt 2009, 20:46
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
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#2

Re: from ANSI_STRING to PAnsichar

  Alt 24. Okt 2009, 20:48
Use Buffer
Markus Kinzler
  Mit Zitat antworten Zitat
mohfa

Registriert seit: 11. Feb 2007
97 Beiträge
 
Delphi 7 Enterprise
 
#3

Re: from ANSI_STRING to PAnsichar

  Alt 24. Okt 2009, 21:08
But how about the Length and MaximumLength ?
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.149 Beiträge
 
Delphi 12 Athens
 
#4

Re: from ANSI_STRING to PAnsichar

  Alt 24. Okt 2009, 21:09
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
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
mohfa

Registriert seit: 11. Feb 2007
97 Beiträge
 
Delphi 7 Enterprise
 
#5

Re: from ANSI_STRING to PAnsichar

  Alt 25. Okt 2009, 14:03
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 ?
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:32 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