I'm messing with resources at the moment. win32.hlp was most usefull however i'v come across some problems i hope someone might be able to point me out of.
I use FindResource, SizeofResource and LoadResource and then write the results into a file (song.xm)
Then MIDAS11.DLL (Midas module library) *should* play the song.xm. The init routines for the module are correct cause when i dont extract the file from the resource (it lays in the dir) it plays fine. It seems song.xm is 0byte or in use at the time the library starts to load it. I tried sleep 5000 to see if delays fix it but it doesnt.
Anyone know as to whats going on? :)
Also dont suppose anyone has a smaller (smaller than 71kb) module dll?

Posted on 2002-01-14 19:38:25 by ThrawN

What OS are you using? A recent thread discussed
a limit on resource size for Win 9x of 64k.
Search for the thread if this sounds like a cause
of your trouble.

Posted on 2002-01-15 01:10:49 by farrier
Win98 and Win2k
In both cases once the program has crashed the written file is correct.
The resource file is 35kb anyway.
Any idea's? or maybe iv done something or missed something :/
Posted on 2002-01-15 02:38:05 by ThrawN

Thrawn, do you use LockResource ?
And do you close the File handle (because 0 Byte)?

I don't know if there is a resource limit on win 9x of 64k.
I can include a resource of 7 MByte or more without any problem.

The only problem I encounter with resources
is that it is not possible (in the standard way)
to use API CreateCompatibleBitmap to create a
big Bitmap for example 4000x4000 pixel.
Also all other methods (CreateBitmap, CreateDIBitmap, CreateBitmapIndirect, LoadBitmap, LoadImage ...) fail.
No trouble on win2k.

But there must be a Workaround avaible, because
other programs (IrfanView...) do it.

Posted on 2002-01-15 02:47:38 by Test Department
Try a function like "FlushFileBuffers hFile" or similar. It is not guaranteed that the OS will write the file when you tell it to, rather it will buffer it and write at a more appropriate moment.

Either that or open the file with the FILE_FLAG_NO_BUFFERING option (which could impact on performance), and also imposes some limits (which you can read about in the hlp files).

Posted on 2002-01-15 04:53:10 by Mirno
No i didnt use lockresource, i gathered that locked the resource in memory making it unavadble to other processes?
I dont close any filehandle untill the process is exited (but a exception error occurs from midas11.dll cause the song.xm is in use or something). Basicly whats happening is the program extracts the XM file and writes it to file. Then the module library loads and plays the file, then the file is deleted.

Thanks Mirno, ill try your suggestions shortly
Posted on 2002-01-15 04:59:19 by ThrawN

When using FlushFileBuffers the filesize is instantly correctly reported (written 100% to disk) but the file still apears to be in use thus midas cant read it.

One step closer =)

Any ideas now?
Posted on 2002-01-15 05:07:47 by ThrawN
You must close the file handle after writing
the file (if not file size is 0).!
API LockResource returns a pointer to the datas.
You can use this pointer to write the datas to
a file.

good luck

Posted on 2002-01-15 09:32:38 by Test Department
Ok i used closehandle to close the filehandle. The file is written 100% now and can be loaded by winamp, but seems to still crash when trying to play it internatly in the program
Have a look for yourself at what im doing:
invoke FindResource, NULL, offset rname, RT_RCDATA
mov rhnd, eax
invoke SizeofResource, NULL, eax
mov rsize, eax
invoke LoadResource, NULL,
mov rloc, eax
invoke CreateFileA, offset module, GENERIC_WRITE,\
mov fhand, eax
invoke WriteFile, eax, (rloc), (rsize), offset bwrite, NULL
invoke FlushFileBuffers,
invoke CloseHandle, (fhand)
And from there the usal midas procedures...
Any idea's?

I replaced the brackets (][) to avoid problems on the board.
Posted on 2002-01-15 20:34:33 by ThrawN
Hi Thrawn,

you must use API LockResource.
API LoadResource don't (!) return a pointer to
the datas. This API return a handle.

And, I never need to use API FlushFileBuffers ?
But I think it is not bad to use it because Mirno
uses it.

OK, here is my example that works.

; API "FindResource" determines the location of a resource with the specified
; type and name in the specified module
push 10 ;lpType,address of resource type, RT_RCDATA
push OFFSET SoundName ;lpName, address of resource name
push hInstance ;hModule, resource-module handle
call FindResourceA ;- API Function -
cmp eax,0h ;
je ErrorPrg ;
mov handleResource,eax ;
; API "SizeofResource" returns the size, in bytes, of the specified resource.
push handleResource ;hrsrc, resource handle
push hInstance ;hModule, resource-module handle
call SizeofResource ;- API Function -
cmp eax,0h ;
je ErrorPrg ;
mov sizeResource,eax ;returned value is critical ( WIN32.HLP )
; API "LoadResource" loads the specified resource into global memory.
push handleResource ;hResInfo, resource handle
push hInstance ;hModule, resource-module handle
call LoadResource ;- API Function -
cmp eax,0h ;
je ErrorPrg ;
; API "LockResource" locks the specified resource in memory.
push eax ;hResData, handle to resource to lock
call LockResource ;- API Function -
cmp eax,0h ;
je ErrorPrg ;
mov pointerResource,eax ;pointer to the first byte of the resource

; API "CreateFileA" creates or opens a file, returns a handle to access object.
push 0h ;hTemplateFile,
push 80h ;dwFlagsAndAttributes, 80h=normal
push 2h ;dwCreationDistribution, CREATE_ALWAYS
push 0h ;lpSecurityAttributes,
push 0h ;dwShareMode,
push 40000000h ;dwDesiredAccess,GENERIC_WRITE
push OFFSET FileName ;lpFileName,pointer to filename
call CreateFileA ;- API Function -
cmp eax,-1 ;error ? INVALID_HANDLE_VALUE = -1
je ErrorPrg ;
mov handleFile,eax ;store handle in variable
; API "WriteFile" writes data to a file
push 0h ;lpOverlapped, structure overlapped I/O
push OFFSET returnFile ;lpNumberOfBytesWritten,
push sizeResource ;nNumberOfBytesToWrite, bytes to write
push pointerResource ;lpBuffer, address data write to file
push handleFile ;hFile, handle of file to write to
call WriteFile ;- API Function -
cmp eax,0h ;check for error
je ErrorPrg ;
; API "CloseHandle" closes an open object handle.
push handleFile ;hObject, handle of object to close
call CloseHandle ;- API Function -
cmp eax,0h ;check for error
je ErrorPrg ;

Posted on 2002-01-16 04:22:58 by Test Department
Originally posted by ThrawN
I replaced the brackets (][) to avoid problems on the board.

You can use the CODE and /CODE tags (put it with [ at beginning and ] at ending).

xor eax, eax

Posted on 2002-01-16 05:31:41 by JCP
Mirno, FlushFileBuffers should not be important in this
respect at all... the data might be only in the cache and
not on disk, sure, but windows (on openfile/readfile) will
just give you the stuff from the cache with no sweats :).

ThrawN, can't midas play the file from memory? It's some
time since I messed with midas, but I seem to recall no problems
with playing from memory? I've always found the solution of
writing something to disk temporarily and deleting it afterwards
is very messy and hacky :).

Also, why use a resource? Just include the file directly in
your executable, then you don't have to mess with resource
finding, locking, possible 95 limitations and whatnot. You can
do this either by using a "bin2asm" program (slow compilation on
large resources), or a "bin2coff" that creates a .obj you can
link directly into your executable (I've written such a tool,
I guess I should clean it up and post it at my site).
Posted on 2002-01-16 06:02:57 by f0dder
God i feel like a cock, found the source of the crashing after wondering why it mysterously worked in win98. I left a small int 3 in my code. Musta forgotton bout it during early debugging stages heh.
Now all works amazingly

f0dder: im not sure midas supports reading from memory? im only working on exports in the dll. No readme or nothing :(
If its possible pls explain =)

Thanks everyone else who helped
Posted on 2002-01-16 07:15:52 by ThrawN
ThrawN, take a look at . It's the
midas project, although they've had to rename it. Haven't tried the
download links from their page, as I have an old version somewhere
on a backup CD... if you can't figure it out yourself, I could dig it out.
You might want to consider alternatives like fmod (can be made
pretty small) or bass (seems to be good quality etc), I don't think
midas has been updated in a long time.
Posted on 2002-01-16 07:26:40 by f0dder
Cheers, found a PDF explaining the midas api.
Iv tried others like fmod and bass
Bass was the same just a tad bit larger in the end
fmod could be hella smalller but had some effects raped :\

Thanks tho iv gotton through the problems i had
Posted on 2002-01-16 07:47:58 by ThrawN
Yes, it doesn't seem fmod was made with correct playback in mind.
At least not minifmod. But if you don't use too many effects and
size counts... it might be okay.
Posted on 2002-01-16 08:07:50 by f0dder
Just a quick one, you mentioned about append before? is this better than using resources?
If so do you have a example of how to use it? i used it on delphi once a long time ago making good use of TFileStream =)
Posted on 2002-01-17 06:55:21 by ThrawN
Appending... you'd need some way of figuring out where in your exe
the data is stored (unused part of the MZ header is a good place).
Including into the executable is better though... I'm attaching my
bin2o tool here, it's great for this :).
Posted on 2002-01-17 07:06:38 by f0dder