Recent

Author Topic: Type mismatch - Inno Setup Unicode 5.5  (Read 4853 times)

fiazhnd

  • New Member
  • *
  • Posts: 36
Type mismatch - Inno Setup Unicode 5.5
« on: May 27, 2018, 11:57:54 am »
I face error "Type Mismatch' in Inno Setup Unicode 5.5.9 and the same code I use in Delphi work well.


Code: Pascal  [Select][+][-]
  1.  
  2. function GetHardwareId(HDD, NIC, CPU, BIOS: LongBool; lpHWID: PAnsiChar; nMaxCount: Integer): Integer; external 'GetHardwareId@files:hwid.dll stdcall setuponly';
  3.  
  4. function GetHWID(): AnsiChar;
  5. var
  6.   sHWID: array[0..254] of AnsiChar;
  7.   iRtn : Integer;
  8.   HDD, NIC, CPU, BIOS: LongBool;
  9. begin
  10.  
  11.   SetAppName('');
  12.  
  13.   HDD := True;
  14.    NIC := False;
  15.     CPU := True;
  16.      BIOS := True;
  17.  
  18.   iRtn:= GetHardwareId(HDD, NIC, CPU, BIOS, sHWID, SizeOf(sHWID)); // <= Error
  19.   if iRtn > 0 then
  20.   Edit0.Text := sHWID;
  21. end;

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Type mismatch - Inno Setup Unicode 5.5
« Reply #1 on: May 27, 2018, 12:55:40 pm »
That's not nearly enough information. Are you sure you tried this in {$mode delphi} or {$mode delphiunicode} and platform Windows?
Quote
I face error "Type Mismatch'
that's not all information: the error has the full type mismatch line: what type it expects and what type you try to use.
That is essential information. We need that to help you.
Your code is also very badly formatted.

My current guesswork ends up with:
Code: Pascal  [Select][+][-]
  1.   sHWID: array[0..254] of AnsiChar;
should be
Code: Pascal  [Select][+][-]
  1.   sHWID: array[0..255] of AnsiChar;
and
Code: Pascal  [Select][+][-]
  1. SizeOf(sHWID))
should be
Code: Pascal  [Select][+][-]
  1. Strlen(sHWID)


It is a complete mess....maybe this will help:
Code: Pascal  [Select][+][-]
  1. {$ifdef fpc}{$mode delphi}{$H+}{$endif}
  2. var s: array [0..255] of AnsiChar;
  3. begin
  4.  s := Pchar('testmewhat my length is?');
  5.  writeln('Array length: ',SizeOf(s),' Array length: ', length(s),' Content length!: ' , strlen(s));
  6. end.
See the difference?

« Last Edit: May 27, 2018, 01:31:58 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: Type mismatch - Inno Setup Unicode 5.5
« Reply #2 on: May 27, 2018, 01:53:51 pm »
uhm?
The 5th Argument of the Function expects a Pointer to AnsiChar, but he throws the Array at it?

i would have expected something like

iRtn:= GetHardwareId(HDD, NIC, CPU, BIOS, @sHWID[0], Length(sHWID));
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Josh

  • Hero Member
  • *****
  • Posts: 1274
Re: Type mismatch - Inno Setup Unicode 5.5
« Reply #3 on: May 27, 2018, 01:57:44 pm »
Hi

Are you trying this in INNOSetup itself?
surely your protection should be in your app?

AFAIK If innosetup could use the wmi to get the information, the info would only be valid for the developer machine(when you compile the script) not the client machine. I could be wrong here though.

If its an innosetup specific, maybe posting on their groups would be better
http://www.jrsoftware.org/newsgroups.php
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Type mismatch - Inno Setup Unicode 5.5
« Reply #4 on: May 27, 2018, 02:03:03 pm »
uhm?
The 5th Argument of the Function expects a Pointer to AnsiChar, but he throws the Array at it?

i would have expected something like

iRtn:= GetHardwareId(HDD, NIC, CPU, BIOS, @sHWID[0], Length(sHWID));
Well, I already showed why your code will fail too.... I gave a simple example, compiles and works and shows exactly what is wrong.
Like
Code: Pascal  [Select][+][-]
  1.  Length(sHWID));// this is a mistake! just like SizeOf() is
Some people don't believe simple examples. It is very hard to write simple examples...
« Last Edit: May 27, 2018, 02:07:47 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Type mismatch - Inno Setup Unicode 5.5
« Reply #5 on: May 27, 2018, 02:06:21 pm »
AFAIK If innosetup could use the wmi to get the information, the info would only be valid for the developer machine(when you compile the script) not the client machine. I could be wrong here though.
Using WMI is not an option and not needed (because Innosetup uses the underlying lowlevel calls anyway!!!) . But InnoSetup is windows platform only.
What he is doing is not giving enough information:
The compiler tells you what it expects and what it gets......
« Last Edit: May 27, 2018, 02:08:19 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: Type mismatch - Inno Setup Unicode 5.5
« Reply #6 on: May 27, 2018, 02:14:29 pm »
Thaddy, i said expected.

Since he's using an Array i would have expected "Length", but you're correct.
Since it's a Pointer to AnsiChar expected, strLen would be correct

EDIT: What actually baffles me: If he knows, that his external function expects a PAnsiChar, why is he using an Array??
Something like this would have been my first try (untested)
Code: Pascal  [Select][+][-]
  1. Var
  2.    sHWID:PAnsiChar;
  3. .
  4. .
  5. .
  6. sHWID:=GetMem(256);
  7. iRtn:= GetHardwareId(HDD, NIC, CPU, BIOS, sHWID, StrLen(sHWID));
  8. .
  9. .
  10. .
  11. FreeMem(sHWID);
  12.  
« Last Edit: May 27, 2018, 02:29:56 pm by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Type mismatch - Inno Setup Unicode 5.5
« Reply #7 on: May 27, 2018, 05:32:59 pm »
@sHWID[0]
should be enough on the original verison..

The only true wisdom is knowing you know nothing

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Type mismatch - Inno Setup Unicode 5.5
« Reply #8 on: May 27, 2018, 06:01:42 pm »
@sHWID[0]
should be enough on the original verison..
No it is not. The library is NOT written in Pascal. Pascal allows embedded #0's in a string. C and C++ (and more brackety languages)
You should always determine the length of such a type of string with compatible code such as strlen.

Comments such as yours introduce bugs, not solve them, for a Pascal programmer.
I suppose now you know the errors of your ways? O:-)

BTW even using an index my small example shows clearly that is just as wrong....
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Type mismatch - Inno Setup Unicode 5.5
« Reply #9 on: May 27, 2018, 08:48:40 pm »
what ever..
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018