문제

이름이 gettickcount64 인 Kernel32.dll 라이브러리에서 외부 기능을 선언하고 싶습니다. 내가 아는 한, 그것은 Vista와 이후 Windows 버전에서만 정의됩니다. 이것은 기능을 다음과 같이 정의 할 때 다음과 같이 의미합니다.

function GetTickCount64: int64; external kernel32 name 'GetTickCount64';

응용 프로그램 시작에서 생성 된 오류로 인해 이전 버전의 Windows에서 응용 프로그램을 실행할 수 없습니다.

그 문제에 대한 해결 방법이 있습니까? 해당 기능이 존재하지 않을 때 해당 기능을 포함시키지 않으려면 내 코드에서 대체 기능을 사용한다고 가정 해 봅시다. 그렇게하는 방법? 도움이 될 컴파일러 지침이 있습니까? 나는 정의가 그러한 지침으로 둘러싸여 있어야 할 것이며, gettickcount64 founction을 사용하는 곳마다 몇 가지 지침을 사용해야 할 것입니다.

당신의 도움은 감사하겠습니다. 미리 감사드립니다.

마리우스.

도움이 되었습니까?

해결책

해당 유형의 함수 포인터를 선언 한 다음 런타임에 기능을로드하십시오. LoadLibrary 또는 GetModuleHandle 그리고 GetProcAddress. 델파이 소스 코드에서 기술의 몇 가지 예를 찾을 수 있습니다. 보다 tlhelp32.pas,로드 도구 헬프 라이브러리, 이전 버전의 Windows NT에서는 사용할 수 없습니다.

interface

function GetTickCount64: Int64;

implementation

uses Windows, SysUtils;

type
   // Don't forget stdcall for API functions.
  TGetTickCount64 = function: Int64; stdcall;

var
  _GetTickCount64: TGetTickCount64;

// Load the Vista function if available, and call it.
// Raise EOSError if the function isn't available.
function GetTickCount64: Int64;
var
  kernel32: HModule;
begin
  if not Assigned(_GetTickCount64) then begin
    // Kernel32 is always loaded already, so use GetModuleHandle
    // instead of LoadLibrary
    kernel32 := GetModuleHandle('kernel32');
    if kernel32 = 0 then
      RaiseLastOSError;
    @_GetTickCount := GetProcAddress(kernel32, 'GetTickCount64');
    if not Assigned(_GetTickCount64) then
      RaiseLastOSError;
  end;
  Result := _GetTickCount64;
end;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top