Forum > General
how do I know how much to allocate with getmem when calling an api
(1/1)
jw:
here's the code I'm grabbing the drives serial number.
var
serial : pdword;
s : string;
begin
GetMem(serial, 100);
GetVolumeInformation(pChar('c:\'), nil, 0, serial, DWord(nil^), DWord(nil^) , nil, 0);
s:=hexstr(serial^,8);
FreeMem(serial, 100);
edit1.text:=copy(s,1,4) + '-' + copy(s,5,8);
end;
ok I got it working but still not sure how it actually works.
pdword? memory address one word in length being pointed to? so it 2 bytes but already reserved as soon as I define it right
now i need to define how much memory to use from where the pointer points to. The delphi page used getmem to allocate 260 bytes I lowered it to 100 but if I say getmem(serial,0) the program still works.
it seems to me the drives serial number is a double word xxxx-xxxx so it seems
getmem(serial,4) would be sufficient. Does any of this sound right?
faber:
function Serial: string;
var
SerialNumber : DWORD;
begin
GetVolumeInformation(pChar('c:\'),nil,0, @SerialNumber, DWord(^nil), DWord(^nil), nil, 0) ;
Result :=IntToHex(HiWord(SerialNumber), 4) +' - ' +IntToHex(LoWord(SerialNumber), 4) ;
end;
jw:
thanks
carrots in wrong place
GetVolumeInformation(PChar('c:\'), nil, 0, @SerialNumber, DWORD(nil^), DWORD(nil^), nil, 0);
Navigation
[0] Message Index