Implemented Local Server COM.
[wine] / dlls / oleaut32 / oleaut.c
1 /*
2  *      OLEAUT32
3  *
4  */
5 #include <string.h>
6
7 #include "windef.h"
8 #include "winbase.h"
9 #include "wingdi.h"
10 #include "winuser.h"
11 #include "winerror.h"
12
13 #include "ole2.h"
14 #include "olectl.h"
15 #include "wine/obj_oleaut.h"
16 #include "wine/obj_olefont.h"
17
18 #include "tmarshal.h"
19
20 #include "debugtools.h"
21
22 DEFAULT_DEBUG_CHANNEL(ole);
23
24 static WCHAR    _delimiter[2] = {'!',0}; /* default delimiter apparently */
25 static WCHAR    *pdelimiter = &_delimiter[0];
26
27 /***********************************************************************
28  *              RegisterActiveObject (OLEAUT32.33)
29  */
30 HRESULT WINAPI RegisterActiveObject(
31         LPUNKNOWN punk,REFCLSID rcid,DWORD dwFlags,LPDWORD pdwRegister
32 ) {
33         WCHAR                   guidbuf[80];
34         HRESULT                 ret;
35         LPRUNNINGOBJECTTABLE    runobtable;
36         LPMONIKER               moniker;
37
38         StringFromGUID2(rcid,guidbuf,39);
39         ret = CreateItemMoniker(pdelimiter,guidbuf,&moniker);
40         if (FAILED(ret)) 
41                 return ret;
42         ret = GetRunningObjectTable(0,&runobtable);
43         if (FAILED(ret)) {
44                 IMoniker_Release(moniker);
45                 return ret;
46         }
47         ret = IRunningObjectTable_Register(runobtable,dwFlags,punk,moniker,pdwRegister);
48         IRunningObjectTable_Release(runobtable);
49         IMoniker_Release(moniker);
50         return ret;
51 }
52
53 /***********************************************************************
54  *              RevokeActiveObject (OLEAUT32.34)
55  */
56 HRESULT WINAPI RevokeActiveObject(DWORD xregister,LPVOID reserved)
57 {
58         LPRUNNINGOBJECTTABLE    runobtable;
59         HRESULT                 ret;
60
61         ret = GetRunningObjectTable(0,&runobtable);
62         if (FAILED(ret)) return ret;
63         ret = IRunningObjectTable_Revoke(runobtable,xregister);
64         if (SUCCEEDED(ret)) ret = S_OK;
65         IRunningObjectTable_Release(runobtable);
66         return ret;
67 }
68
69 /***********************************************************************
70  *              GetActiveObject (OLEAUT32.35)
71  */
72 HRESULT WINAPI GetActiveObject(REFCLSID rcid,LPVOID preserved,LPUNKNOWN *ppunk)
73 {
74         WCHAR                   guidbuf[80];
75         HRESULT                 ret;
76         LPRUNNINGOBJECTTABLE    runobtable;
77         LPMONIKER               moniker;
78
79         StringFromGUID2(rcid,guidbuf,39);
80         ret = CreateItemMoniker(pdelimiter,guidbuf,&moniker);
81         if (FAILED(ret)) 
82                 return ret;
83         ret = GetRunningObjectTable(0,&runobtable);
84         if (FAILED(ret)) {
85                 IMoniker_Release(moniker);
86                 return ret;
87         }
88         ret = IRunningObjectTable_GetObject(runobtable,moniker,ppunk);
89         IRunningObjectTable_Release(runobtable);
90         IMoniker_Release(moniker);
91         return ret;
92 }
93
94
95 /***********************************************************************
96  *           OaBuildVersion           [OLEAUT32.170]
97  *
98  * known OLEAUT32.DLL versions:
99  * OLE 2.1  NT                          1993-95 10     3023
100  * OLE 2.1                                      10     3027
101  * Win32s 1.1e                                  20     4049
102  * OLE 2.20 W95/NT                      1993-96 20     4112
103  * OLE 2.20 W95/NT                      1993-96 20     4118
104  * OLE 2.20 W95/NT                      1993-96 20     4122
105  * OLE 2.30 W95/NT                      1993-98 30     4265
106  * OLE 2.40 NT??                        1993-98 40     4267
107  * OLE 2.40 W98 SE orig. file           1993-98 40     4275
108  * OLE 2.40 W2K orig. file              1993-XX 40     4514
109  *
110  * I just decided to use version 2.20 for Win3.1, 2.30 for Win95 & NT 3.51,
111  * and 2.40 for all newer OSs. The build number is maximum, i.e. 0xffff.
112  */
113 UINT WINAPI OaBuildVersion()
114 {
115     switch(GetVersion() & 0x8000ffff)  /* mask off build number */
116     {
117     case 0x80000a03:  /* WIN31 */
118                 return MAKELONG(0xffff, 20);
119     case 0x00003303:  /* NT351 */
120                 return MAKELONG(0xffff, 30);
121     case 0x80000004:  /* WIN95; I'd like to use the "standard" w95 minor
122                          version here (30), but as we still use w95
123                          as default winver (which is good IMHO), I better
124                          play safe and use the latest value for w95 for now.
125                          Change this as soon as default winver gets changed
126                          to something more recent */
127     case 0x80000a04:  /* WIN98 */
128     case 0x00000004:  /* NT40 */
129     case 0x00000005:  /* W2K */
130                 return MAKELONG(0xffff, 40);
131     default:
132                 ERR("Version value not known yet. Please investigate it !\n");
133                 return 0x0;
134     }
135 }
136
137 /***********************************************************************
138  *              DllRegisterServer (OLEAUT32.320)
139  */
140 HRESULT WINAPI OLEAUT32_DllRegisterServer() { 
141     FIXME("stub!\n");
142     return S_OK;
143 }
144
145 /***********************************************************************
146  *              DllUnregisterServer (OLEAUT32.321)
147  */
148 HRESULT WINAPI OLEAUT32_DllUnregisterServer() {
149     FIXME("stub!\n");
150     return S_OK;
151 }
152
153 extern void _get_STDFONT_CF(LPVOID);
154
155 /***********************************************************************
156  *              DllGetClassObject (OLEAUT32.1)
157  */
158 HRESULT WINAPI OLEAUT32_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
159 {
160     *ppv = NULL;
161     if (IsEqualGUID(rclsid,&CLSID_StdFont)) {
162         if (IsEqualGUID(iid,&IID_IClassFactory)) {
163             _get_STDFONT_CF(ppv);
164             IClassFactory_AddRef((IClassFactory*)*ppv);
165             return S_OK;
166         }
167     }
168     if (IsEqualGUID(rclsid,&CLSID_PSOAInterface)) {
169         if (S_OK==TypeLibFac_DllGetClassObject(rclsid,iid,ppv))
170             return S_OK;
171         /*FALLTHROUGH*/
172     }
173     FIXME("\n\tCLSID:\t%s,\n\tIID:\t%s\n",debugstr_guid(rclsid),debugstr_guid(iid));
174     return CLASS_E_CLASSNOTAVAILABLE;
175 }
176
177 /***********************************************************************
178  *              DllCanUnloadNow (OLEAUT32.410)
179  */
180 HRESULT WINAPI OLEAUT32_DllCanUnloadNow() {
181     FIXME("(), stub!\n");
182     return S_FALSE;
183 }