Go Back   FileForums > Game Backup > PC Games > PC Games - CD/DVD Conversions > Conversion Tutorials
Register FAQ Community Calendar Today's Posts Search

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #11  
Old 29-04-2023, 06:33
BLACKFIRE69's Avatar
BLACKFIRE69 BLACKFIRE69 is offline
Registered User
 
Join Date: Mar 2019
Location: In the Hell
Posts: 688
Thanks: 481
Thanked 2,547 Times in 561 Posts
BLACKFIRE69 is on a distinguished road
Question Help

does anyone know how to convert this following Delphi code into InnoSetup?
alternatively, if you have any other suggestions on how to accomplish this in a similar manner, please feel free to share your thoughts. thanks.

Code:
uses
  Winapi.Windows, System.SysUtils;

type
  TFuncX = procedure(const Var1: Integer); cdecl;
  TFuncY = function(const Count: Longint; var Str: AnsiString): Integer; cdecl;
  TFuncZ = procedure(const Str1, Str2: WideString); cdecl;
  TFuncCommon = record
    case Integer of
      0: (FuncX: TFuncX);
      1: (FuncY: TFuncY);
      2: (FuncZ: TFuncZ);
  end;

function MySafeLoadLibFunc(const LibName, FuncName: WideString;
   var Func: TFuncCommon; var ErrorStr: WideString): Cardinal;
begin
  ErrorStr := '';
  Result := LoadLibraryW(PWideChar(LibName));
  if Result > 32 then begin
    try
      case Integer(Func) of  // Get the address of the function by name
        0: Func.FuncX := GetProcAddress(Result, PWideChar(FuncName));
        1: Func.FuncY := GetProcAddress(Result, PWideChar(FuncName));
        2: Func.FuncZ := GetProcAddress(Result, PWideChar(FuncName));
      end;
      if not Assigned(Pointer(Integer(Func))) then begin
        ErrorStr := 'Could not find function "' + FuncName + '" in library "' + LibName + '"';
        Result := 0;
      end;
    except
      on E: Exception do begin
        ErrorStr := 'Error loading function "' + FuncName + '" from library "' + LibName + '": ' + E.Message;
        Result := 0;
      end;
    end;
  end else ErrorStr := 'Could not load library "' + LibName + '"';

  if ErrorStr = '' then ErrorStr := 'empty';
end;
Code:
USAGE:

procedure Test;
var
  MyFunc: TFuncCommon;
  ErrorStr: WideString;
  LibModule: Cardinal;
  TmpStr: AnsiString;
begin
  try
    LibModule := MySafeLoadLibFunc('MyDll.dll', 'MyFunc3', MyFunc, ErrorStr);
    if LibModule > 32 then
    begin
      //MyFunc.FuncX(69);                 // Call function FuncX
      //MyFunc.FuncY(47, TmpStr);         // Call function FuncY
      MyFunc.FuncZ('Hello', 'World');   // Call function FuncZ

      FreeLibrary(LibModule); // Free MyDll.dll
    end
    else WriteLn(ErrorStr);
  except
    on E: Exception do WriteLn(E.ClassName, ': ', E.Message);
  end;
end;


Code:
MyDll:

library MyDll;

uses
  System.SysUtils, Winapi.Windows;

{$R *.res}

function ShowMsg(const Msg: WideString; Caption: WideString = 'A Msg From MyDll.dll'): Integer; cdecl;
begin
  Result := MessageBoxW(0, PWideChar(Msg), PWideChar(Caption), MB_OK);
end;

procedure MyFunc1(const Var1: Integer); cdecl;
begin
  ShowMsg('[MyFunc1] : Var1  =  ' + IntToStr(Var1));
end;

function MyFunc2(const Count: Longint; var Str: AnsiString): Integer; cdecl;
begin
  Str := 'BLACKFIRE';
  Result := -10;
  ShowMsg('[MyFunc2] : Count  =  ' + IntToStr(Count));
end;

procedure MyFunc3(const Str1, Str2: WideString); cdecl;
begin
  ShowMsg('[MyFunc3] : Str1  =  ' + Str1 + ',  Str2  =  ' + Str2);
end;

exports MyFunc1, MyFunc2, MyFunc3;

begin
end.
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
INNO TROUBLESHOOT - Tutorials and Answers about INNO Setup REV0 Conversion Tutorials 129 21-05-2021 05:51
INNO TUTORIAL - Using Unicode and ANSI Versions of INNO Setup REV0 Conversion Tutorials 51 26-03-2015 06:57
Frequently Asked Questions Joe Forster/STA PC Games - Frequently Asked Questions 0 29-11-2005 09:48



All times are GMT -7. The time now is 11:17.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
FileForums @ https://fileforums.com