Preliminary implementation of ICreateTypeInfo2_fnAddFuncDesc() and
[wine] / dlls / ole32 / ole32_main.c
1 /*
2  *  OLE32 Initialization
3  *
4  * Copyright 2000 Huw D M Davies for CodeWeavers
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #include "windef.h"
25 #include "winerror.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29 #include "winnls.h"
30 #include "ole32_main.h"
31 #include "wine/debug.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(ole);
34
35 HINSTANCE OLE32_hInstance = 0;
36
37 /***********************************************************************
38  *              OleMetafilePictFromIconAndLabel (OLE32.@)
39  */
40 HGLOBAL WINAPI OleMetafilePictFromIconAndLabel(HICON hIcon, LPOLESTR lpszLabel,
41                                                LPOLESTR lpszSourceFile, UINT iIconIndex)
42 {
43         METAFILEPICT mfp;
44         HDC hdc;
45         UINT dy;
46         HGLOBAL hmem = NULL;
47         LPVOID mfdata;
48         static const char szIconOnly[] = "IconOnly";
49
50         TRACE("%p %p %s %d\n", hIcon, lpszLabel, debugstr_w(lpszSourceFile), iIconIndex);
51
52         if( !hIcon )
53                 return NULL;
54
55         hdc = CreateMetaFileW(NULL);
56         if( !hdc )
57                 return NULL;
58
59         ExtEscape(hdc, MFCOMMENT, sizeof(szIconOnly), szIconOnly, 0, NULL);
60
61         /* FIXME: things are drawn in the wrong place */
62         DrawIcon(hdc, 0, 0, hIcon);
63         dy = GetSystemMetrics(SM_CXICON);
64         if(lpszLabel)
65                 TextOutW(hdc, 0, dy, lpszLabel, lstrlenW(lpszLabel));
66
67         if (lpszSourceFile)
68         {
69                 char szIconIndex[10];
70                 int path_length = WideCharToMultiByte(CP_ACP,0,lpszSourceFile,-1,NULL,0,NULL,NULL);
71                 if (path_length > 1)
72                 {
73                         char * szPath = CoTaskMemAlloc(path_length * sizeof(CHAR));
74                         if (szPath)
75                         {
76                                 WideCharToMultiByte(CP_ACP,0,lpszSourceFile,-1,szPath,path_length,NULL,NULL);
77                                 ExtEscape(hdc, MFCOMMENT, path_length, szPath, 0, NULL);
78                                 CoTaskMemFree(szPath);
79                         }
80                 }
81                 snprintf(szIconIndex, 10, "%u", iIconIndex);
82                 ExtEscape(hdc, MFCOMMENT, strlen(szIconIndex)+1, szIconIndex, 0, NULL);
83         }
84
85         mfp.mm = MM_ISOTROPIC;
86         mfp.xExt = mfp.yExt = 0; /* FIXME ? */
87         mfp.hMF = CloseMetaFile(hdc);
88         if( !mfp.hMF )
89                 return NULL;
90
91         hmem = GlobalAlloc( GMEM_MOVEABLE, sizeof(mfp) );
92         if( !hmem )
93         {
94                 DeleteMetaFile(mfp.hMF);
95                 return NULL;
96         }
97
98         mfdata = GlobalLock( hmem );
99         if( !mfdata )
100         {
101                 GlobalFree( hmem );
102                 DeleteMetaFile(mfp.hMF);
103                 return NULL;
104         }
105
106         memcpy(mfdata,&mfp,sizeof(mfp));
107         GlobalUnlock( hmem );
108
109         TRACE("returning %p\n",hmem);
110
111         return hmem;
112 }
113
114
115 /***********************************************************************
116  *              DllMain (OLE32.@)
117  */
118 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
119 {
120     TRACE("%p 0x%lx %p\n", hinstDLL, fdwReason, fImpLoad);
121
122     switch(fdwReason) {
123     case DLL_PROCESS_ATTACH:
124         DisableThreadLibraryCalls(hinstDLL);
125         OLE32_hInstance = hinstDLL;
126         COMPOBJ_InitProcess();
127         if (TRACE_ON(ole)) CoRegisterMallocSpy((LPVOID)-1);
128         break;
129
130     case DLL_PROCESS_DETACH:
131         if (TRACE_ON(ole)) CoRevokeMallocSpy();
132         COMPOBJ_UninitProcess();
133         OLE32_hInstance = 0;
134         break;
135     }
136     return TRUE;
137 }
138
139 /* NOTE: DllRegisterServer and DllUnregisterServer are in regsvr.c */