前提・実現したいこと
C#(.NET Framework 4.6.2)から、Windows API HtmlHelp を、コマンド:HH_GET_WIN_TYPE で実行して、HH_WINTYPE 構造体を取得したい
発生している問題・エラーメッセージ
以下のコードを実行後、
var ret = NativeMethods.HtmlHelp(hWndCaller, helpFilePath, command, hWinType);
Win32 SetLastError 関数から、以下エラーメッセージがでて、正常にHH_WINTYPE構造体を取得できません。
122:システム コールに渡されるデータ領域が小さすぎます
該当のソースコード
DllImportの定義
C#
1[DllImport(ExternDll.Hhctrl, SetLastError = true, EntryPoint = HtmlHelpEntryPoint, CharSet = CharSet.Unicode)] 2public static extern int HtmlHelp(HWND hwndCaller, [MarshalAs(UnmanagedType.LPWStr)]string pszFile, HTMLHelpCommand uCommand, [In][Out]HH_WINTYPE dwData);
HTMLHelpCommandの定義
C#
1[Flags()] 2public enum HTMLHelpCommand : uint 3{ 4 HH_DISPLAY_TOPIC = 0x0000, 5 HH_DISPLAY_TOC = 0x0001, 6 HH_DISPLAY_INDEX = 0x0002, 7 HH_DISPLAY_SEARCH = 0x0003, 8 HH_SET_WIN_TYPE = 0x0004, 9 HH_GET_WIN_TYPE = 0x0005, 10 HH_GET_WIN_HANDLE = 0x0006, 11 HH_DISPLAY_TEXT_POPUP = 0x000E, 12 HH_HELP_CONTEXT = 0x000F, 13 HH_CLOSE_ALL = 0x0012, 14 HH_GET_LAST_ERROR = 0x0014, 15 HH_INITIALIZE = 0x001C, 16 HH_UNINITIALIZE = 0x001D, 17 HH_PRETRANSLATEMESSAGE = 0x00FD 18}
HH_WINTYPE の定義
C#
1[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] 2public class HH_WINTYPE 3{ 4 internal int cbStruct = Marshal.SizeOf(typeof(HH_WINTYPE)); 5 internal bool fUniCodeStrings; 6 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] 7 internal string pszType; 8 internal uint fsValidMembers; 9 internal uint fsWinProperties; 10 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] 11 internal string pszCaption; 12 internal uint dwStyles; 13 internal uint dwExStyles; 14 internal Win32.RECT rcWindowPos = Win32.RECT.FromXYWH(-1, -1, -1, -1); 15 internal int nShowState; 16 internal IntPtr hwndHelp; 17 internal IntPtr hwndCaller; 18 internal IntPtr hwndToolBar; 19 internal IntPtr hwndNavigation; 20 internal IntPtr hwndHTML ; 21 internal int iNavWidth; 22 internal Win32.RECT rcHTML = Win32.RECT.FromXYWH(-1, -1, -1, -1); 23 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] 24 internal string pszToc; 25 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] 26 internal string pszIndex; 27 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] 28 internal string pszFile; 29 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] 30 internal string pszHome; 31 internal uint fsToolBarFlags; 32 internal bool fNotExpanded; 33 internal int curNavType; 34 internal int idNotify; 35 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] 36 internal string pszJump1; 37 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] 38 internal string pszJump2; 39 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] 40 internal string pszUrlJump1; 41 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] 42 internal string pszUrlJump2; 43}
HTMLHelp APIの呼び出し
C#
1var command = NativeMethods.HTMLHelpCommand.HH_GET_WIN_TYPE; 2var hWinType = new NativeMethods.HH_WINTYPE(); 3var ret = NativeMethods.HtmlHelp(hWndCaller, helpFilePath, command, hWinType); 4 5var errCode = Marshal.GetLastWin32Error(); 6Debug.Print($"HH_GET_WIN_TYPE errCode: {errCode}");
補足情報(FW/ツールのバージョンなど)
C#(.NET Framework 4.6.2)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/07/07 09:57
2020/07/07 11:48
2020/07/07 12:09
2020/07/08 02:14
2020/07/08 02:31
2020/07/08 11:54
2024/08/31 18:14 編集
2020/07/09 01:18
2020/07/09 04:38