2 * Copyright (C) 2009 Tony Wasserka
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "wine/debug.h"
21 #include "d3dx9_36_private.h"
23 /************************************************************
26 * Loads a file into buffer and stores the number of read bytes in length.
29 * filename [I] name of the file to be loaded
30 * buffer [O] pointer to destination buffer
31 * length [O] size of the obtained data
36 * see error codes for CreateFileW, GetFileSize, CreateFileMapping and MapViewOfFile
39 * The caller must UnmapViewOfFile when it doesn't need the data anymore
42 HRESULT
map_view_of_file(LPCWSTR filename
, LPVOID
*buffer
, DWORD
*length
)
44 HANDLE hfile
, hmapping
= NULL
;
46 hfile
= CreateFileW(filename
, GENERIC_READ
, FILE_SHARE_READ
, 0, OPEN_EXISTING
, 0, 0);
47 if(hfile
== INVALID_HANDLE_VALUE
) goto error
;
49 *length
= GetFileSize(hfile
, NULL
);
50 if(*length
== INVALID_FILE_SIZE
) goto error
;
52 hmapping
= CreateFileMappingW(hfile
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
53 if(!hmapping
) goto error
;
55 *buffer
= MapViewOfFile(hmapping
, FILE_MAP_READ
, 0, 0, 0);
56 if(*buffer
== NULL
) goto error
;
58 CloseHandle(hmapping
);
64 CloseHandle(hmapping
);
66 return HRESULT_FROM_WIN32(GetLastError());
69 /************************************************************
70 * load_resource_into_memory
72 * Loads a resource into buffer and stores the number of
73 * read bytes in length.
76 * module [I] handle to the module
77 * resinfo [I] handle to the resource's information block
78 * buffer [O] pointer to destination buffer
79 * length [O] size of the obtained data
84 * See error codes for SizeofResource, LoadResource and LockResource
87 * The memory doesn't need to be freed by the caller manually
90 HRESULT
load_resource_into_memory(HMODULE module
, HRSRC resinfo
, LPVOID
*buffer
, DWORD
*length
)
94 *length
= SizeofResource(module
, resinfo
);
95 if(*length
== 0) return HRESULT_FROM_WIN32(GetLastError());
97 resource
= LoadResource(module
, resinfo
);
98 if( !resource
) return HRESULT_FROM_WIN32(GetLastError());
100 *buffer
= LockResource(resource
);
101 if(*buffer
== NULL
) return HRESULT_FROM_WIN32(GetLastError());