Einzelnen Beitrag anzeigen

mts

Registriert seit: 14. Dez 2008
24 Beiträge
 
Delphi XE4 Professional
 
#10

AW: DelphiTwain findet keine Geräte in Delphi 10.1 - in XE4 alles ok

  Alt 7. Jan 2022, 18:55

Eventuell liegt es an einer Änderung von Optionen wie dem Record-Alignment. Zeig mal die Deklaration des Typs von Newsource.Structure.
Genau das glaube ich auch.
Ich habe mir die original-header mal angeschaut (https://github.com/twain/twain-speci...ns/2.4/twain.h)
Alle structs sind pack(2) aligned. Soweit ich weiß ist ein Delphi "packed record" aber pack(1).

Wundere mich bloß wie der jemals laufen konnte? Oder übersehe ich hier was?

Die Änderung in das hier hat aber auch nix gebracht:
{$A2}
TW_IDENTITY = record
...

vorher:
Code:
  TW_IDENTITY = packed record
    Id: TW_UINT32;            { Unique number. In Windows, application hWnd }
    Version: TW_VERSION ;     { Identifies the piece of code }
    ProtocolMajor: TW_UINT16; { Application and DS must set to TWON_PROTOCOLMAJOR }
    ProtocolMinor: TW_UINT16; { Application and DS must set to TWON_PROTOCOLMINOR }
    SupportedGroups: TW_UINT32; { Bit field OR combination of DG_ constants }
    Manufacturer: TW_STR32;  { Manufacturer name, e.g. "Hewlett-Packard" }
    ProductFamily: TW_STR32; { Product family name, e.g. "ScanJet" }
    ProductName: TW_STR32;   { Product name, e.g. "ScanJet Plus" }
  end;
>> Ich bin mittlerweile zu 90% sicher, dass es etwas mit dem byte-alignment zu tun hat. Finde allerdings keine Info, dass dort etwas geändert wurde.

Hier die komplette Funktion mal auf das wesentliche runtergebrochen (funktioniert in XE4, funktioniert nicht in 10.1):
Code:
var
  _Handle: HInst;
  _TwainProc: TDSMEntryProc;
  res : boolean;
  resI : integer;
  idn : TW_IDENTITY;
  newS : TW_IDENTITY;
  hndl : THandle;
begin
  _Handle := LoadLibrary('c:\Windows\twain_32.dll');;
  if (_Handle = INVALID_HANDLE_VALUE) then exit;

  _TwainProc := nil;
  @_TwainProc := GetProcAddress(_Handle, MakeIntResource(1));
  if (@_TwainProc = nil) then exit;

  idn.Id := 0;
  idn.Version.MajorNum := 0;
  idn.Version.MinorNum := 0;
  idn.Version.Language := 0;
  idn.Version.Country := 0;
  idn.Version.Info := '';
  idn.ProtocolMajor := 1;
  idn.ProtocolMinor := 9;
  idn.SupportedGroups := DG_CONTROL or DG_IMAGE;
  idn.Manufacturer := '';
  idn.ProductFamily := '';
  idn.ProductName := '';

  hndl := Handle;
  res := _TwainProc(@idn, nil, DG_CONTROL, DAT_PARENT, MSG_OPENDSM, @hndl) = TWRC_SUCCESS; //source manager loaded
  if (not res) then exit;

  newS := idn;
  newS.Id := 0;
  resI := _TwainProc(@idn, nil, DG_CONTROL, DAT_IDENTITY, MSG_GETFIRST, @newS);
  if (resI = 0) then
    ShowMessage('gut');

Geändert von mts ( 7. Jan 2022 um 19:57 Uhr)
  Mit Zitat antworten Zitat