Announcement

Collapse
No announcement yet.

Aus einer C++ DLL Funktionen und Proceduren in Delphi importieren

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Aus einer C++ DLL Funktionen und Proceduren in Delphi importieren

    Hey Profis,

    ich möchte aus einer Windows-Dll Funktionen und Prozeduren importieren. Die Dll ist in C++ geschrieben, ich habe bereits stundenlang versucht, diese zu importieren, doch leider ohne Erfolg. Die beiden nachfolgenden Funktion möchte ich importieren. Den Text den ich bisher gefunden habe lautet:

    VOID CreateProgmanGroup(LPSTR szGroup, LPSTR szPath, INT cmo);

    CreateProgmanGroup creates a new Program Manager group with the specified name.

    Arguments

    szGroup: Specifies the name of the Program Manager group you want to create. This name will be displayed in the group window title bar (or below the icon when the group window is minimized).

    szPath: Specifies the name and path for the Program goup that you want to create. If you provide an empty string for szPath (the suggested method), a default file is created.

    cmo: Specifies the command option flag. You can use cmoVital or cmoNone.

    Comments: Typically, you should use an empty string for szPath.

    und

    VOID CreateProgmanItem(LPSTR szGroup, LPSTR szItem, LPSTR szCmd, LPSTR szOther, INT cmo);

    CreateProgmanItem creates a new item in the specified Program Manager group.

    Arguments

    szGroup: Specifies the name of the Program Manager group in which you want to create the item. If szGroup does not exist, CreateProgmanItem does nothing.

    szItem: Specifies the description that will be displayed below the item.

    szCmd: Specifies the path and executable filename for the new item.

    szOther: Specifies an optional icon file, icon resource index, x and y icon positions for the new item, and the working directory, separated by commas. If you provide an empty string for szOther, defaults are used. However, if you need to specify one of the latter options in the string, you must specify the preceding ones.

    cmo: Specifies the command option flag. You can use cmoVital or cmoOverwrite. If you use cmoOverwrite and the user is running Windows version 3.1, Setup will replace an existing Program Manager item.

    Wer kann mir weiterhelfen? Danke!

  • #2
    Hallo,

    die C-Deklaration <i>VOID CreateProgmanItem(LPSTR szGroup, LPSTR szItem, LPSTR szCmd, LPSTR szOther, INT cmo);</i> sollte sich in Delphi in die folgende Deklaration umsetzen lassen:
    <pre>
    procedure CreateProgmanItem(szGroup, szItem, szCmd: PChar; cmo Integer);
    </pre>
    Die ersten 3 Parameter werden als PChar deklariert und sind somit nur ein 4 Byte grosser Zeiger auf einen nulltermininierten String.

    Alle diese Funktionen stammen aus dem Win16-API von Windows 3.x und sind in Win32 "überflüssig". Welche Delphi-Version wird eingesetzt, etwa noch Delphi 1

    Comment


    • #3
      Hallo,

      zuerst einmal Danke für den Tipp. Auf dir Frage, welche Delphi Version ich habe: 5.0 Standart. Ich habe die Prozedure so deklariert, wie sie mir es empfolen haben.<BR>
      procedure CreateProgmanItem(szGroup, szItem, szCmd: PChar; cmo: Integer); bei dieser Deklaartion bekam ich die Fehlermeldung: Deklaration fehlt. Ich habe sie dann wiefolgt geändert:
      peocedure CreateProgmanItem(szGroup, szItem, szCmd, szOther: PChar; cmo: Integer);<BR>
      In mein Programm fügte ich den Quelltext so ein:<BR>
      procedure CreateProgmanItem(szGroup, szItem, szCmd, szOther: PChar; cmo: Integer); external 'pifmgr.dll';<BR>
      ...

      begin<BR>
      CreateProgramItem('Test', 'Test', 'C:\TEST.EXE', '', 0);<BR>
      end;<BR>

      Beim starten des Programms kam die Fehlermeldung: Die Datei ..\WINDOWS\SYSTEM\PIFMGR.DLL ist fehlerhaft. Installieren Sie die Datei erneut, und wiederholen Sie den Vorgang.<BR>

      1. Was ist falsch? Warum bekomme ich eine Fehlermeldung?<BR>
      2. Sie schrieben, es handelt sich um eine Win16-API Funktion. Welche Funktion gibt es für Win32? Wie kann ich diese in mein Programm einbinden?<BR>
      Ich möchte an einer Stelle in meinem Programm, dass ein neue Programmgruppe im Startmenü und natürlich auch in der neuen Gruppe, neue Einträge erstellt werden. Danke

      Comment


      • #4
        Hallo,

        kann es sein, dass sich hinter PIFMGR.DLL ein 16-Bit-Modul verbirgt. In diesem Fall kann das mit Delphi 5 erstellte 32-Bit-Programm nicht auf die 16-Bit-DLL zugreifen, da eine 16-Bit-DLL nicht so ohne weiteres in den eigenen 32-Bit-Adressraum geladen werden kann. Ab Windows 9x gelten spezielle Regeln, welche Arbeitsschritte beim Setup im System abzuarbeiten sind (Registry, korrektes Verwalten der gemeinsam genutzten DLLs usw.). Aus diesem Grund ist ab Delphi Professional auch das Tool InstallSHIELD Express dabei, das diese Regeln automatisch beachtet und alle notwendigen Einträge anlegen kann. <br>
        Das folgende Beispiel demonstriert, wie Verknüpfungen angelegt werden. Über den Radiobutton im Formular wird festgelegt, ob der Eintrag ins Startmenü oder auf den Desktop kommen soll:
        <pre>
        unit ShortcutFrm;

        interface

        uses
        Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
        Dialogs, StdCtrls, Buttons, ComCtrls, ExtCtrls;

        type
        TFormMain = class(TForm)
        StatBar: TStatusBar;
        BitBtnStart: TBitBtn;
        RadioGroupSort: TRadioGroup;
        Label1: TLabel;
        Label2: TLabel;
        EditPrg: TEdit;
        EditParam: TEdit;
        SBtnEXE: TSpeedButton;
        OpenDialogPrg: TOpenDialog;
        Label3: TLabel;
        EditLNK: TEdit;
        procedure BitBtnStartClick(Sender: TObject);
        procedure SBtnEXEClick(Sender: TObject);
        private
        { Private-Deklarationen }
        function GetShellFolderPath(const aFolder: Integer): String;
        public
        { Public-Deklarationen }
        end;

        var
        FormMain: TFormMain;

        implementation

        {$R *.DFM}

        uses
        ShlObj, ActiveX, ComObj;

        procedure TFormMain.BitBtnStartClick(Sender: TObject);
        var
        aObject : IUnknown;
        aSLink : IShellLink;
        aPFile : IPersistFile;
        sDirectory : String;
        wsFileName : WideString;
        szWinDir : array[0..29] of Char;
        begin
        StatBar.SimpleText := '';
        FillChar(szWinDir, SizeOf(szWinDir), #0);
        GetWindowsDirectory(szWinDir, SizeOf(szWinDir));
        // ShellLink-Objekt anfordern
        aObject := CreateComObject(CLSID_ShellLink);
        // Verbindung zum IShellLink-Interface herstellen
        aSLink := aObject as IShellLink;
        // Verbindung zum IPersistFile-Interface herstellen
        aPFile := aObject as IPersistFile;
        // Verknüpfung über IShellLink definieren
        with aSLink do begin
        // Programmpfad festlegen
        SetPath(PChar(EditPrg.Text));
        // Programmparameter festlegen
        SetArguments(PChar(EditParam.Text));
        // Arbeitsverzeichnis festlegen
        SetWorkingDirectory(szWinDir);
        end;
        // Pfad des gewünschten Shellfolders ermitteln
        if RadioGroupSort.ItemIndex = 0
        then sDirectory := GetShellFolderPath(CSIDL_DESKTOPDIRECTORY)
        else sDirectory := GetShellFolderPath(CSIDL_STARTMENU);
        Assert(sDirectory[Length(sDirectory)] <> '\', 'Backslash!');
        wsFileName := sDirectory + '\' + EditLNK.Text;
        // Verknüpfung über IPersistFile anlegen
        aPFile.Save(PWChar(wsFileName), False);
        StatBar.SimpleText := Format('Der Link »%s« wurde angelegt!',
        [EditLNK.Text]);
        end;

        { Programmdatei auswählen }

        procedure TFormMain.SBtnEXEClick(Sender: TObject);
        begin
        with OpenDialogPrg do
        if Execute then begin
        EditPrg.Text := FileName;
        EditParam.Text := '';
        end;
        end;

        { Private Methode liest über ShellAPI den Pfadnamen aus }

        function TFormMain.GetShellFolderPath(const aFolder: Integer): String;
        var
        pIIL : PItemIDList;
        szPath : array[0..MAX_PATH] of Char;
        aMalloc : IMalloc;
        begin
        Result := '';
        Assert(aFolder <= CSIDL_PRINTHOOD,'Falsche Shellfolder-Konstante');
        OleCheck(SHGetSpecialFolderLocation(0, aFolder, pIIL));
        SHGetPathFromIDList(pIIL, szPath);
        OleCheck(SHGetMalloc(aMalloc));
        aMalloc.Free(pIIL);
        Result := szPath;
        end;

        end.
        </pre>

        P.S: Das Beispiel stammt aus meinem Buch <i>COM/DCOM mit Delphi</i>, die Details können dort nachgelesen werden

        Comment


        • #5
          Herzlich Dank für den Tipp. Alleine wäre ich sicherlich nicht auf die Lösung gekommen

          Comment


          • #6
            Hallo Andreas,

            dein Tipp hat super funktioniert. Jetzt das nächste Problem. Ich möchte nun die Verknüpfung wieder löschen. Dies habe ich mit dem Befehl: <br> DeleteFile(File); <br> durchgeführt. Natürlich habe ich vorher das Verzeichnis des Startmenüs ermittel. Das ganze Funktioniert auch. Nur wenn die Datei gelöscht ist, wird Sie im Startmenü immer noch angezeigt. Erst nach einem Neustart verschwindet auch der Eintrag. Gib es eine andere Möglichkeit das Symbol zu löschen? <br> Gib es auch für das oben genannte Beispiel nicht schon eine fertige Procedure oder Function in einer DLL? <BR>Dank

            Comment

            Working...
            X