Reputation: 4847
I'm trying to list all WIA devices with C++/CLI. I'm fairly new to C++/CLI (although I consider myself an intermediate C++ programmer), but I keep getting this error:
error C2664: 'WIA::IDeviceInfos::default::get' : cannot convert parameter 1 from 'int' to 'System::Object ^%'
when using the following code snippet:
DeviceManager^ dm = (gcnew WIA::DeviceManager());
for (int i = 1; i <= dm->DeviceInfos->Count; i++)
{
String^ deviceName = dm->DeviceInfos[i].Properties("Name")->get_Value()->ToString();
this->devices->Items->Add(deviceName);
}
Why should I treat that int as an Object? In Managed C++ there was the concept of boxing, but it doesn't work here and anyway I thought C++/CLI was introduced in order to get rid of it?
Upvotes: 0
Views: 349
Reputation: 3874
The Value property needs some non-obvious code to get it out. Try this:
WIA::DeviceInfo ^ info = dm->DeviceInfos[gcnew System::Int32(i)];
WIA::Property ^ propName = info->Properties[gcnew System::String(L"Name")];
String ^ strName = propName->default->ToString();
Upvotes: 0