Read through the
Language Tutorial on this site to learn more about C++
http://www.cplusplus.com/doc/tutorial/
You cannot use operator+ on c-strings. You must concatenate them using the usual functions. Windows provides versions of them so you don't need to use <strings.h> if you don't need it. Also, make sure to be const-correct:
1 2 3 4 5 6 7 8 9 10 11
|
#include <windows.h>
export STDCALL double sound_load( const char* filename, double loop )
{
char newfilename[ MAX_PATH ];
lstrcpyA( newfilename, "play " ); // same as <string.h>'s strcpy()
lstrcatA( newfilename, filename ); // same as <string.h>'s strcat()
return PlaySoundA( newfilename, NULL, SND_FILENAME || ((loop) ? SND_LOOP : 0) )
? 1.0 // is this the GML 'true' value?
: 0.0;
}
|
I have to wonder, though, if you really mean to do what you are doing. For example, if I call
sound_load( "C:\\WINDOWS\\Media\\tada.wav", 0.0 );
then the program will endeavor to load the file
play C:\WINDOWS\Media\tada.wav |
...which is obviously not correct.
Also, you should typically export functions using the
STDCALL calling convention -- unless GML expects to read them using the default
cdecl calling convention (which I doubt...)
As for only using
doubles.. I can't fix that, but you should know what the value for 'true' is. I listed it above as simply '1.0', but you will need to read the GML documentation to know what the value actually is. (If it is any non-zero value, then 1.0 is fine... you could just
return PlaySoundA(...
directly -- it will properly type-promote to
double.)
Before you go too much further, you should read up on the
PlaySound() function itself:
http://www.google.com/search?btnI=1&q=msdn+PlaySound
Notice that in order to compile your DLL, you will need to link with
Winmm.lib in order to use the function.
Alternatively, you could use
LoadModule() directly on the "winmm.dll" (kept in the Windows System directory, so you don't need to provide path information to load it), and
GetProcAddress() to find the
PlaySoundA() function.
Doesn't Game Maker provide functions for controlling sounds?
Anyway, I've got to go now... sorry I can't give you more information ATM.