using madres in other programming language...

delphi package - madRes, madTools, madStrings, ...
Post Reply
d2k2
Posts: 7
Joined: Tue Jun 07, 2005 7:52 pm

using madres in other programming language...

Post by d2k2 »

hi madshi,

i was very happy when i found finally a solution to make Resource updates under win98 possible.

i am coding with masm and i dont understand delphi code. (i compiled my first delphi "hello world" this week :crazy: ). so i asked a friend who made a small dll from your madres code. but it doesnt work :(

i debugged it and that what i find:

1. when i call BeginUpdateResourceW it returns always 0 (failed).
taking a closer look into the debugger this happens:

Code: Select all

function BeginUpdateResourceW(fileName: PWideChar; delExistingRes: bool) : dword; stdcall;
...
    fh := CreateFileX(fileName, true, false);
    if fh <> dword(-1) then begin
      map := CreateFileMapping(fh, nil, PAGE_READWRITE, 0, 0, nil);
...
CreateFileX returns always -1

2. taking a closer look to CreateFileX, this happens:

Code: Select all

else result := CreateFileA(pchar(string(wideString(fileName))), c1, c2, nil, c3, 0, 0);
you are doing some convertation with the string. the filenamestring gets destroyed from "c:\bla.exe" to "?????". why this? :cry:

when i kill this convertcode,all works fine.

i hope that you could build a madres.dll which can be used in other program languages. :crazy:
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

The converting code is necessary, because BeginUpdateResourceW expects a wide string as the first parameter. I guess that you called it with an ansi string instead.

How do you call BeginUpdateResourceW?
d2k2
Posts: 7
Joined: Tue Jun 07, 2005 7:52 pm

Post by d2k2 »

madshi wrote:The converting code is necessary, because BeginUpdateResourceW expects a wide string as the first parameter. I guess that you called it with an ansi string instead.

How do you call BeginUpdateResourceW?
i dont really know what an ansi string is. when i code in masm a string is string.

first i load the madres.dll with LoadLibrary and i use GetProcAddress to get the required addresses for BeginUpdateResourceW...

then i do the update:

Code: Select all

UpdatePatcherResource proc _filename:dword,_type:dword,_name:dword,_resdata:dword,_ressize:dword
	LOCAL local_hUpdateRes	:DWORD
	LOCAL local_retvalue	:BYTE
	
	pushad
	mov local_retvalue,0
	.if _BeginUpdateResource!=0		;is the dll loaded ?
		push FALSE			;TRUE=DeleteExisting,FALSE=Don't DeleteExisting
		push _filename			;points to the filename string.
		call _BeginUpdateResource	
		.if eax!=0
			mov local_hUpdateRes,eax
			
			push _ressize
			push _resdata
			push 0
			push _name
			push _type
			push eax
			call _UpdateResource
			.if eax!=0
				push FALSE
				push local_hUpdateRes
				call _EndUpdateResource
				.if eax!=0
					mov local_retvalue,1
				.endif	
			.endif	
		.endif
	.endif	
	@return:
	popad
	movzx eax,local_retvalue	;return: 1=success 0=failed
	ret
UpdatePatcherResource endp
here is the info from win32.hlp:
HANDLE BeginUpdateResource(

LPCTSTR pFileName, // pointer to file in which to update resources
BOOL bDeleteExistingResources // deletion option
);
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

You need to give in a wide string, which has 2 byte per character. An ansi string has only one byte per character.

Have you ever called any wide functions from asm like e.g. CopyFileW or CreateFileW? That also need wide strings.
d2k2
Posts: 7
Joined: Tue Jun 07, 2005 7:52 pm

Post by d2k2 »

madshi wrote:You need to give in a wide string, which has 2 byte per character. An ansi string has only one byte per character.

Have you ever called any wide functions from asm like e.g. CopyFileW or CreateFileW? That also need wide strings.
i just was confused, because the original UpdateResource API dont need this "wide string" with 2 byte per character.
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

The original API exists in BeginUpdateResourceA and BeginUpdateResourseW flavours. If you call the original API BeginUpdateResourceW API, then you need to give in a wide string, too.
d2k2
Posts: 7
Joined: Tue Jun 07, 2005 7:52 pm

Post by d2k2 »

thank you. now i understand :wink:
d2k2
Posts: 7
Joined: Tue Jun 07, 2005 7:52 pm

Post by d2k2 »

the madres.dll works on my system winxp sp2. but people who want to use it under win9x, say that the resourceupdate dont work. :cry:
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

It works for me. Are you sure you called the correct BeginUpdateResourceW API? In the code you posted it sais:

.if _BeginUpdateResource!=0 ;is the dll loaded ?

That looks wrong to me. Shouldn't it be BeginUpdateResourceW?

Do you have a win9x system on which you can test your program? You should. If not, I'd recommend to think about using either VmWare or VirtualPC. Great products to do multi OS development!
d2k2
Posts: 7
Joined: Tue Jun 07, 2005 7:52 pm

Post by d2k2 »

.if _BeginUpdateResource!=0 ;is the dll loaded ?

That looks wrong to me. Shouldn't it be BeginUpdateResourceW?
i didnt show you the whole source code. i imort the exports from madres.dll with GetProcAddress and save them to variables (like _BeginUpdateResource).

i install vmware today and going to find the bug.
d2k2
Posts: 7
Joined: Tue Jun 07, 2005 7:52 pm

Post by d2k2 »

problem solved. it wasnt a bug in madres.dll
Post Reply