Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2007 Feb : Dynamic Link Library Function

www.cryer.info
Managed Newsgroup Archive

Dynamic Link Library Function

Subject:Dynamic Link Library Function
Posted by:"Cecil Ricardo" (cecilricar..@gmail.com)
Date:15 Feb 2007 14:03:47

Dynamic Link Library Functions

We are having a problem where a function is successfully called when using static call.
However we cannot execute it via a dynamic call.

The two snippets of code below shows they way we are treating each case.

Code 1 is the static call for the function. It works correctly.
Code 2 is the dynamic call. It does not work.

Can you tell me what is wrong with the code 2 ?

Thank you


Code 1

Function WTSOpenServer; external 'WTSApi32.dll' name 'WTSOpenServerW';
.
.
.
Function WTSOpenServer(pServerName: PWideChar): Integer; stdCall;
var
   wl_result : Integer;
begin
  wl_result := WTSOpenServer(PWideChar(WideString(NomeComputador))));
end;


Code 2

function OpenServerTS : Integer;
Var
  HDll :THandle;
  wl_Function : Function(pServerName: PWideChar) : Integer;
begin
  Result:= 0;
  HDll  := LoadLibrary( 'WtsAPI32.dll' );
  try
    If HDll <> 0 Then
      Begin
        @wl_Function := GetProcAddress(HDll, 'WTSOpenServerW' );
        If (@wl_Function <> nil) Then
          Result:= Integer(wl_Function(PWideChar(WideString(NomeComputador))));
      end;
  finally
    FreeLibrary( HDll );
  end;
end;


procedure buttonclick;
var
  wl_Result : Integer
begin
   wl_Result := OpenServerTS;
end;

Replies:

www.cryer.info
Managed Newsgroup Archive