- better error check when importing functions via GetProcAdress
[wine/multimedia.git] / win32 / init.c
blobeb0350698a0386efd1cf9741f07a4a6817a52969
1 /*
2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
5 * 1999 Peter Ganten
6 */
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"
19 DEFAULT_DEBUG_CHANNEL(win32);
21 /* filter for page-fault exceptions */
22 static WINE_EXCEPTION_FILTER(page_fault)
24 if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION)
25 return EXCEPTION_EXECUTE_HANDLER;
26 return EXCEPTION_CONTINUE_SEARCH;
29 /***********************************************************************
30 * GetStartupInfoA (KERNEL32.273)
32 VOID WINAPI GetStartupInfoA(LPSTARTUPINFOA lpStartupInfo)
35 LPSTARTUPINFOA startup;
37 startup = ((LPSTARTUPINFOA )PROCESS_Current()->env_db->startup_info);
38 memcpy ( lpStartupInfo, startup, sizeof (STARTUPINFOA) );
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 );
52 /***********************************************************************
53 * GetStartupInfoW (KERNEL32.274)
55 VOID WINAPI GetStartupInfoW(LPSTARTUPINFOW lpStartupInfo)
58 STARTUPINFOA startup;
59 GetStartupInfoA ( &startup );
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;
83 /***********************************************************************
84 * GetComputerNameA (KERNEL32.165)
86 BOOL WINAPI GetComputerNameA(LPSTR name,LPDWORD size)
88 /* At least Win95OSR2 survives if size is not a pointer (NT crashes though) */
89 BOOL ret;
90 __TRY
92 ret = (-1!=gethostname(name,*size));
93 if (ret)
94 *size = lstrlenA(name);
96 __EXCEPT(page_fault)
98 SetLastError( ERROR_INVALID_PARAMETER );
99 return FALSE;
101 __ENDTRY
103 return ret;
106 /***********************************************************************
107 * GetComputerNameW (KERNEL32.166)
109 BOOL WINAPI GetComputerNameW(LPWSTR name,LPDWORD size)
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;