如何从 IFileDialogCustomize GetEditBoxText() 中获取字符串 在 C# 中
How to get string from IFileDialogCustomize GetEditBoxText() in C#
我正在尝试使用COM调用在C#中使用IFileDialogCustom接口。我有对GetEditBoxText(id,buffer)的调用定义为:
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
HRESULT GetEditBoxText([In] int dwIDCtl, [Out] IntPtr ppszText);
我从 https://msdn.microsoft.com/en-us/library/windows/desktop/bb775908(v=vs.85)得到的.aspx
我编写的代码是:
IntPtr buffer = Marshal.AllocCoTaskMem(sizeof(int));
string textboxString;
var customizeDialog = GetFileDialog() as IFileDialogCustomize;
if (customizeDialog != null)
{
HRESULT result = customizeDialog.GetEditBoxText(id, buffer);
if (result != HRESULT.S_OK)
{
throw new Exception("Couldn't parse string from textbox");
}
}
textboxString = Marshal.PtrToStringUni(buffer);
Marshal.FreeCoTaskMem(buffer);
return textboxString;
该字符串始终返回奇数字符,例如 벰∔。
我是使用 Com 接口的新手,从未做过C++编程,所以我在这里有点迷茫。为什么我没有从这里的文本框中获取实际字符串?
我想通了。这是雅各布所说的话和改变Com电话签名的结合。而不是
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
void GetEditBoxText([In] int dwIDCtl, [Out] IntPtr ppszText);
我需要签名:
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
HRESULT GetEditBoxText([In] int dwIDCtl, out IntPtr ppszText);
这实际上正确地传递了 IntPtr,我能够使用
Marshal.PtrToStringUni(buffer);
相关文章:
- 获取字符串的长度并将其分配给数组
- 调用CreateProcess()并获取字符串的返回值
- 你如何从 Boost Spirit X3 词法解析器中获取字符串?
- 使用 ReadProcessMemory 获取字符串值的访问冲突
- 如何从输入中获取字符串向量?
- 如何获取字符串输入n次?
- property_tree获取字符串形式的数组值
- 使用 ctypes 和 wchar_t 时如何从 C++ 获取字符串到 python?
- 获取字符串大小的各种方法之间的比较
- 方法获取字符串
- 在getline()之后获取字符串
- 为什么我的拆卸C 代码使用指令指针和偏移来获取字符串文字
- 无法使用 Poco 获取字符串的路径
- 如何在qtablewidget中获取字符串的行号
- 如何获取字符串和字节进行比较
- 恒定字符阵列的获取字符串长度函数(strlen)不是恒定表达式
- 我需要创建一个函数来获取字符串中的这些数字
- 如何从地址获取字符串?
- 为什么即使尚未初始化,获取字符串[0]也是有效的?
- 获取C++字符串的位