Reputation:
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?
Upvotes: 0
Views: 1145
Reputation: 163317
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.
Upvotes: 0