ntdll: Use cpu_info to check for AVX availability.
[wine/zf.git] / dlls / user32 / winhelp.c
blob2b4ca5b89b56ccfc15a36e6c1e5d0cc24f8a01af
1 /*
2 * Windows Help
4 * Copyright 1996 Martin von Loewis
5 * 2002 Eric Pouech
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdlib.h>
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <string.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "winnls.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(win);
36 /* Wine doesn't use the way WinHelp API sends information in Windows, because:
37 * 1/ it's not consistent across Win9x, NT...
38 * 2/ NT implementation is not yet fully understood (and includes some shared
39 * memory mechanism)
40 * 3/ uses a dynamically allocated message number (WM_WINHELP), which
41 * obfuscates the code
43 * So we use (for now) the simple protocol:
44 * 1/ it's based on copy data
45 * 2/ we tag the message with a magic number, to make it a bit more robust
46 * (even if it's not 100% safe)
47 * 3/ data structure (WINHELP) has the same layout that the one used on Win95.
48 * This doesn't bring much, except not going to far away from real
49 * implementation.
51 * This means anyway that native winhelp.exe and winhlp32.exe cannot be
52 * called/manipulated from WinHelp API.
54 typedef struct
56 WORD size;
57 WORD command;
58 LONG data;
59 LONG reserved;
60 WORD ofsFilename;
61 WORD ofsData;
62 } WINHELP;
64 /* magic number for this message:
65 * aide means help is French ;-)
66 * SOS means ???
68 #define WINHELP_MAGIC 0xA1DE505
70 /**********************************************************************
71 * WinHelpA (USER32.@)
73 BOOL WINAPI WinHelpA( HWND hWnd, LPCSTR lpHelpFile, UINT wCommand, ULONG_PTR dwData )
75 COPYDATASTRUCT cds;
76 HWND hDest;
77 int size, dsize, nlen;
78 WINHELP* lpwh;
79 LRESULT ret;
81 hDest = FindWindowA("MS_WINHELP", NULL);
82 if (!hDest)
84 if (wCommand == HELP_QUIT) return TRUE;
85 if (WinExec("winhlp32.exe -x", SW_SHOWNORMAL) < 32)
87 ERR("can't start winhlp32.exe -x ?\n");
88 return FALSE;
90 if (!(hDest = FindWindowA("MS_WINHELP", NULL)))
92 FIXME("Did not find a MS_WINHELP Window\n");
93 return FALSE;
97 switch (wCommand)
99 case HELP_CONTEXT:
100 case HELP_SETCONTENTS:
101 case HELP_CONTENTS:
102 case HELP_CONTEXTPOPUP:
103 case HELP_FORCEFILE:
104 case HELP_HELPONHELP:
105 case HELP_FINDER:
106 case HELP_QUIT:
107 dsize = 0;
108 break;
109 case HELP_KEY:
110 case HELP_PARTIALKEY:
111 case HELP_COMMAND:
112 dsize = dwData ? strlen((LPSTR)dwData) + 1 : 0;
113 break;
114 case HELP_MULTIKEY:
115 dsize = ((LPMULTIKEYHELPA)dwData)->mkSize;
116 break;
117 case HELP_SETWINPOS:
118 dsize = ((LPHELPWININFOA)dwData)->wStructSize;
119 break;
120 default:
121 FIXME("Unknown help command %d\n", wCommand);
122 return FALSE;
124 if (lpHelpFile)
125 nlen = strlen(lpHelpFile) + 1;
126 else
127 nlen = 0;
128 size = sizeof(WINHELP) + nlen + dsize;
130 lpwh = HeapAlloc(GetProcessHeap(), 0, size);
131 if (!lpwh) return FALSE;
133 cds.dwData = WINHELP_MAGIC;
134 cds.cbData = size;
135 cds.lpData = (void*)lpwh;
137 lpwh->size = size;
138 lpwh->command = wCommand;
139 lpwh->data = dwData;
140 if (nlen)
142 strcpy(((char*)lpwh) + sizeof(WINHELP), lpHelpFile);
143 lpwh->ofsFilename = sizeof(WINHELP);
144 } else
145 lpwh->ofsFilename = 0;
146 if (dsize)
148 memcpy(((char*)lpwh) + sizeof(WINHELP) + nlen, (LPSTR)dwData, dsize);
149 lpwh->ofsData = sizeof(WINHELP) + nlen;
150 } else
151 lpwh->ofsData = 0;
152 TRACE("Sending[%u]: cmd=%u data=%08x fn=%s\n",
153 lpwh->size, lpwh->command, lpwh->data,
154 lpwh->ofsFilename ? (LPSTR)lpwh + lpwh->ofsFilename : "");
156 ret = SendMessageA(hDest, WM_COPYDATA, (WPARAM)hWnd, (LPARAM)&cds);
157 HeapFree(GetProcessHeap(), 0, lpwh);
158 return ret;
162 /**********************************************************************
163 * WinHelpW (USER32.@)
165 BOOL WINAPI WinHelpW( HWND hWnd, LPCWSTR helpFile, UINT command, ULONG_PTR dwData )
167 INT len;
168 LPSTR file;
169 BOOL ret = FALSE;
171 if (!helpFile) return WinHelpA( hWnd, NULL, command, dwData );
173 len = WideCharToMultiByte( CP_ACP, 0, helpFile, -1, NULL, 0, NULL, NULL );
174 if ((file = HeapAlloc( GetProcessHeap(), 0, len )))
176 WideCharToMultiByte( CP_ACP, 0, helpFile, -1, file, len, NULL, NULL );
177 ret = WinHelpA( hWnd, file, command, dwData );
178 HeapFree( GetProcessHeap(), 0, file );
180 return ret;