netstat: Initial implementation.
[wine] / dlls / typelib.dll16 / typelib.c
1 /*
2  *      TYPELIB 16bit part.
3  *
4  * Copyright 1997 Marcus Meissner
5  * Copyright 1999 Rein Klazes
6  * Copyright 2000 Francois Jacques
7  * Copyright 2001 Huw D M Davies for CodeWeavers
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23
24 #include "config.h"
25 #include "wine/port.h"
26
27 #include <stdlib.h>
28 #include <string.h>
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <ctype.h>
32
33 #include "winerror.h"
34 #include "windef.h"
35 #include "winbase.h"
36 #include "wine/winbase16.h"
37 #include "winreg.h"
38 #include "winuser.h"
39 #include "objbase.h"
40 #include "oleauto.h"
41 #include "wine/debug.h"
42
43 WINE_DEFAULT_DEBUG_CHANNEL(ole);
44
45 /*************************************************************************
46  * TYPELIB {TYPELIB}
47  *
48  * This dll is the 16 bit version of the Typelib API, part the original
49  * implementation of Ole automation. It and its companion ole2disp.dll were
50  * superseded by oleaut32.dll which provides 32 bit implementations of these
51  * functions and greatly extends the OLE API.
52  *
53  * Winelib developers cannot use these functions directly, they are implemented
54  * solely for backwards compatibility with existing legacy applications.
55  *
56  * SEE ALSO
57  *  oleaut32(), ole2disp().
58  */
59
60 /****************************************************************************
61  *              QueryPathOfRegTypeLib   [TYPELIB.14]
62  *
63  * Get the registry key of a registered type library.
64  *
65  * RETURNS
66  *  Success: S_OK. path is updated with the key name
67  *  Failure: E_FAIL, if guid was not found in the registry
68  *
69  * NOTES
70  *  The key takes the form "Classes\Typelib\<guid>\<major>.<minor>\<lcid>\win16\"
71  */
72 HRESULT WINAPI
73 QueryPathOfRegTypeLib16(
74         REFGUID guid,   /* [in] Guid to get the key name for */
75         WORD wMaj,      /* [in] Major version */
76         WORD wMin,      /* [in] Minor version */
77         LCID lcid,      /* [in] Locale Id */
78         SEGPTR *path)   /* [out] Destination for the registry key name */
79 {
80         char    xguid[80];
81         char    typelibkey[100],pathname[260];
82         LONG    plen;
83         char   *ret;
84
85         TRACE("\n");
86
87         if (HIWORD(guid)) {
88             sprintf( typelibkey, "SOFTWARE\\Classes\\Typelib\\{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\%d.%d\\%x\\win16",
89                      guid->Data1, guid->Data2, guid->Data3,
90                      guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
91                      guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7],
92                      wMaj,wMin,lcid);
93         } else {
94                 sprintf(xguid,"<guid 0x%08x>",(DWORD)guid);
95                 FIXME("(%s,%d,%d,0x%04x,%p),can't handle non-string guids.\n",xguid,wMaj,wMin,lcid,path);
96                 return E_FAIL;
97         }
98         plen = sizeof(pathname);
99         if (RegQueryValueA(HKEY_LOCAL_MACHINE,typelibkey,pathname,&plen)) {
100                 /* try again without lang specific id */
101                 if (SUBLANGID(lcid))
102                         return QueryPathOfRegTypeLib16(guid,wMaj,wMin,PRIMARYLANGID(lcid),path);
103                 FIXME("key %s not found\n",typelibkey);
104                 return E_FAIL;
105         }
106         ret = HeapAlloc( GetProcessHeap(), 0, strlen(pathname) + 1 );
107         if (!ret) return E_FAIL;
108         strcpy( ret, pathname );
109         *path = MapLS(ret);
110         return S_OK;
111 }
112
113 /******************************************************************************
114  * LoadTypeLib [TYPELIB.3]
115  *
116  * Load and register a type library.
117  *
118  * RETURNS
119  *  Success: S_OK. pptLib contains the type libraries ITypeLib interface.
120  *  Failure: An HRESULT error code.
121  *
122  * NOTES
123  *  Both parameters are FAR pointers.
124  */
125 HRESULT WINAPI LoadTypeLib16(
126     LPSTR szFile, /* [in] Name of file to load from */
127     ITypeLib** pptLib) /* [out] Destination for loaded ITypeLib interface */
128 {
129     FIXME("(%s,%p): stub\n",debugstr_a(szFile),pptLib);
130
131     if (pptLib!=0)
132       *pptLib=0;
133
134     return E_FAIL;
135 }
136
137 /***********************************************************************
138  *              LHashValOfNameSys  (TYPELIB.4)
139  */
140 ULONG WINAPI LHashValOfNameSys16( SYSKIND skind, LCID lcid, LPCSTR lpStr)
141 {
142     return LHashValOfNameSysA( skind, lcid, lpStr );
143 }
144
145 /****************************************************************************
146  *      OaBuildVersion                          (TYPELIB.15)
147  *
148  * Get the Ole Automation build version.
149  *
150  * PARAMS
151  *  None
152  *
153  * RETURNS
154  *  The build version.
155  *
156  * NOTES
157  *  Known typelib.dll versions:
158  *| OLE Ver.  Comments                   Date    Build Ver.
159  *| --------  -------------------------  ----    ---------
160  *| OLE 2.01  Call not available         1993     N/A
161  *| OLE 2.02                             1993-94  02 3002
162  *| OLE 2.03                                      23 730
163  *| OLE 2.03                                      03 3025
164  *| OLE 2.03  W98 SE orig. file !!       1993-95  10 3024
165  *| OLE 2.1   NT                         1993-95  ?? ???
166  *| OLE 2.3.1 W95                                 23 700
167  *| OLE2 4.0  NT4SP6                     1993-98  40 4277
168  *| OLE 2.1   W2K                        2000     10 3029
169  *| OLE 2.1   WXP                        2002     10 3029
170  *| OLE 2.1   Vista                      2007     10 3029
171  */
172 DWORD WINAPI OaBuildVersion16(void)
173 {
174     /* FIXME: I'd like to return the highest currently known version value
175      * in case the user didn't force a --winver, but I don't know how
176      * to retrieve the "versionForced" info from misc/version.c :(
177      * (this would be useful in other places, too) */
178     FIXME("If you get version error messages, please report them\n");
179     switch(GetVersion() & 0x8000ffff)  /* mask off build number */
180     {
181     case 0x80000a03:  /* WIN31 */
182                 return MAKELONG(3027, 3); /* WfW 3.11 */
183     case 0x80000004:  /* WIN95 */
184                 return MAKELONG(700, 23); /* Win95A */
185     case 0x80000a04:  /* WIN98 */
186                 return MAKELONG(3024, 10); /* W98 SE */
187     case 0x00000004:  /* NT4 */
188                 return MAKELONG(4277, 40); /* NT4 SP6 */
189     case 0x00000005:  /* W2K */
190                 return MAKELONG(3029, 10); /* W2K SP4 */
191     case 0x00000105:  /* WXP */
192                 return MAKELONG(3029, 10); /* WXP SP2 */
193     case 0x00000006:  /* Vista */
194                 return MAKELONG(3029, 10); /* Vista */
195     default:
196         FIXME("Version value not known yet. Please investigate it!\n");
197                 return 0;
198     }
199 }