I'm trying to call IsNativeVhdBoot function but i get error message The parameter is incorrect.
function IsNativeVhdBoot(var NativeVhdBoot:PBOOL):BOOL; external Kernel32 name 'IsNativeVhdBoot';
function _IsNativeVhdBoot:Boolean;
var
pB:PBOOL;
begin
Result := False;
if IsNativeVhdBoot(pB) then
Result := pB^
else RaiseLastOSError;
end;
I have also tried to call it this way
function __IsNativeVhdBoot: Boolean;
type
TIsNativeVhdBoot = function(
var NativeVhdBoot: pBOOL
): BOOL; stdcall;
var
bNativeVhdBoot: pBOOL;
NativeVhdBoot : TIsNativeVhdBoot;
begin
Result := False;
NativeVhdBoot := GetProcAddress(GetModuleHandle(kernel32), 'IsNativeVhdBoot');
if (@NativeVhdBoot <> nil) then
begin
if not NativeVhdBoot(bNativeVhdBoot) then
RaiseLastOSError;
Result := bNativeVhdBoot^;
end
else
RaiseLastOSError;
end;
My questions is
- What I'm doing wrong to call the above function.
- When Calling an
extranl WinAPI in delphi what is the difference between calling it
function Foo():BOOL; external Kernel32 name 'Foo';
andtype TFoo = function(): BOOL; stdcall;
Because i usually do the calls like the first method but when i get the above error message i searched how to call external function and i found the other method.
Update
Tested the same function in C++ and i got the same error, my code was as the following
#include "stdafx.h"
#include "Windows.h"
int _tmain(int argc, _TCHAR* argv[])
{
BOOL Result = false;
SetLastError(0);
if (IsNativeVhdBoot(&Result)) {
if (Result) {
printf_s("Running inside VHD\n");
}
else
printf_s("Running inside physical disk drive\n");
}
else
printf("IsNativeVhdBoot failed with error %d.\n", GetLastError());
return 0;
}