source: trunk/src/shlwapi/mem.cpp@ 3539

Last change on this file since 3539 was 3539, checked in by phaller, 25 years ago

Further SHLWAPI development

File size: 5.1 KB
Line 
1/* $Id: mem.cpp,v 1.1 2000-05-15 02:43:16 phaller Exp $ */
2
3/*
4 * Win32 Lightweight SHELL32 for OS/2
5 *
6 * Copyright 1997 Marcus Meissner
7 * Copyright 1999 Patrick Haller (haller@zebra.fh-weingarten.de)
8 * Project Odin Software License can be found in LICENSE.TXT
9 *
10 * Path Functions
11 *
12 * Many of this functions are in SHLWAPI.DLL also
13 *
14 * Corel WINE 20000324 level (without CRTDLL_* calls)
15 */
16
17/*****************************************************************************
18 * Remark *
19 *****************************************************************************
20
21 */
22
23
24/*****************************************************************************
25 * Includes *
26 *****************************************************************************/
27
28#include <odin.h>
29#include <odinwrap.h>
30#include <os2sel.h>
31
32#include <string.h>
33#include <ctype.h>
34#include <wctype.h>
35#include <wcstr.h>
36#define HAVE_WCTYPE_H
37
38#include "debugtools.h"
39
40#include <winreg.h>
41
42#include <heapstring.h>
43#include <misc.h>
44#include <win\shell.h>
45#include <win\winerror.h>
46#include <winversion.h>
47#include <winuser.h>
48
49
50#define ICOM_CINTERFACE 1
51#define CINTERFACE 1
52
53#include "winerror.h"
54#include "winnls.h"
55#include "winversion.h"
56#include "heap.h"
57
58#include "shellapi.h"
59#include "shlobj.h"
60#include "wine/undocshell.h"
61
62#include "shlwapi.h"
63
64/*****************************************************************************
65 * Local Variables *
66 *****************************************************************************/
67
68ODINDEBUGCHANNEL(SHLWAPI-MEM)
69
70
71/*************************************************************************
72 * SHFree [SHELL32.195]
73 *
74 * NOTES
75 * free_ptr() - frees memory using IMalloc
76 * exported by ordinal
77 */
78#define MEM_DEBUG 0
79DWORD WINAPI SHFree(LPVOID x)
80{
81#if MEM_DEBUG
82 WORD len = *(LPWORD)(x-2);
83
84 if ( *(LPWORD)(x+len) != 0x7384)
85 ERR("MAGIC2!\n");
86
87 if ( (*(LPWORD)(x-4)) != 0x8271)
88 ERR("MAGIC1!\n");
89 else
90 memset(x-4, 0xde, len+6);
91
92 TRACE("%p len=%u\n",x, len);
93
94 x -= 4;
95#else
96 TRACE("%p\n",x);
97#endif
98 return HeapFree(GetProcessHeap(), 0, x);
99}
100
101/*************************************************************************
102 * SHAlloc [SHELL32.196]
103 *
104 * NOTES
105 * void *task_alloc(DWORD len), uses SHMalloc allocator
106 * exported by ordinal
107 */
108LPVOID WINAPI SHAlloc(DWORD len)
109{
110 LPBYTE ret;
111
112#if MEM_DEBUG
113 ret = (LPBYTE) HeapAlloc(GetProcessHeap(),0,len+6);
114#else
115 ret = (LPBYTE) HeapAlloc(GetProcessHeap(),0,len);
116#endif
117
118#if MEM_DEBUG
119 *(LPWORD)(ret) = 0x8271;
120 *(LPWORD)(ret+2) = (WORD)len;
121 *(LPWORD)(ret+4+len) = 0x7384;
122 ret += 4;
123 memset(ret, 0xdf, len);
124#endif
125 TRACE("%lu bytes at %p\n",len, ret);
126 return (LPVOID)ret;
127}
128
129/*************************************************************************
130 * SHAllocShared [SHELL32.520]
131 *
132 * NOTES
133 * parameter1 is return value from HeapAlloc
134 * parameter2 is equal to the size allocated with HeapAlloc
135 * parameter3 is return value from GetCurrentProcessId
136 *
137 * the return value is posted as lParam with 0x402 (WM_USER+2) to somewhere
138 * WM_USER+2 could be the undocumented CWM_SETPATH
139 * the allocated memory contains a pidl
140 */
141HGLOBAL WINAPI SHAllocShared(LPVOID psrc, DWORD size, DWORD procID)
142{ HGLOBAL hmem;
143 LPVOID pmem;
144
145 TRACE("ptr=%p size=0x%04lx procID=0x%04lx\n",psrc,size,procID);
146 hmem = GlobalAlloc(GMEM_FIXED, size);
147 if (!hmem)
148 return 0;
149
150 pmem = GlobalLock (hmem);
151
152 if (! pmem)
153 return 0;
154
155 memcpy (pmem, psrc, size);
156 GlobalUnlock(hmem);
157 return hmem;
158}
159/*************************************************************************
160 * SHLockShared [SHELL32.521]
161 *
162 * NOTES
163 * parameter1 is return value from SHAllocShared
164 * parameter2 is return value from GetCurrentProcessId
165 * the receiver of (WM_USER+2) trys to lock the HANDLE (?)
166 * the returnvalue seems to be a memoryadress
167 */
168LPVOID WINAPI SHLockShared(HANDLE hmem, DWORD procID)
169{ TRACE("handle=0x%04x procID=0x%04lx\n",hmem,procID);
170 return GlobalLock(hmem);
171}
172/*************************************************************************
173 * SHUnlockShared [SHELL32.522]
174 *
175 * NOTES
176 * parameter1 is return value from SHLockShared
177 */
178BOOL WINAPI SHUnlockShared(HANDLE pmem)
179{ TRACE("handle=0x%04x\n",pmem);
180 return GlobalUnlock(pmem);
181}
182/*************************************************************************
183 * SHFreeShared [SHELL32.523]
184 *
185 * NOTES
186 * parameter1 is return value from SHAllocShared
187 * parameter2 is return value from GetCurrentProcessId
188 */
189HANDLE WINAPI SHFreeShared(HANDLE hmem, DWORD procID)
190{ TRACE("handle=0x%04x 0x%04lx\n",hmem,procID);
191 return GlobalFree(hmem);
192}
Note: See TracBrowser for help on using the repository browser.