<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[CreateFile bei HID kommunikation schlägt fehl]]></title><description><![CDATA[<p>Hi ich habe bereits versucht in einem alten Thread eine die selbe Frage zu stellen leider bis jetzt ohne erfolg. Deshalb vesuch ich hier nochmal mein glück da ich echt nicht weiterkomme zu zeit.</p>
<p>ich habe ein HID gerät welches auch von Windows richtig erkannt wird.<br />
nun hab ich mich bei der progamierung an das buch von Jan Axelson und einen Thread hier aus dem Forum gehalten und es funktioniert auch alles so wie es soll bis ich an die stelle kommen wo ich mit CreateFile einen Handle auf das Device aufmachen will. Dabei bekommen ich immer ein ERROR_ACCESS_DENIED</p>
<p>Hier mal der C-Code vielleicht kann mir jemand helfen.</p>
<p>danke</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;winerror.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;ddk/hidsdi.h&gt;
#include &lt;ddk/hidpi.h&gt;
#include &lt;ddk/hidusage.h&gt;
#include &lt;setupapi.h&gt;

int main()
{
    PSP_DEVICE_INTERFACE_DETAIL_DATA pspdidd;
    SP_DEVICE_INTERFACE_DATA         spdid;
    SP_DEVINFO_DATA                  spdd;
    HDEVINFO                         hDevInfo;
    DWORD                            dwIndex, dwSize, dwType;
    TCHAR                            szProperty[256];
    GUID                             guid;
    HANDLE                           DeviceHandle;
    HIDD_ATTRIBUTES                  Attributes;
    PHIDP_PREPARSED_DATA             PreparsedData;
    HIDP_CAPS                        Capabilities;
    char                             InputReport[800];
    unsigned long                    numBytesReturned;

    dwIndex = 0;
    spdid.cbSize = sizeof(spdid);
    HidD_GetHidGuid(&amp;guid);
    printf(&quot;\n1. %d&quot;,GetLastError());
    hDevInfo = SetupDiGetClassDevs(&amp;guid,NULL,NULL,DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
    printf(&quot;\n2. %d&quot;,GetLastError());
    if(hDevInfo == INVALID_HANDLE_VALUE)
    {
        printf(&quot;SetupDiGetClassDevs failed, Error %u\n&quot;, GetLastError());
        return(FALSE);
    }

    SetupDiEnumDeviceInterfaces(hDevInfo,NULL,&amp;guid,dwIndex,&amp;spdid);
    printf(&quot;\n3. %d&quot;,GetLastError());
    dwSize = 0;

    SetupDiGetDeviceInterfaceDetail(hDevInfo,&amp;spdid,NULL,0,&amp;dwSize,NULL);
    printf(&quot;\n4. %d&quot;,GetLastError());

    if(dwSize)
    {
        pspdidd = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(dwSize);

        pspdidd-&gt;cbSize = sizeof(*pspdidd);
        spdd.cbSize = sizeof(spdd);

        if(SetupDiGetDeviceInterfaceDetail(hDevInfo,&amp;spdid,pspdidd,dwSize,&amp;dwSize,&amp;spdd))
        {
            printf(&quot;\n5. %d&quot;,GetLastError());
            printf(&quot;Name fuer CreateFile(): %s&quot;, pspdidd-&gt;DevicePath);

            if(SetupDiGetDeviceRegistryProperty(hDevInfo,&amp;spdd,SPDRP_FRIENDLYNAME,&amp;dwType,(PBYTE)szProperty,sizeof(szProperty),NULL))
            {
                printf(&quot;\n6. %d&quot;,GetLastError());
                if(dwType == REG_SZ)
                    printf(&quot;FriendlyName: %s\n&quot;, szProperty);
            }
            if(SetupDiGetDeviceRegistryProperty(hDevInfo,&amp;spdd,SPDRP_DEVICEDESC,&amp;dwType,(PBYTE)szProperty,sizeof(szProperty),NULL))
            {
                printf(&quot;\n7. %d&quot;,GetLastError());
                if(dwType == REG_SZ)
                    printf(&quot;DeviceDescription: %s&quot;, szProperty);
            }
        }

    }
    SetupDiDestroyDeviceInfoList(hDevInfo);
    DeviceHandle = CreateFile((LPCTSTR)pspdidd-&gt;DevicePath,GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,NULL);
    printf(&quot;\n8. %d&quot;,GetLastError());
    HidD_GetAttributes(DeviceHandle,&amp;Attributes);
    printf(&quot;\n9. %d&quot;,GetLastError());

//  printf(&quot; %d&quot;,GetLastError());
//  printf(&quot;\nVendorID : %X&quot;,Attributes.VendorID);
//  printf(&quot;\nProductID: %X&quot;,Attributes.ProductID);
//  printf(&quot;\nVersion  : %X&quot;,Attributes.VersionNumber);
//  HidD_GetPreparsedData(DeviceHandle,&amp;PreparsedData);
//  printf(&quot; %d&quot;,GetLastError());
//  HidP_GetCaps(PreparsedData,&amp;Capabilities);
//  ReadFile(DeviceHandle,InputReport,Capabilities.InputReportByteLength,&amp;numBytesReturned,NULL);*/
    return(0);
}
</code></pre>
<p>gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/193375/createfile-bei-hid-kommunikation-schlägt-fehl</link><generator>RSS for Node</generator><lastBuildDate>Tue, 30 Jun 2026 17:28:19 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/193375.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 25 Sep 2007 16:11:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to CreateFile bei HID kommunikation schlägt fehl on Tue, 25 Sep 2007 16:11:10 GMT]]></title><description><![CDATA[<p>Hi ich habe bereits versucht in einem alten Thread eine die selbe Frage zu stellen leider bis jetzt ohne erfolg. Deshalb vesuch ich hier nochmal mein glück da ich echt nicht weiterkomme zu zeit.</p>
<p>ich habe ein HID gerät welches auch von Windows richtig erkannt wird.<br />
nun hab ich mich bei der progamierung an das buch von Jan Axelson und einen Thread hier aus dem Forum gehalten und es funktioniert auch alles so wie es soll bis ich an die stelle kommen wo ich mit CreateFile einen Handle auf das Device aufmachen will. Dabei bekommen ich immer ein ERROR_ACCESS_DENIED</p>
<p>Hier mal der C-Code vielleicht kann mir jemand helfen.</p>
<p>danke</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;winerror.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;ddk/hidsdi.h&gt;
#include &lt;ddk/hidpi.h&gt;
#include &lt;ddk/hidusage.h&gt;
#include &lt;setupapi.h&gt;

int main()
{
    PSP_DEVICE_INTERFACE_DETAIL_DATA pspdidd;
    SP_DEVICE_INTERFACE_DATA         spdid;
    SP_DEVINFO_DATA                  spdd;
    HDEVINFO                         hDevInfo;
    DWORD                            dwIndex, dwSize, dwType;
    TCHAR                            szProperty[256];
    GUID                             guid;
    HANDLE                           DeviceHandle;
    HIDD_ATTRIBUTES                  Attributes;
    PHIDP_PREPARSED_DATA             PreparsedData;
    HIDP_CAPS                        Capabilities;
    char                             InputReport[800];
    unsigned long                    numBytesReturned;

    dwIndex = 0;
    spdid.cbSize = sizeof(spdid);
    HidD_GetHidGuid(&amp;guid);
    printf(&quot;\n1. %d&quot;,GetLastError());
    hDevInfo = SetupDiGetClassDevs(&amp;guid,NULL,NULL,DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
    printf(&quot;\n2. %d&quot;,GetLastError());
    if(hDevInfo == INVALID_HANDLE_VALUE)
    {
        printf(&quot;SetupDiGetClassDevs failed, Error %u\n&quot;, GetLastError());
        return(FALSE);
    }

    SetupDiEnumDeviceInterfaces(hDevInfo,NULL,&amp;guid,dwIndex,&amp;spdid);
    printf(&quot;\n3. %d&quot;,GetLastError());
    dwSize = 0;

    SetupDiGetDeviceInterfaceDetail(hDevInfo,&amp;spdid,NULL,0,&amp;dwSize,NULL);
    printf(&quot;\n4. %d&quot;,GetLastError());

    if(dwSize)
    {
        pspdidd = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(dwSize);

        pspdidd-&gt;cbSize = sizeof(*pspdidd);
        spdd.cbSize = sizeof(spdd);

        if(SetupDiGetDeviceInterfaceDetail(hDevInfo,&amp;spdid,pspdidd,dwSize,&amp;dwSize,&amp;spdd))
        {
            printf(&quot;\n5. %d&quot;,GetLastError());
            printf(&quot;Name fuer CreateFile(): %s&quot;, pspdidd-&gt;DevicePath);

            if(SetupDiGetDeviceRegistryProperty(hDevInfo,&amp;spdd,SPDRP_FRIENDLYNAME,&amp;dwType,(PBYTE)szProperty,sizeof(szProperty),NULL))
            {
                printf(&quot;\n6. %d&quot;,GetLastError());
                if(dwType == REG_SZ)
                    printf(&quot;FriendlyName: %s\n&quot;, szProperty);
            }
            if(SetupDiGetDeviceRegistryProperty(hDevInfo,&amp;spdd,SPDRP_DEVICEDESC,&amp;dwType,(PBYTE)szProperty,sizeof(szProperty),NULL))
            {
                printf(&quot;\n7. %d&quot;,GetLastError());
                if(dwType == REG_SZ)
                    printf(&quot;DeviceDescription: %s&quot;, szProperty);
            }
        }

    }
    SetupDiDestroyDeviceInfoList(hDevInfo);
    DeviceHandle = CreateFile((LPCTSTR)pspdidd-&gt;DevicePath,GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,NULL);
    printf(&quot;\n8. %d&quot;,GetLastError());
    HidD_GetAttributes(DeviceHandle,&amp;Attributes);
    printf(&quot;\n9. %d&quot;,GetLastError());

//  printf(&quot; %d&quot;,GetLastError());
//  printf(&quot;\nVendorID : %X&quot;,Attributes.VendorID);
//  printf(&quot;\nProductID: %X&quot;,Attributes.ProductID);
//  printf(&quot;\nVersion  : %X&quot;,Attributes.VersionNumber);
//  HidD_GetPreparsedData(DeviceHandle,&amp;PreparsedData);
//  printf(&quot; %d&quot;,GetLastError());
//  HidP_GetCaps(PreparsedData,&amp;Capabilities);
//  ReadFile(DeviceHandle,InputReport,Capabilities.InputReportByteLength,&amp;numBytesReturned,NULL);*/
    return(0);
}
</code></pre>
<p>gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1372517</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1372517</guid><dc:creator><![CDATA[Neo120484]]></dc:creator><pubDate>Tue, 25 Sep 2007 16:11:10 GMT</pubDate></item><item><title><![CDATA[Reply to CreateFile bei HID kommunikation schlägt fehl on Wed, 26 Sep 2007 09:17:15 GMT]]></title><description><![CDATA[<p>Bist du dir sicher das er alles vorher Korrekt ausgeführt hat (wenn dwSize = 0 ist bekommst du keine Ausgabe)</p>
<p>Ach habe spdd noch auf 0 gestetzt bevor ich SetupDiGEtDeviceInterfaceDetail aufrufe</p>
<pre><code class="language-cpp">pspdidd-&gt;cbSize = sizeof(*pspdidd);
ZeroMemory((PVOID)&amp;spdd, sizeof(spdd)); 
spdd.cbSize = sizeof(spdd);
if(SetupDiGetDeviceInterfaceDetail(hDevInfo, &amp;spdid, pspdidd, dwSize, &amp;dwSize, &amp;spdd))
{
//get the name of the device for CreateFile
h = CreateFile(pspdidd-&gt;DevicePath, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
HIDAttributes.Size = sizeof(HIDD_ATTRIBUTES);
HidD_GetAttributes(h, &amp;HIDAttributes);
...
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1372900</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1372900</guid><dc:creator><![CDATA[Destiniy]]></dc:creator><pubDate>Wed, 26 Sep 2007 09:17:15 GMT</pubDate></item><item><title><![CDATA[Reply to CreateFile bei HID kommunikation schlägt fehl on Wed, 26 Sep 2007 10:23:12 GMT]]></title><description><![CDATA[<p>Ha die Lösung des Problems mitlerweile raus. Unter win2000/XP ist der zugriff auf HID Tastaturen und Mäuse nicht erlaubt und da ich anfänglich mein Gerät als Tastatur enumeriert habe ging das nicht..</p>
<p>jetzt hängt sich mitlerweile allerdings leider der ReadFile aufruf auf (blockiert) bzw. beendet mit einem Fehler weil er keine Daten bekommt.</p>
<p>Komisch ist wenn ich mir einen USB sniffer nehme werden in kontinuierlich in einem interrupt-transfer 4 Byte daten zum Host übertragen (die daten stimmen auch die übertragen werden.)</p>
<p>ich dachte der Host speichter die Daten einfach in seinem Puffer und ich als nutzer muss die dann nur noch mittels Readfile aus dem Puffer lesen.</p>
<pre><code class="language-cpp">HidD_FreePreparsedData(PreparsedData);
    printf(&quot;\n12. %d&quot;,GetLastError());

    InputReport = (DWORD*) malloc(Capabilities.InputReportByteLength);

    hEventObject = CreateEvent(NULL,TRUE,TRUE,&quot;&quot;);
    printf(&quot;\n13. %d&quot;,GetLastError());
    s_overlapped.hEvent = hEventObject;
    s_overlapped.Offset = 0;
    s_overlapped.OffsetHigh = 0;

    ReadFile(DeviceHandle,InputReport,Capabilities.InputReportByteLength,&amp;numBytesReturned,(LPOVERLAPPED)&amp;s_overlapped);
</code></pre>
<p>gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1372949</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1372949</guid><dc:creator><![CDATA[Neo120484]]></dc:creator><pubDate>Wed, 26 Sep 2007 10:23:12 GMT</pubDate></item><item><title><![CDATA[Reply to CreateFile bei HID kommunikation schlägt fehl on Wed, 26 Sep 2007 13:00:46 GMT]]></title><description><![CDATA[<p>du solltest beim event manual reset ausschalten.</p>
<p>Dann in einer schleife:<br />
- auf das event mit WaitForSingleObject warten<br />
- die Daten mit GetOverlappedResult holen<br />
- ReadFile aufrufen</p>
<p>beim ersten mal sind noch keine Daten vorhanden aber das event ist gestzt. D.h. es wird nur readfile gestartet.</p>
<p>MfG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1373103</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1373103</guid><dc:creator><![CDATA[Destiniy]]></dc:creator><pubDate>Wed, 26 Sep 2007 13:00:46 GMT</pubDate></item></channel></rss>