Danke für die schnelle Reaktion.
Code: Alles auswählen
class CAnelUSBCtrl : public COleDispatchDriver
{
// Operationen
public:
short get_DevCount()
{
short result;
InvokeHelper(0x68030000, DISPATCH_PROPERTYGET, VT_I2, (void*)&result, NULL);
return result;
}
CString DevName(short * Device)
{
CString result;
static BYTE parms[] = VTS_PI2 ;
InvokeHelper(0x60030001, DISPATCH_METHOD, VT_BSTR, (void*)&result, parms, Device);
return result;
}
short DevType(short * Device)
{
short result;
static BYTE parms[] = VTS_PI2 ;
InvokeHelper(0x60030002, DISPATCH_METHOD, VT_I2, (void*)&result, parms, Device);
return result;
}
BOOL DevSel(short * Device)
{
BOOL result;
static BYTE parms[] = VTS_PI2 ;
InvokeHelper(0x60030003, DISPATCH_METHOD, VT_BOOL, (void*)&result, parms, Device);
return result;
}
short DevState(short * Device)
{
short result;
static BYTE parms[] = VTS_PI2 ;
InvokeHelper(0x60030004, DISPATCH_METHOD, VT_I2, (void*)&result, parms, Device);
return result;
}
short SwOn(short * Device, short * Segment)
{
short result;
static BYTE parms[] = VTS_PI2 VTS_PI2 ;
InvokeHelper(0x60030005, DISPATCH_METHOD, VT_I2, (void*)&result, parms, Device, Segment);
return result;
}
short SwOff(short * Device, short * Segment)
{
short result;
static BYTE parms[] = VTS_PI2 VTS_PI2 ;
InvokeHelper(0x60030006, DISPATCH_METHOD, VT_I2, (void*)&result, parms, Device, Segment);
return result;
}
void Init()
{
InvokeHelper(0x60030007, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
}
};
// Hier kommt der Code zum ein/aus-schalten
CLSID const clsid
= { 0xA1EBE7D0, 0x3EBD, 0x438A, { 0xA4, 0xDC, 0xC9, 0x97, 0xDB, 0x7A, 0xE, 0xFE } };
IID iid
= { 0x475411FA, 0x5189, 0x405D, { 0x98, 0x92, 0x16, 0x79, 0xCF, 0x5C, 0x18, 0xCB } };
LPVOID iface = NULL;
HRESULT hr = CoCreateInstance(clsid,
NULL,
CLSCTX_INPROC_SERVER,
iid,
&iface);
if(hr!=S_OK)
{
SRESV("Unable to instantiate COM object. Is the control installed and registered?");
break;
}
CAnelUSBCtrl ctl;
ctl.AttachDispatch((LPDISPATCH) iface);
ctl.Init();
short dev = 0, seg = slot;
short res = 0;
if(on)
{
res = ctl.SwOn(&dev,&seg);
}
else
{
res = ctl.SwOff(&dev,&seg);
}
ctl.DetachDispatch();
((IUnknown*)iface)->Release();