-
April 1st, 2018, 11:08 PM
#1
Convert From C# VS2010 - get_Item & set_Value in C++/CLI
Hi,
I wish to convert from c# for the following codes contain get_Item & set_Value convertion in C++/Cli.
Code:
private static void SetWIAProperty(IProperties properties, object propName, object propValue)
{
Property prop = properties.get_Item(ref propName);
prop.set_Value(ref propValue);
}
Any guidences will be helpful.
Thanks
-
April 4th, 2018, 04:45 PM
#2
Re: Convert From C# VS2010 - get_Item & set_Value in C++/CLI
How (and where) are IProperties and Property defined? They do not seem to be part of the .NET framework.
Can you post the original C# code you are translating?
I can't remember any scenario, where application code explicitly calls these "generic" property accessors. However, assuming IProperties has a property Item, presumably of type Object ^, the accessor signatures would be Object ^IProperty::Item::get() and void IProperty::Item::set(Object ^value), if I recall correctly. In concrete code you would replace IProperty:: by, say, properties-> and pass the appropriate ref class reference (i.e. instance) to the setter. However, I'm not sure that would ever compile in any real-life code.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
-
April 6th, 2018, 03:00 AM
#3
Re: Convert From C# VS2010 - get_Item & set_Value in C++/CLI
Thanks Eri. Until my breath I will be remember your help Mr.Eri. Because All my Visual C++ code behind your helps were there.
Now I am in need to scan the invoice & store it to Access Database. For that I found the following c# code to scan.
Code:
// ADD Reference - COM - Microsoft Windows Image Acquisition Library V2.0 1.0 ;
using WIA;
using System.IO;
using System.Runtime.InteropServices;
private static void AdjustScannerSettings(IItem scannnerItem, int scanResolutionDPI, int scanStartLeftPixel, int scanStartTopPixel, int scanWidthPixels, int scanHeightPixels, int brightnessPercents, int contrastPercents, int colorMode)
{
const string WIA_SCAN_COLOR_MODE = "6146";
const string WIA_HORIZONTAL_SCAN_RESOLUTION_DPI = "6147";
const string WIA_VERTICAL_SCAN_RESOLUTION_DPI = "6148";
const string WIA_HORIZONTAL_SCAN_START_PIXEL = "6149";
const string WIA_VERTICAL_SCAN_START_PIXEL = "6150";
const string WIA_HORIZONTAL_SCAN_SIZE_PIXELS = "6151";
const string WIA_VERTICAL_SCAN_SIZE_PIXELS = "6152";
const string WIA_SCAN_BRIGHTNESS_PERCENTS = "6154";
const string WIA_SCAN_CONTRAST_PERCENTS = "6155";
SetWIAProperty(scannnerItem.Properties, WIA_HORIZONTAL_SCAN_RESOLUTION_DPI, scanResolutionDPI);
SetWIAProperty(scannnerItem.Properties, WIA_VERTICAL_SCAN_RESOLUTION_DPI, scanResolutionDPI);
SetWIAProperty(scannnerItem.Properties, WIA_HORIZONTAL_SCAN_START_PIXEL, scanStartLeftPixel);
SetWIAProperty(scannnerItem.Properties, WIA_VERTICAL_SCAN_START_PIXEL, scanStartTopPixel);
SetWIAProperty(scannnerItem.Properties, WIA_HORIZONTAL_SCAN_SIZE_PIXELS, scanWidthPixels);
SetWIAProperty(scannnerItem.Properties, WIA_VERTICAL_SCAN_SIZE_PIXELS, scanHeightPixels);
SetWIAProperty(scannnerItem.Properties, WIA_SCAN_BRIGHTNESS_PERCENTS, brightnessPercents);
SetWIAProperty(scannnerItem.Properties, WIA_SCAN_CONTRAST_PERCENTS, contrastPercents);
SetWIAProperty(scannnerItem.Properties, WIA_SCAN_COLOR_MODE, colorMode);
}
private static void SetWIAProperty(IProperties properties, object propName, object propValue)
{
Property prop = properties.get_Item(ref propName);
prop.set_Value(ref propValue);
}
private void button3_Click(object sender, EventArgs e)
{
var devicemanager = new DeviceManager();
WIA.DeviceInfo FirstScannerAvailable = null;
for (int j = 1; j <= devicemanager.DeviceInfos.Count; j++)
{
if (devicemanager.DeviceInfos[j].Type != WiaDeviceType.ScannerDeviceType)
{
continue;
}
FirstScannerAvailable = devicemanager.DeviceInfos[j];
break;
}
// Scanner Connection
WIA.Device mydev = FirstScannerAvailable.Connect();
WIA.Item MyScannerItem = mydev.Items[1];
var device = FirstScannerAvailable.Connect();
var scannerItem = device.Items[1];
int resolution = 150;
int width_pixel = 1250;
int height_pixel = 1700;
int color_mode = 1;
AdjustScannerSettings(scannerItem, resolution, 0, 0, width_pixel, height_pixel, 0, 0, color_mode);
// Retrieve a image in JPEG format and store it into a variable
var imagefile = (ImageFile)scannerItem.Transfer(FormatID.wiaFormatJPEG);
var path = @"C:\UMan\Scan1.jpeg";
if (File.Exists(path))
{
File.Delete(path);
}
imagefile.SaveFile(path);
}
Thanks
Last edited by MAHEY; April 6th, 2018 at 03:04 AM.
Reason: To Correct Spelling Mistakes
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|