您的位置:程序门 -> .net技术 -> c#



急急急,在线求助!!


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


急急急,在线求助!![已结贴,结贴人:dsd999]
发表于:2007-03-06 13:57:24 楼主
1)原型
winsetupapi
bool
winapi
setupdisetclassinstallparamsa(
        in   hdevinfo                                 deviceinfoset,
        in   psp_devinfo_data                 deviceinfodata,                 optional
        in   psp_classinstall_header   classinstallparams,         optional
        in   dword                                       classinstallparamssize
        );

[dllimport( "setupapi.dll ",   setlasterror   =   true,   charset   =   charset.auto)]static   extern   bool   setupdisetclassinstallparams(intptr   deviceinfoset,   ref   sp_devinfo_data   deviceinfodata,   ref   sp_classinstall_header   classinstallparams,   int   classinstallparamssize);

2)typedef   struct   _sp_classinstall_header   {
        dword               cbsize;
        di_function   installfunction;
}   sp_classinstall_header,   *psp_classinstall_header;

  [structlayout(layoutkind.sequential)]
                public   struct   sp_classinstall_header
                {
                        public   uint32   cbsize;
                        public   uint   installfunction;
                }

3)typedef   struct   _sp_propchange_params   {
        sp_classinstall_header   classinstallheader;
        dword                                     statechange;
        dword                                     scope;
        dword                                     hwprofile;
}   sp_propchange_params,   *psp_propchange_params;

    [structlayout(layoutkind.sequential)]
                public   struct   sp_propchange_params
                {
                        public   sp_classinstall_header   classinstallheader;
                        public   uint32   statechange;
                        public   uint32   scope;
                        public   uint32   hwprofile;
                }

问题:
1)这几个写法是否有问题?
2)
    sp_propchange_params   sppropchangeparam   =   new   sp_propchange_params();
                        sppropchangeparam.scope   =   0x00000001;
                        sppropchangeparam.statechange   =   0;
                        sppropchangeparam.classinstallheader.cbsize   =   (uint32)system.runtime.interopservices.marshal.sizeof(sppropchangeparam.classinstallheader);
                        sppropchangeparam.classinstallheader.installfunction   =   0x00000012;


                        setupdisetclassinstallparams(newdeviceinfoset,   ref   spdata,   ref   sppropchangeparam.classinstallheader,   system.runtime.interopservices.marshal.sizeof(sppropchangeparam));

调用不成功,getlasterror错误值87(参数不正确),哪里出问题了?
newdeviceinfoset和spdata参数应该没有问题。

谢谢


发表于:2007-03-06 14:30:121楼 得分:20
from
http://www.devmedia.com.br/articles/viewcomp.asp?comp=4092&hl=
先看看别人是怎么用的

public   const   int   digcf_present   =   2;
public   const   int   dif_propertychange   =   0x00000012;
public   const   int   dics_flag_global   =   0x00000001;
public   const   int   invalid_handle_value   =   -1;
public   const   int   dics_enable   =   0x00000001;
public   const   int   dics_disable   =   0x00000002;
public   const   string   usbvidpid   =   @ "usb\vid_0403&pid_6001\a1000pra ";

[structlayout(layoutkind.sequential)]
public   struct   sp_classinstall_header
{
        public   int   cbsize;
        public   int   installfunction;
}

[structlayout(layoutkind.sequential)]
public   struct   sp_propchange_params
{
        public   sp_classinstall_header   classinstallheader;
        public   int   statechange;
        public   int   scope;
        public   int   hwprofile;
        public   void   init()
        {
                classinstallheader   =   new   sp_classinstall_header();
        }
}

[structlayout(layoutkind.sequential)]
public   struct   sp_devinfo_data
{
        public   int   cbsize;
        public   guid   classguid;
        public   int   devinst;
        public   int   reserved;
}

[dllimport( "setupapi.dll ")]
public   static   extern   bool   setupdienumdeviceinfo(
        intptr   deviceinfoset,
        int   supplies,
        ref   sp_devinfo_data   deviceinfodata);

[dllimport( "setupapi.dll ")]
public   static   extern   bool   setupdisetclassinstallparams(
        intptr   deviceinfoset,
        ref   sp_devinfo_data   deviceinfodata,
        ref   sp_classinstall_header   classinstallparams,
        int   classinstallparamssize);

[dllimport( "setupapi.dll ")]
public   static   extern   bool   setupdicallclassinstaller(
        int   installfunction,
        intptr   deviceinfoset,
          ref   sp_devinfo_data   deviceinfodata);

static   bool   statechange(int   newstate,   int   selecteditem,   intptr   hdevinfo)
{
        sp_propchange_params   propchangeparams;
        sp_devinfo_data   deviceinfodata;
        propchangeparams   =   new   sp_propchange_params();
        propchangeparams.init();
        deviceinfodata   =   new   sp_devinfo_data();
        propchangeparams.classinstallheader.cbsize
                =   marshal.sizeof(propchangeparams.classinstallheader);
        deviceinfodata.cbsize   =   marshal.sizeof(deviceinfodata);
        if   (!setupdienumdeviceinfo(hdevinfo,   selecteditem,   ref   deviceinfodata))
                return   false;
       
        propchangeparams.classinstallheader.installfunction   =   dif_propertychange;
        propchangeparams.scope   =   dics_flag_global;
        propchangeparams.statechange   =   newstate;
        if   (!setupdisetclassinstallparams(
                hdevinfo,
                ref   deviceinfodata,
                ref   propchangeparams.classinstallheader,
                (int)marshal.sizeof(propchangeparams)))
                return   false;
        if   (!setupdicallclassinstaller(
                dif_propertychange,
                hdevinfo,
                ref   deviceinfodata))
                return   false;
        return   true;
}
发表于:2007-03-06 16:48:482楼 得分:0
谢谢,问题出在sppropchangeparam.statechange   =   0;

所以返回参数不正确。改成   sppropchangeparam.statechange   =   1;就ok了


快速检索

最新资讯
热门点击