www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - What is wrong with this function that I can not get resource content?

reply Marcone <marcone email.com> writes:
// Function get_resource()
void get_resource(const(wchar)* id, const(wchar)* tipo, 
const(wchar)* path_name){
	HRSRC file = FindResource(null, id, tipo);
	DWORD size = SizeofResource(NULL, file);
	HGLOBAL load = LoadResource(NULL, file);
	HANDLE new_file = CreateFile(path_name, GENERIC_WRITE, 0, NULL, 
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
	WriteFile(new_file, load, size, cast(uint*) 0, null);
	CloseHandle(new_file);
}

void main(){
	get_resource("300", "BMP", "melancia.bmp");
}
Feb 05 2020
next sibling parent Marcone <marcone email.com> writes:
I get resource "melancia.bmp" but the file is corrupted.
Feb 05 2020
prev sibling parent reply Marcone <marcone email.com> writes:



Feb 05 2020
parent novice2 <sorrybo ema.ail> writes:
On Wednesday, 5 February 2020 at 20:01:19 UTC, Marcone wrote:



the mistake, very imho, is not check windows API functions results. you can use wenforce: https://dlang.org/phobos/std_windows_syserror.html#.wenforce
Feb 05 2020