Einzelnen Beitrag anzeigen

Relicted

Registriert seit: 24. Jan 2006
Ort: Iserlohn
646 Beiträge
 
Delphi 10.4 Sydney
 
#1

Dynamisches Laden von DLL-Funktion schlägt fehl

  Alt 26. Apr 2017, 12:06
Hallo zusammen,

stehe gerade etwas auf dem Schlauch. Vielleicht hat ja jemand eine Idee. Ich muss/möchte eine statische Linkung einer DLL auflösen. Leider klappt das nicht so wie gehofft.
Hier der Original-Code (funktioniert):
Delphi-Quellcode:
interface

const
  wlan_api_dll = 'wlanapi.dll';

function WlanOpenHandle(dwClientVersion: DWORD; pReserved: PVOID;
  pdwNegotiatedVersion: PWord; phClientHandle: PHandle): DWORD; stdcall;

implementation

function WlanOpenHandle; external wlan_api_dll name 'WlanOpenHandle';
Meine geänderte Version, welche leider nicht funktioniert. Dll-Handle wird ermittelt, sieht valide aus nur leider wirft das GetProcAddress immer NIL zurück.

Delphi-Quellcode:
interface

const
  wlan_api_dll = 'wlanapi.dll';

function WlanOpenHandle(dwClientVersion: DWORD; pReserved: PVOID;
  pdwNegotiatedVersion: PWord; phClientHandle: PHandle): DWORD; stdcall;

implementation

var
  dllHandle : NativeUint = 0;

function GetDllAddress(AFuncName : string) : pointer;
begin
  result := nil;

  if dllHandle <> 0 then
  begin
    result := GetProcAddress(dllHandle, PAnsiChar(AFuncName));
  end;
end;

type
  TWlanOpenHandle = function(dwClientVersion: DWORD; pReserved: PVOID; pdwNegotiatedVersion: PWord; phClientHandle: PHandle): DWORD; stdcall;

function WlanOpenHandle(dwClientVersion: DWORD; pReserved: PVOID;
  pdwNegotiatedVersion: PWord; phClientHandle: PHandle): DWORD; stdcall;
var
  func : TWlanOpenHandle;
begin
  result := 0;
  @func := GetDllAddress('WlanOpenHandle');
  if Assigned(func) then
    result := func(dwClientVersion, pReserved, pdwNegotiatedVersion, phClientHandle);
end;

initialization
  dllHandle := LoadLibrary(wlan_api_dll);
finalization
  if dllHandle <> 0 then FreeLibrary(dllHandle);
Jemand eine Idee?

Geändert von Relicted (26. Apr 2017 um 12:18 Uhr)
  Mit Zitat antworten Zitat