Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Treiberinstallation (https://www.delphipraxis.net/98503-treiberinstallation.html)

Nuclear-Ping 28. Aug 2007 12:10


Treiberinstallation
 
Hallo,

kennt sich jemand mit dem Thema Treiberinstallation per Code / Installer aus und kann mir irgendwie Tutorials oder Tipps geben?

Hab mir schon WiX und WiXEdit angeschaut, allerdings hab ich dafür nur ein WiX-XML-Tutorial gefunden und keins für WiXEdit. Wenn ich mir WiXEdit anschaue, weiß ich nicht, ob ich erst nach links oder rechts gehen soll und selbst wenn, wüßte ich nicht, was ich da machen soll. Also kurz gesagt: Da blick ich ohne Tutorial nicht durch. Und das XML-Tutorial wollte ich mir im Moment grad ungern antun.

Auch hab ich mir die SetupApi von Jedi angeschaut. Die Demos dort beschäftigten sich allerdings nur mit dem Lesen von Systeminformationen und nicht mit dem "schreiben". Ein paar Gehversuche mit "SetupInstallFile", welches eine Inf-Datei installieren soll, endeten bisher nur in Zugriffsverletzungen beim Aufruf von SetupInstallFile.
Delphi-Quellcode:
const
  InfFile = '.\drivers\NT_2K_XP\lqr\lqr_usb.inf';
var
  src: PChar;
begin
  GetMem (src, Length (InfFile));
  try
    StrCopy (src, InfFile);
    if SetupInstallFile (
          nil,
          nil,
          src,
          nil,
          nil,
          SP_COPY_SOURCE_ABSOLUTE,
          nil,
          nil) then
      showmessage ('OK')
    else showmessage ('Oh Oh ...');
  finally
    FreeMem (src);
  end;
end;
Laut MSDN ( http://msdn2.microsoft.com/en-us/library/aa377398.aspx ) ist der Aufruf in meinen Augen korrekt: Bis auf Flags sind alles optionale Parameter. Und das was man braucht (in dem Fall "src" als Quelldatei) gibt man an. Was mach ich hier falsch?

messie 28. Aug 2007 12:25

Re: Treiberinstallation
 
Kann das sein, daß die Routine ein PWideChar statt PChar braucht?

Grüße, Messie

Nuclear-Ping 28. Aug 2007 13:27

Re: Treiberinstallation
 
Hm, sollte eigentlich nicht das Problem sein. Alle API-Header-Kapselungen haben imho ne "Weiche", die Prüft ob Unicode vorliegt oder nicht. SetupInstallFile wird wohl ein Kürzel für entweder SetupInstallFileA oder SetupInstallFileW sein.

Aber ich probier's grad mal aus ...

[Edit]
Ne, mit PWideChar funktionierts erst garnicht. Er will PTSTR / PChar.

Delphi-Quellcode:
type
  {...}
  LPSTR = {$IFDEF USE_DELPHI_TYPES} Windows.LPSTR {$ELSE} PAnsiChar {$ENDIF};
  {...}
  PTSTR = LPSTR;

  {...}

function SetupInstallFile(InfHandle: HINF; InfContext: PInfContext;
  const SourceFile, SourcePathRoot, DestinationName: PTSTR; CopyStyle: DWORD;
  CopyMsgHandler: TSPFileCallback; Context: Pointer): BOOL; stdcall;
:gruebel:
[/Edit]

Remko 29. Aug 2007 20:58

Re: Treiberinstallation
 
MSDN says:
Zitat:

SourceFile
[in] Optional pointer to the file name (no path) of the file to copy. The file is looked up in the SourceDisksFiles section. The SourceFile parameter must be specified if InfContext is not. SourceFile is ignored if InfContext is specified.
I presume that the inf file must be in systemroot\inf or that you must use either supply an InfHandle if the file is in another path or that you must specify the path in SourcePathRoot parameter.

Edit: a HINF can be obtained by calling MSDN-Library durchsuchenSetupOpenInfFile, there you can give an optional path:
Zitat:

FileName
[in] Pointer to a null-terminated string containing the name (and optional path) of the INF file to be opened. If the filename does not contain path separator characters, it is searched for, first in the %windir%\inf directory, and then in the %windir%\system32 directory. If the filename contains path separator characters, it is assumed to be a full path specification and no further processing is performed on it.

Nuclear-Ping 30. Aug 2007 13:55

Re: Treiberinstallation
 
Great suggestions, thanks. But none of them work ... :(

Suggestion to separate file name and root path:
Delphi-Quellcode:
const
  infPath = '.\drivers\NT_2K_XP\lqr\';
  infFile = 'lqr_usb.inf';
var
  srcPath,
  srcFile: PChar;
begin
  GetMem (srcPath, Length (infPath) + 1);
  GetMem (srcFile, Length (infFile) + 1);
  StrCopy (srcPath, infPath);
  StrCopy (srcFile, infFile);
  if SetupInstallFile (
        nil,
        nil,
        srcFile,
        srcPath,
        nil,
        SP_COPY_SOURCE_ABSOLUTE,
        nil,
        nil) then
    showmessage ('OK')
  else showmessage ('Oh Oh ...');
  FreeMem (srcPath);
  FreeMem (srcFile);
end;
Suggestion to use SetupOpenInfFile: I get an AV when calling SetupOpenInfFile, Read of Adress 000...
I already tried several ways, without GetMem, with GetMem, without ZeroMemory, ... :wall:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
const
  infPath = '.\drivers\NT_2K_XP\lqr\';
  infFile = 'lqr_usb.inf';
var
  srcPath,
  srcFile,
  InfClass: PChar;
  Inf: HINF;
  ErrorLine: PUINT;
begin
  GetMem (InfClass, 32);
  ZeroMemory (InfClass, 32);
  GetMem (srcFile, Length (infPath + infFile) + 1);
  StrCopy (srcFile, infPath + infFile);
  showmessage (srcFile);
  Inf := SetupOpenInfFile (srcFile, InfClass, INF_STYLE_WIN4, ErrorLine);
  try
    if SetupInstallFile (
          Inf,
          nil,
          nil,
          nil,
          nil,
          SP_COPY_SOURCE_ABSOLUTE,
          nil,
          nil) then
      showmessage ('OK')
    else showmessage ('Failed');
  finally
    FreeMem (srcFile);
    FreeMem (InfClass);
    SetupCloseInfFile (Inf);
  end;
end;
[Edit]
Ich hab ne Lösung gefunden mit der DIFxAPI von MSDN! :)

Hab parallel zu dem Vorhaben mit SetupApi die difxapi.h nach Delphi übersetzt - soweit das meine Kenntnisse zuliesen - und scheinbar klappt das.

Die Header-Datei:
http://www.108bits.de/private/files/sources/difxapi.zip

Der Code:
Delphi-Quellcode:
const
  lqrInfFile: String = '.\drivers\NT_2K_XP\lqr\lqr_usb.inf';
  ftdiInfFile1: String = '.\drivers\NT_2K_XP\rs232\FTDIPORT.INF';
  ftdiInfFile2: String = '.\drivers\NT_2K_XP\rs232\FTDIBUS.INF';
var
  NR: Boolean;
  Info: PCINSTALLERINFO_A;
begin
  GetMem (Info, 128);
  Info.pApplicationId := 'AppGUID';
  Info.pDisplayName := 'ApplicationDisplayName';
  Info.pProductName := 'YourProductName';
  Info.pMfgName := 'ManufacturerName';
  DriverPackageInstall (PChar (ftdiInfFile1), DRIVER_PACKAGE_FORCE or DRIVER_PACKAGE_LEGACY_MODE, Info, NR);
  FreeMem (Info);

{...}
end;
Das funzt. Kurze Sanduhr, Treiber ist installiert. :corky:

Allerdings hab ich hier bei der Übersetzung der Header-Datei wohl auch bissl geschlampt. Wenn ich Info nil übergebe (was bei MSDN ok ist), bekomme ich nach der Funktion eine AV, der Treiber wird aber trotzdem installiert.
Auch funktioniert "DriverPackagePreinstall" scheinbar nicht, da dort gleich mal garnix passiert, weder Sanduhr noch Treiberinstallation.
Bin halt kein C'ler ... :P Wer also Fehler findet darf sie gern korrigieren und der Community 'ne optimierte Übersetzung zur Verfügung stellen.
[/Edit]


Alle Zeitangaben in WEZ +1. Es ist jetzt 16:05 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz