Portability fixes.
[wine.git] / dlls / ole32 / ole32_main.c
blobf5f79058483b762cd796a732288c6367240af428
1 /*
2 * OLE32 Initialization
4 * Copyright 2000 Huw D M Davies for Codeweavers
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.
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.
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
21 #include "windef.h"
22 #include "winerror.h"
23 #include "winbase.h"
24 #include "wingdi.h"
25 #include "winuser.h"
26 #include "ole32_main.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(ole);
31 HINSTANCE OLE32_hInstance = 0;
33 /***********************************************************************
34 * OleMetafilePictFromIconAndLabel (OLE32.115)
36 HGLOBAL WINAPI OleMetafilePictFromIconAndLabel(HICON hIcon, LPOLESTR lpszLabel,
37 LPOLESTR lpszSourceFile, UINT iIconIndex)
39 HMETAFILE hmf;
40 HDC hdc;
41 UINT dy, mfsize;
42 HGLOBAL hmem = 0;
43 LPVOID mfdata;
45 TRACE("%p %p %p %d\n", hIcon, lpszLabel, lpszSourceFile, iIconIndex);
47 if( !hIcon )
48 return 0;
50 hdc = CreateMetaFileW(NULL);
51 if( !hdc )
52 return 0;
54 /* FIXME: things are drawn in the wrong place */
55 DrawIcon(hdc, 0, 0, hIcon);
56 dy = GetSystemMetrics(SM_CXICON);
57 if(lpszLabel)
58 TextOutW(hdc, 0, dy, lpszLabel, lstrlenW(lpszLabel));
60 hmf = CloseMetaFile(hdc);
61 if( !hmf )
62 return 0;
64 mfsize = GetMetaFileBitsEx( hmf, 0, NULL);
65 if( !mfsize )
66 goto end;
68 hmem = GlobalAlloc( GMEM_MOVEABLE, mfsize );
69 if( !hmem )
70 goto end;
72 mfdata = GlobalLock( hmem );
73 if( !mfdata )
75 GlobalFree( hmem );
76 hmem = 0;
77 goto end;
80 GetMetaFileBitsEx( hmf, mfsize, mfdata );
81 GlobalUnlock( hmem );
82 end:
83 DeleteMetaFile(hmf);
85 TRACE("returning %p\n",hmem);
87 return hmem;
91 /***********************************************************************
92 * DllMain (OLE32.@)
94 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
96 TRACE("%p 0x%lx %p\n", hinstDLL, fdwReason, fImpLoad);
98 switch(fdwReason) {
99 case DLL_PROCESS_ATTACH:
100 DisableThreadLibraryCalls(hinstDLL);
101 OLE32_hInstance = hinstDLL;
102 COMPOBJ_InitProcess();
103 if (TRACE_ON(ole)) CoRegisterMallocSpy((LPVOID)-1);
104 break;
106 case DLL_PROCESS_DETACH:
107 if (TRACE_ON(ole)) CoRevokeMallocSpy();
108 COMPOBJ_UninitProcess();
109 OLE32_hInstance = 0;
110 break;
112 return TRUE;
115 /* NOTE: DllRegisterServer and DllUnregisterServer are in regsvr.c */