Fixed the Win16/Win32 structure size/alignment differences of
[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 "winerror.h"
12 #include "wine/winestring.h"
13 #include "wine/exception.h"
14 #include "heap.h"
15 #include "task.h"
16 #include "debugtools.h"
17 #include "process.h"
18
19 DEFAULT_DEBUG_CHANNEL(win32);
20   
21 /* filter for page-fault exceptions */
22 static WINE_EXCEPTION_FILTER(page_fault)
23 {
24     if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION)
25         return EXCEPTION_EXECUTE_HANDLER;
26     return EXCEPTION_CONTINUE_SEARCH;
27 }
28
29 /***********************************************************************
30  *              GetStartupInfoA         (KERNEL32.273)
31  */
32 VOID WINAPI GetStartupInfoA(LPSTARTUPINFOA lpStartupInfo)
33 {
34   
35   LPSTARTUPINFOA  startup;
36
37   startup = ((LPSTARTUPINFOA )PROCESS_Current()->env_db->startup_info);
38   memcpy ( lpStartupInfo, startup, sizeof (STARTUPINFOA) );
39
40   TRACE("size: %ld\n"
41           "\tlpReserverd: %s, lpDesktop: %s, lpTitle: %s\n"
42           "\tdwX: %ld, dwY: %ld, dwXSize: %ld, dwYSize: %ld\n"
43           "\tdwFlags: %lx, wShowWindow: %x\n", lpStartupInfo->cb, 
44           debugstr_a(lpStartupInfo->lpReserved),
45           debugstr_a(lpStartupInfo->lpDesktop), 
46           debugstr_a(lpStartupInfo->lpTitle),
47           lpStartupInfo->dwX, lpStartupInfo->dwY,
48           lpStartupInfo->dwXSize, lpStartupInfo->dwYSize,
49           lpStartupInfo->dwFlags, lpStartupInfo->wShowWindow );
50 }
51
52 /***********************************************************************
53  *              GetStartupInfoW         (KERNEL32.274)
54  */
55 VOID WINAPI GetStartupInfoW(LPSTARTUPINFOW lpStartupInfo)
56 {
57
58   STARTUPINFOA startup;
59   GetStartupInfoA ( &startup );
60
61   lpStartupInfo->cb = sizeof(STARTUPINFOW);
62   lpStartupInfo->lpReserved = 
63     HEAP_strdupAtoW (GetProcessHeap(), 0, startup.lpReserved );
64   lpStartupInfo->lpDesktop = 
65     HEAP_strdupAtoW (GetProcessHeap(), 0, startup.lpDesktop );
66   lpStartupInfo->lpTitle = 
67     HEAP_strdupAtoW (GetProcessHeap(), 0, startup.lpTitle );
68   lpStartupInfo->dwX = startup.dwX;
69   lpStartupInfo->dwY = startup.dwY;
70   lpStartupInfo->dwXSize = startup.dwXSize;
71   lpStartupInfo->dwXCountChars = startup.dwXCountChars;
72   lpStartupInfo->dwYCountChars = startup.dwYCountChars;
73   lpStartupInfo->dwFillAttribute = startup.dwFillAttribute;
74   lpStartupInfo->dwFlags = startup.dwFlags;
75   lpStartupInfo->wShowWindow = startup.wShowWindow;
76   lpStartupInfo->cbReserved2 = startup.cbReserved2;
77   lpStartupInfo->lpReserved2 = startup.lpReserved2;
78   lpStartupInfo->hStdInput = startup.hStdInput;
79   lpStartupInfo->hStdOutput = startup.hStdOutput;
80   lpStartupInfo->hStdError = startup.hStdError;
81 }
82
83 /***********************************************************************
84  *              GetComputerNameA         (KERNEL32.165)
85  */
86 BOOL WINAPI GetComputerNameA(LPSTR name,LPDWORD size)
87 {
88     /* At least Win95OSR2 survives if size is not a pointer (NT crashes though) */
89     BOOL ret;
90     __TRY
91     {
92       ret = (-1!=gethostname(name,*size));
93       if (ret)
94         *size = lstrlenA(name);
95     }
96     __EXCEPT(page_fault)
97     {
98       SetLastError( ERROR_INVALID_PARAMETER );
99       return FALSE;
100     }
101     __ENDTRY
102      
103     return ret;
104 }
105
106 /***********************************************************************
107  *              GetComputerNameW         (KERNEL32.166)
108  */
109 BOOL WINAPI GetComputerNameW(LPWSTR name,LPDWORD size)
110 {
111     LPSTR nameA = (LPSTR)HeapAlloc( GetProcessHeap(), 0, *size);
112     BOOL ret = GetComputerNameA(nameA,size);
113     if (ret) lstrcpynAtoW(name,nameA,*size+1);
114     HeapFree( GetProcessHeap(), 0, nameA );
115     return ret;
116 }
117