線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:4234
推到 Plurk!
推到 Facebook!

有關USB GUID的問題

尚未結案
kelvin00929
一般會員


發表:6
回覆:6
積分:2
註冊:2004-04-22

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-05-07 21:08:22 IP:61.220.xxx.xxx 未訂閱
請問一下 我按照msdn上寫應用程序的步驟在windows 2000下執行: 1)HidD_GetHidGuid 得到guid: 4d1e55b2-f16f-11cf-88cb001111000030 , 然後用guid作為參數在SetupDiGetClassDevs 函數裡面使用: SetupDiGetClassDevs(classguid, NULL, NULL, DIGCF_PRESENT|DIGCF_INTERFACEDEVICE ) 而函數返回不是INVALID_HANDLE_VALUE ,但是為其他的錯誤, 用GetLastError發現,error code是997,內容是 “Overlapped I/O operation is in progress” 為什麼會這樣呢? 希望各位大大,能提供方向不吝指教,謝謝
fushiyun2000
一般會員


發表:0
回覆:4
積分:0
註冊:2004-05-16

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-05-27 14:02:54 IP:218.165.xxx.xxx 未訂閱
相關問題請到 www.usblab.idv.tw 發言
axsoft
版主


發表:681
回覆:1056
積分:969
註冊:2002-03-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-05-27 14:51:12 IP:61.218.xxx.xxx 未訂閱
kelvin00929您好:    請試試這個範例:
Unit1.H
//---------------------------------------------------------------------------    #ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include 
#include 
#include 
#include <Forms.hpp>
#include 
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:        // IDE-managed Components
        TListBox *ListBox1;
        TButton *Button1;
        void __fastcall Button1Click(TObject *Sender);
private:        // User declarations
public:                // User declarations
        __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif        Unit1.cpp    //---------------------------------------------------------------------------    #include 
#pragma hdrstop    #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
#pragma argsused
#define MAX_DEV_LEN 1000
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------    int EnumerateDevices(ULONG DeviceIndex, char *ClassName, char *DeviceName)
{
  DWORD RequiredSize = 0;
  GUID *guids;
  HDEVINFO NewDeviceInfoSet;
  SP_DEVINFO_DATA DeviceInfoData;
  DWORD rs;
  DWORD typeP;
  bool res=SetupDiClassGuidsFromNameA(ClassName,
                                      guids,
                                      RequiredSize,
                                      &RequiredSize);
  if(RequiredSize==0){
         //incorrect class name:
         *DeviceName=0;
         return -2;
     }
  if(!res)
     {
         guids=(GUID *)malloc(RequiredSize*sizeof(GUID));
         res=SetupDiClassGuidsFromNameA(ClassName,
                                        guids,
                                        RequiredSize,
                                       &RequiredSize);
         if(!res || RequiredSize==0)
               {
                 //incorrect class name:
                realloc(guids,0);
                *DeviceName=0;
                return -2;
               }
     }
   NewDeviceInfoSet=SetupDiGetClassDevs(guids,
                                        NULL,
                                        NULL,
                                        DIGCF_PRESENT);
   if( NewDeviceInfoSet == INVALID_HANDLE_VALUE )
        if(!res) {
         //device information is unavailable:
                realloc(guids,0);
                *DeviceName=0;
                return -3;
             }            DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
        res=SetupDiEnumDeviceInfo(NewDeviceInfoSet,DeviceIndex,&DeviceInfoData);
        if(!res) {
                //no such device:
                SetupDiDestroyDeviceInfoList(NewDeviceInfoSet);
                realloc(guids,0);
                *DeviceName=0;
                return -1;
            }            if(!SetupDiGetDeviceRegistryPropertyA(NewDeviceInfoSet,&DeviceInfoData,
                        SPDRP_FRIENDLYNAME,&typeP,DeviceName,MAX_DEV_LEN,&rs) )
            {
                res = SetupDiGetDeviceRegistryPropertyA(NewDeviceInfoSet,
                                                        &DeviceInfoData,
                                                        SPDRP_DEVICEDESC,
                                                        &typeP,
                                                        DeviceName,
                                                        MAX_DEV_LEN,
                                                        &rs);
                if(!res){
                         //incorrect device name:
                         SetupDiDestroyDeviceInfoList(NewDeviceInfoSet);
                         realloc(guids,0);
                         *DeviceName=0;
                         return -4;
                     }
             }
        realloc(guids,0);
        return 0;
}    void __fastcall TForm1::Button1Click(TObject *Sender)
{
  char *devices=0;
  char *devicesOEM=0;
  int Index=0;
  devices=(char*)malloc(MAX_DEV_LEN);
  devicesOEM=(char*)malloc(MAX_DEV_LEN);
  while(true)
        {
        int result=EnumerateDevices(Index, "USB", devices);
        Index++;
        if(result == -2)
                {
                  ShowMessage("Incorrect name of Class GPIB");
                  break;
                }
        if(result == -1)break;
        if(result == 0)
               {
                CharToOem(devices,devicesOEM);
                ListBox1->Items->Add(devicesOEM);
               }
        }
        realloc(devices,0);
        realloc(devicesOEM,0);
       // return 0;
}
//---------------------------------------------------------------------------
/*生活是一種藝術,用心生活享受生活*/
發表人 - axsoft 於 2004/05/27 14:58:47
系統時間:2024-04-19 22:40:48
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!