简体   繁体   中英

Determine RasEntry structure size use RasGetEntryProperties in Delphi

I'm trying to create a DUN entry.

I am calling RasGetEntryProperties with a lpRasEntry parameter of null. This should return the structure size in the lpdwEntryInfoSize parameter. Instead it returns an error - ERROR_INVALID_SIZE.

How do I call the RasGetEntryProperties function to get the RasEntry structure size?

The documentation says that Error_Invalid_Size is the error when the dwSize field fo the RasEntry record is incorrect. If the function was able to read that field, then you did not provide a null pointer for the lpRasEntry parameter as you claim you did. The Microsoft documentation says "null," and in Delphi, the reserved word nil designates the null pointer. Do not get confused with the function named Null ; it designates the special Variant value.

Based on the documentation, you should have code like this:

var
  RasEntry: PRasEntry;
  RasBufferSize: DWord;
  Res: DWord;
begin
  RasBufferSize := 0;
  Res := RasGetEntryProperties(nil, '', nil, @RasBufferSize, nil, nil);
  if Res <> Error_Success then
    RaiseLastOSError(Res);
  RasEntry := AllocMem(RasBufferSize);
  try
    RasEntry.dwSize := SizeOf(TRasEntry);
    Assert(RasEntry.dwSize <= RasBufferSize);
    Res := RasGetEntryProperties(nil, '', RasEntry, @RasBufferSize, nil, nil);
  finally
    FreeMem(RasEntry);
  end;
end;

You ask the function how large a buffer it requires (in RasBufferSize ), and then you tell it how large a buffer you're expecting it to fill (in RasEntry.dwSize ). The dwSize field tells the function what version of the structure you're expecting to receive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM