Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Delphi record? von C nach Delphi (https://www.delphipraxis.net/163492-record-von-c-nach-delphi.html)

Alter Mann 30. Sep 2011 13:07

record? von C nach Delphi
 
Hallo,

ich habe in C diesen Code:

Code:
LIST_ENTRY EnumeratedHCListHead =
{
    &EnumeratedHCListHead,
    &EnumeratedHCListHead
};
LIST_ENTRY ist in der winnt.h so definiert:
Code:
typedef struct _LIST_ENTRY {
   struct _LIST_ENTRY *Flink;
   struct _LIST_ENTRY *Blink;
} LIST_ENTRY, *PLIST_ENTRY, *RESTRICTED_POINTER PRLIST_ENTRY;
Das an sich stellt nicht das Problem da, da in der Windows.pas (Delphi) eine entsprchende Definition vorhanden ist:
Delphi-Quellcode:
  PListEntry = ^TListEntry;
  _LIST_ENTRY = record
    Flink: PListEntry;
    Blink: PListEntry;
  end;
  {$EXTERNALSYM _LIST_ENTRY}
  TListEntry = _LIST_ENTRY;
  LIST_ENTRY = _LIST_ENTRY;
  {$EXTERNALSYM LIST_ENTRY}
Doch wie stelle ich EnumeratedHCListHead da?

patti 30. Sep 2011 13:13

AW: record? von C nach Delphi
 
Wo genau ist denn jetzt das Problem bzw. die Frage?
Die Eigenschaften Flink und Blink zeigen beim Kopf halt ganz einfach auf den Kopf selbst... Also EnumeratedHCListHead vom Typ TListEntry erzeugen und die beiden Zeiger darauf zeigen lassen.

Alter Mann 30. Sep 2011 13:28

AW: record? von C nach Delphi
 
Ich glaube ich komme darauf noch einmal zurück.
Behelfe mich jetzt erst einmal so:
Delphi-Quellcode:
listEntry := new(PListEntry);
Mal sehen wie weit ich damit komme.

Bis hier her. Es scheint etwas komplizierter zu sein.
Zum besseren Verständnis mal die ganze Routine:
Code:
VOID
EnumerateHostController (
    HTREEITEM hTreeParent,
    HANDLE    hHCDev,
    __in PTSTR leafName
)
{
    PTSTR      driverKeyName;
    PTSTR      deviceDesc;
    PTSTR      deviceId;
    HTREEITEM  hHCItem;
    PTSTR      rootHubName;
    PLIST_ENTRY listEntry;
    PUSBHOSTCONTROLLERINFO hcInfo;
    PUSBHOSTCONTROLLERINFO hcInfoInList;

    // Allocate a structure to hold information about this host controller.
    //
    hcInfo = (PUSBHOSTCONTROLLERINFO)ALLOC(sizeof(USBHOSTCONTROLLERINFO));

    if (hcInfo != NULL)
    {
        hcInfo->DeviceInfoType = HostControllerInfo;

        // Obtain the driver key name for this host controller.
        //
        driverKeyName = GetHCDDriverKeyName(hHCDev);

        if (driverKeyName)
        {
            // Don't enumerate this host controller again if it already
            // on the list of enumerated host controllers.
            //
            listEntry = EnumeratedHCListHead.Flink;

            while (listEntry != &EnumeratedHCListHead)
            {
                hcInfoInList = CONTAINING_RECORD(listEntry,
                                                 USBHOSTCONTROLLERINFO,
                                                 ListEntry);

                if (_tcscmp(driverKeyName, hcInfoInList->DriverKey) == 0)
                {
                    // Already on the list, exit
                    //
                    FREE(driverKeyName);
                    FREE(hcInfo);
                    return;
                }

                listEntry = listEntry->Flink;
            }

            // Obtain the device id string for this host controller.
            // (Note: this a tmp global string buffer, make a copy of
            // this string if it will used later.)
            //
            deviceId = DriverNameToDeviceDesc(driverKeyName, TRUE);

            if (deviceId)
            {
                ULONG  ven, dev, subsys, rev;

                if (_stscanf_s(deviceId,
                           _T("PCI\\VEN_%x&DEV_%x&SUBSYS_%x&REV_%x"),
                           &ven, &dev, &subsys, &rev) != 4)
                {
                    OOPS();
                }

                hcInfo->DriverKey = driverKeyName;

                hcInfo->VendorID = ven;
                hcInfo->DeviceID = dev;
                hcInfo->SubSysID = subsys;
                hcInfo->Revision = rev;
            }
            else
            {
                OOPS();
            }

            // Obtain the device description string for this host controller.
            // (Note, this a tmp global string buffer, make a copy of
            // this string if it will be used later.)
            //
            deviceDesc = DriverNameToDeviceDesc(driverKeyName, FALSE);

            if (deviceDesc)
            {
                leafName = deviceDesc;
            }
            else
            {
                OOPS();
            }

            // Add this host controller to the USB device tree view.
            //
            hHCItem = AddLeaf(hTreeParent,
                              (LPARAM)hcInfo,
                              leafName,
                              GoodDeviceIcon);

            if (hHCItem)
            {
                // Add this host controller to the list of enumerated
                // host controllers.
                //
                InsertTailList(&EnumeratedHCListHead,
                               &hcInfo->ListEntry);

                // Get the name of the root hub for this host
                // controller and then enumerate the root hub.
                //
                rootHubName = GetRootHubName(hHCDev);

                if (rootHubName != NULL)
                {
                    if (EnumerateHub(hHCItem,
                                 rootHubName,
                                 NULL,     // ConnectionInfo
                                 NULL,     // ConfigDesc
                                 NULL,     // StringDescs
                                 _T("RootHub") // DeviceDesc
                                ) == FALSE)
                    {
                        FREE(rootHubName);
                    }
                }
                else
                {
                    // Failure obtaining root hub name.

                    OOPS();
                }
            }
            else
            {
                // Failure adding host controller to USB device tree
                // view.

                OOPS();

                FREE(driverKeyName);
                FREE(hcInfo);
            }
        }
        else
        {
            // Failure obtaining driver key name.

            OOPS();

            FREE(hcInfo);
        }
    }
}
Hängen bleibe ich nun hier:
Code:
  ...
  listEntry = EnumeratedHCListHead.Flink;
  while (listEntry != &EnumeratedHCListHead)
  ...
Wie müsste ich das angehen?

Danke.


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:34 Uhr.

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