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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 29-04-2023, 06:33
BLACKFIRE69's Avatar
BLACKFIRE69 BLACKFIRE69 is offline
Registered User
 
Join Date: Mar 2019
Location: In the Hell
Posts: 701
Thanks: 486
Thanked 2,619 Times in 574 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
Sponsored Links
  #2  
Old 07-06-2023, 17:44
Junior53's Avatar
Junior53 Junior53 is offline
Registered User
 
Join Date: May 2023
Location: Sri Lanka
Posts: 25
Thanks: 23
Thanked 32 Times in 10 Posts
Junior53 is on a distinguished road
Thumbs up

Quote:
Originally Posted by BLACKFIRE69 View Post
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.
I recommend you to use ChatGPT or Bing Ai for this!
Reply With Quote
  #3  
Old 08-06-2023, 00:32
Masquerade Masquerade is offline
Registered User
 
Join Date: Jan 2020
Location: Monte d'Or
Posts: 1,218
Thanks: 294
Thanked 1,407 Times in 637 Posts
Masquerade is on a distinguished road
Quote:
Originally Posted by Junior53 View Post
I recommend you to use ChatGPT or Bing Ai for this!
ChatGPT is notoriously bad at writing complicated code. Sure, it can write simple algorithms, I use it sometimes to write quick scripts for making my repacks, but anything beyond this it usually gets the syntax wrong or the program will not work.
Reply With Quote
  #4  
Old 10-04-2023, 07:52
Lord.Freddy's Avatar
Lord.Freddy Lord.Freddy is offline
Registered User
 
Join Date: Apr 2022
Location: ...
Posts: 54
Thanks: 222
Thanked 41 Times in 25 Posts
Lord.Freddy is on a distinguished road
Unhappy Why doesn't (innoSetup) compile my script?

Code:
#define public RequiredSpace "1000"

#define MbToBytes(str *Value) \
  Local[1] = MbToBytes((Value)), \
  Local[1]

[Setup]
AppName=111
AppVersion=0.0
AppPublisher=bbbbb
DefaultDirName={autopf}\111
ExtraDiskSpaceRequired={#MbToBytes(RequiredSpace)}

[_Code]
function MbToBytes(Value: Integer): Integer;
begin
  Result := (Value * (1024 * 1024));
end;
__________________
¤ Life good be a Dream ¤

Last edited by Lord.Freddy; 10-04-2023 at 07:55.
Reply With Quote
  #5  
Old 10-04-2023, 10:10
Cesar82's Avatar
Cesar82 Cesar82 is offline
Registered User
 
Join Date: May 2011
Location: Brazil
Posts: 1,077
Thanks: 1,837
Thanked 2,311 Times in 789 Posts
Cesar82 is on a distinguished road
You cannot mix ISPP and CODE section codes.
Try like this:
Code:
#define public RequiredSpace "1000"

#define MbToBytes(str Value) \
  Int(Value, 0) * 1024 * 1024

[Setup]
AppName=111
AppVersion=0.0
AppPublisher=bbbbb
DefaultDirName={autopf}\111
ExtraDiskSpaceRequired={#MbToBytes(RequiredSpace)}
Reply With Quote
The Following User Says Thank You to Cesar82 For This Useful Post:
Lord.Freddy (10-04-2023)
  #6  
Old 05-05-2023, 01:52
Junior53's Avatar
Junior53 Junior53 is offline
Registered User
 
Join Date: May 2023
Location: Sri Lanka
Posts: 25
Thanks: 23
Thanked 32 Times in 10 Posts
Junior53 is on a distinguished road
Question Can someone explain what this is used for and what is filemapping?

Code:
function CreateFileMapping(
  File: Cardinal; Attributes: Cardinal; Protect: Cardinal;
  MaximumSizeHigh: Cardinal; MaximumSizeLow: Cardinal; Name: PAnsiChar): Cardinal;
  external '[email protected] stdcall';
  
function MapViewOfFile(
  FileMappingObject: THandle; DesiredAccess: Cardinal; FileOffsetHigh: Cardinal;
  FileOffsetLow: Cardinal; NumberOfBytesToMap: Cardinal): PChar;
  external '[email protected] stdcall';
What is FileMapping & benefits of FileMapping?

File mapping is a technique that allows you to map the contents of a file into the virtual memory space of a process. This allows you to access the contents of the file as if it were in memory, rather than on disk.
There are several benefits to using file mapping:

• Performance: File mapping can improve the performance of file I/O operations by reducing the number of disk accesses. When you map a file into memory, the operating system can use its virtual memory management mechanisms to cache the contents of the file in memory. This means that subsequent accesses to the file can be satisfied from memory, rather than requiring a disk access.

• Concurrency: File mapping allows multiple processes to access the same file concurrently. When multiple processes map the same file into their virtual memory space, they can all access the contents of the file simultaneously. This can be useful for inter-process communication and data sharing.

• Ease of use: File mapping allows you to access the contents of a file using memory-mapped I/O operations, rather than traditional file I/O operations. This can make it easier to work with files, as you can use pointer arithmetic and other memory-based operations to manipulate the contents of the file.
Overall, file mapping is a powerful technique that can improve the performance and ease-of-use of file I/O operations. It is widely used in many different types of applications and is supported by most modern operating systems.

Last edited by Junior53; 07-06-2023 at 17:37. Reason: I found the answer myself :)
Reply With Quote
  #7  
Old 06-05-2023, 14:23
IRAQIGHOST IRAQIGHOST is offline
Registered User
 
Join Date: Jun 2020
Location: Iraq
Posts: 71
Thanks: 42
Thanked 29 Times in 16 Posts
IRAQIGHOST is on a distinguished road
error everytime

Hi
In last days I used method (xt_zlib+srep_new:3+LOLZ_NORMAL) DiskSpan
In thes games
Call of Duty Ghosts
Call of Duty Black Ops 4
A Plague Tale Requiem

but every time after click on install this what come to me


what is the wrong that I did?
Reply With Quote
  #8  
Old 06-05-2023, 16:38
Cesar82's Avatar
Cesar82 Cesar82 is offline
Registered User
 
Join Date: May 2011
Location: Brazil
Posts: 1,077
Thanks: 1,837
Thanked 2,311 Times in 789 Posts
Cesar82 is on a distinguished road
Quote:
Originally Posted by IRAQIGHOST View Post
Hi
In last days I used method (xt_zlib+srep_new:3+LOLZ_NORMAL) DiskSpan
In thes games
Call of Duty Ghosts
Call of Duty Black Ops 4
A Plague Tale Requiem

but every time after click on install this what come to me


what is the wrong that I did?
I don't know if that's it, more the ISDone limits the number of characters to 255 or 260 characters.
Make sure the selected installation path is not too long. Try installing in a folder like "D:\Games\Call of Duty Ghosts"
It also cannot contain special characters in the installation path.
Reply With Quote
The Following User Says Thank You to Cesar82 For This Useful Post:
IRAQIGHOST (10-05-2023)
  #9  
Old 17-05-2023, 14:37
KaktoR's Avatar
KaktoR KaktoR is offline
Lame User
 
Join Date: Jan 2012
Location: From outer space
Posts: 4,713
Thanks: 1,107
Thanked 7,371 Times in 2,854 Posts
KaktoR is on a distinguished road
My question is not about INNO but batch. Since batch is not something I deal everyday with, I need some help here. I don't want to open a new topic for this.

I have some files which I extract with a tool. The problem is that the extracted folders have the exact name as the files.

For example
Code:
File1.abc > Folder1.abc
File2.abc > Folder2.abc
...
Basically I need to get rid of the ".abc" in the folder names.


I already tried something like this but didn't work.
Code:
for /d %%i in (*.abc) do ren "%%~i" *
__________________
Haters gonna hate
Reply With Quote
  #10  
Old 17-05-2023, 18:45
Cesar82's Avatar
Cesar82 Cesar82 is offline
Registered User
 
Join Date: May 2011
Location: Brazil
Posts: 1,077
Thanks: 1,837
Thanked 2,311 Times in 789 Posts
Cesar82 is on a distinguished road
Quote:
Originally Posted by KaktoR View Post
My question is not about INNO but batch. Since batch is not something I deal everyday with, I need some help here. I don't want to open a new topic for this.

I have some files which I extract with a tool. The problem is that the extracted folders have the exact name as the files.

For example
Code:
File1.abc > Folder1.abc
File2.abc > Folder2.abc
...
Basically I need to get rid of the ".abc" in the folder names.


I already tried something like this but didn't work.
Code:
for /d %%i in (*.abc) do ren "%%~i" *
Try
Code:
for /d %%i in (*.abc) do ren "%%~i" "%%~ni"
Reply With Quote
The Following User Says Thank You to Cesar82 For This Useful Post:
KaktoR (18-05-2023)
  #11  
Old 18-05-2023, 01:10
KaktoR's Avatar
KaktoR KaktoR is offline
Lame User
 
Join Date: Jan 2012
Location: From outer space
Posts: 4,713
Thanks: 1,107
Thanked 7,371 Times in 2,854 Posts
KaktoR is on a distinguished road
Thanks this works
__________________
Haters gonna hate
Reply With Quote
  #12  
Old 18-05-2023, 05:02
shazzla shazzla is offline
Registered User
 
Join Date: Nov 2010
Location: Hunnia
Posts: 292
Thanks: 529
Thanked 102 Times in 78 Posts
shazzla is on a distinguished road
Hi all !

How can i get the installed app's path to 'DefaultDirName' ?

I have a reg-entry :
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\ Windows\CurrentVersion\Uninstall\MyApp]
"InstallLocation"="D:\\MyProgram"

Theoretically in InnoSetup's [setup] section

DefaultDirName={reg:HKLM64\HKEY_LOCAL_MACHINE\SOFT WARE\Microsoft\Windows\CurrentVersion\Uninstall\My App, InstallLocation}

should do the job. But no... Any idea ?

Note : (there are "spaces" in the example paths,etc. Its only visible here,dont know why. I my script they doesnt exists. No matter.)
Reply With Quote
  #13  
Old 18-05-2023, 06:51
Cesar82's Avatar
Cesar82 Cesar82 is offline
Registered User
 
Join Date: May 2011
Location: Brazil
Posts: 1,077
Thanks: 1,837
Thanked 2,311 Times in 789 Posts
Cesar82 is on a distinguished road
Quote:
Originally Posted by shazzla View Post
Hi all !

How can i get the installed app's path to 'DefaultDirName' ?

I have a reg-entry :
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\ Windows\CurrentVersion\Uninstall\MyApp]
"InstallLocation"="D:\\MyProgram"

Theoretically in InnoSetup's [setup] section

DefaultDirName={reg:HKLM64\HKEY_LOCAL_MACHINE\SOFT WARE\Microsoft\Windows\CurrentVersion\Uninstall\My App, InstallLocation}

should do the job. But no... Any idea ?

Note : (there are "spaces" in the example paths,etc. Its only visible here,dont know why. I my script they doesnt exists. No matter.)
Try
Code:
DefaultDirName={reg:HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\My App_is1,InstallLocation|{pf}\My App}
UsePreviousAppDir=no
The value {pf}\My App is default dir if not found value in windows registry.

Last edited by Cesar82; 18-05-2023 at 07:01.
Reply With Quote
The Following User Says Thank You to Cesar82 For This Useful Post:
shazzla (19-05-2023)
  #14  
Old 18-05-2023, 21:13
shazzla shazzla is offline
Registered User
 
Join Date: Nov 2010
Location: Hunnia
Posts: 292
Thanks: 529
Thanked 102 Times in 78 Posts
shazzla is on a distinguished road
Thank you very much!
I will try and report back ASAP !

Its working fine !
Thanks !

Last edited by shazzla; 19-05-2023 at 02:35.
Reply With Quote
  #15  
Old 23-06-2023, 09:14
Junior53's Avatar
Junior53 Junior53 is offline
Registered User
 
Join Date: May 2023
Location: Sri Lanka
Posts: 25
Thanks: 23
Thanked 32 Times in 10 Posts
Junior53 is on a distinguished road
Question Question's

01.how to show Component Page before the Select Dir Page (without creating custom forms or anything like that) in Inno setup 5.5.1 ee2 version?

02.how to calculate the required disk space based on the components selected and show in gigabyte on Component page in Inno setup 5.5.1 ee2 version?

I actually found an answer to this. But it doesn't work. If someone gives an answer to these two, it will be a great help <3

Code:
var
  Component1Size: Extended;
  Component2Size: Extended;
  // Add variables for each component as needed

procedure InitializeWizard;
begin
  Component1Size := 1048576;
  Component2Size := 2097152;
  // Assign sizes for other components if needed
end;

function GetTotalSize: String;
var
  TotalSize: Extended;
begin
  TotalSize := 0;
  if WizardForm.ComponentsList.Checked[0] then
    TotalSize := TotalSize + Component1Size;
  if WizardForm.ComponentsList.Checked[1] then
    TotalSize := TotalSize + Component2Size;
  // Add similar lines for other components if needed

  Result := FormatFloat('#,##0.00', TotalSize / 1024 / 1024 / 1024); // Convert bytes to gigabytes
end;

procedure ComponentsPageOnNextButtonClick(Sender: TWizardPage; var Continue: Boolean);
begin
  if Sender.ID = wpSelectComponents then
    WizardForm.DiskSpaceLabel.Caption := 'Required disk space: ' + GetTotalSize + ' GB';
end;
Reply With Quote
Reply


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 22:53.


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