Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从C#中的程序设置或INI(自定义类)加载十六进制值作为int?_C#_Winapi - Fatal编程技术网

如何从C#中的程序设置或INI(自定义类)加载十六进制值作为int?

如何从C#中的程序设置或INI(自定义类)加载十六进制值作为int?,c#,winapi,C#,Winapi,我正在使用C#应用程序监视另一个程序,当检测到不活动时,只需单击一个按钮 我用的是Pinvoke,效果很好。我的问题是从十六进制格式的INI加载按钮控件ID。inif只是读取十六进制字符串(“000003F2”)的INI文件 现在我需要这个来处理以下内容 [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] static extern IntPtr GetDlgItem(IntPtr hWnd, int nI

我正在使用C#应用程序监视另一个程序,当检测到不活动时,只需单击一个按钮

我用的是Pinvoke,效果很好。我的问题是从十六进制格式的INI加载按钮控件ID。inif只是读取十六进制字符串(“000003F2”)的INI文件

现在我需要这个来处理以下内容

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern IntPtr GetDlgItem(IntPtr hWnd, int nIDDlgItem);

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, IntPtr lParam);

//Click Button
IntPtr hWndButton = GetDlgItem(m_handle, m_button_id);
int wParam = (BN_CLICKED << 16) | (m_button_id & 0xffff);
SendMessage(m_handle, WM_COMMAND, wParam, hWndButton);
使用
Convert.ToInt32(十六进制字符串,16)


或者
int.Parse(hexString,System.Globalization.NumberStyles.HexNumber)

我真不敢相信我错过了。谢谢你的回答!引发异常:System.dll中的“System.ComponentModel.Win32Exception”-我得到这个,它不会将十六进制加载到int。它将删除0x并保留任何数字。但是,如果字符串包含十六进制字母,它将抛出如上所述的异常。错误(行)在哪里,输入数据在哪里?
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern IntPtr GetDlgItem(IntPtr hWnd, int nIDDlgItem);

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, IntPtr lParam);

//Click Button
IntPtr hWndButton = GetDlgItem(m_handle, m_button_id);
int wParam = (BN_CLICKED << 16) | (m_button_id & 0xffff);
SendMessage(m_handle, WM_COMMAND, wParam, hWndButton);
public int m_button_id = 0x3F2;