Added a first-cut version of MapVirtualKeyExW() that has the same
[wine] / win32 / init.c
1 /*
2  * Win32 kernel functions
3  *
4  * Copyright 1995 Martin von Loewis and Cameron Heide
5  * 1999 Peter Ganten
6  */
7
8 #include <string.h>
9 #include <unistd.h>
10 #include <stdlib.h>
11 #include "winnls.h"
12 #include "winerror.h"
13 #include "wine/exception.h"
14 #include "heap.h"
15 #include "task.h"
16 #include "debugtools.h"
17
18 DEFAULT_DEBUG_CHANNEL(win32);
19   
20 /* filter for page-fault exceptions */
21 static WINE_EXCEPTION_FILTER(page_fault)
22 {
23     if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION)
24         return EXCEPTION_EXECUTE_HANDLER;
25     return EXCEPTION_CONTINUE_SEARCH;
26 }
27
28 /***********************************************************************
29  *              GetComputerNameA         (KERNEL32.165)
30  */
31 BOOL WINAPI GetComputerNameA(LPSTR name,LPDWORD size)
32 {
33     /* At least Win95OSR2 survives if size is not a pointer (NT crashes though) */
34     BOOL ret;
35     __TRY
36     {
37       ret = (-1!=gethostname(name,*size));
38       if (ret)
39         *size = strlen(name);
40     }
41     __EXCEPT(page_fault)
42     {
43       SetLastError( ERROR_INVALID_PARAMETER );
44       return FALSE;
45     }
46     __ENDTRY
47      
48     return ret;
49 }
50
51 /***********************************************************************
52  *              GetComputerNameW         (KERNEL32.166)
53  */
54 BOOL WINAPI GetComputerNameW(LPWSTR name,LPDWORD size)
55 {
56     LPSTR nameA = (LPSTR)HeapAlloc( GetProcessHeap(), 0, *size);
57     BOOL ret = GetComputerNameA(nameA,size);
58     /* FIXME: should set *size in Unicode chars */
59     if (ret) MultiByteToWideChar( CP_ACP, 0, nameA, -1, name, *size+1 );
60     HeapFree( GetProcessHeap(), 0, nameA );
61     return ret;
62 }
63