Hi,

To get straight to the point: I'm new at C++. I have quite some programming experience, mainly in GML [Game Maker Language], PHP and Visual Basic. I use GML frequently, almost everyday. But it's problem is, it does not have a lot of functions. But you can use a DLL, which has a lot more functions. That's why I would really like to learn C++. To start off I thought I could make a simple audio DLL. To load and play audio files. I've read some tutorials before trying this, but I still have some questions. GML and PHP have an easy-to-understand help, but the MSDN is too difficult to understand for me [partly because I'm Dutch]. But anyway, so far I've got this header file:

#ifndef _DLL_H_
#define _DLL_H_
#define export extern "C" __declspec (dllexport)
#endif

This is just copied from an example, so I don't know exactly what it means. The only thing I actually know is that the word 'export' is defined.
Now a personal problem comes in: I tend to don't understand it if something isn't clear. So I hoped you could explain the rest as I could not find a clear explanation.

This is the source for the DLL I made:

#include <windows.h>
#include <string.h>

export double sound_load(char *filename, double loop)
	{
	PlaySound("play "+filename,

I know a bit more from this code: '#include' means that a list of functions is included [a library it's called I believe]. 'export' means that the output of the function is given to the calling thing. Furthermore 'double' means a variable of type double is returned by the function and the things between brackets are the arguments and what type they are.
As I said before, I don't get a thing at what they say at MSDN, so I was hoping someone could clearly explain what PlaySound needs [which and what type of arguments].

Btw, it's quite annoying, GML only uses char *s and doubles so could anyone explain to me what a char * is? I know it points to a variable in the memory which points to another one and that variable's value is used.

Ragoune

mvmalderen commented: Code tags on first post, great! +13
Nick Evan commented: for code-tags and being Dutch :) +21

Recommended Answers

All 4 Replies

char* is a pointer to a certain amount of memory containing characters (assuming space was allocated there), and can be used to store a string.

To play a file, you use the following arguments.

PlaySound("sound.wav", NULL, SND_FILENAME);

And to make it loop, just put it in a simple for loop.

Hope this helps.

Edit: Don't forget to link to Winmm.lib to use the PlaySound function.

This is just copied from an example, so I don't know exactly what it means. The only thing I actually know is that the word 'export' is defined.

__declspec(dllexport) is the magic incantation to add a name to the export table of a DLL. extern "C" is C++'s way of disabling the usual name mangling that makes overloading and such easier for compilers to manage. They're both really just boilerplate unless you care to learn more about the details of compilers and DLLs. ;)

The #define part says that after that line, everywhere you say export , you mean extern "C" __declspec (dllexport) . These two function tags are the same:

export
double sound_load(char *filename, double loop)
extern "C" __declspec (dllexport)
double sound_load(char *filename, double loop)

'#include' means that a list of functions is included [a library it's called I believe].

You include headers, and headers contain declarations for types, objects, and functions. When you say #include [I]{header}[/I] , the contents of the header are pasted into the source file just like if you had written it all out yourself.

As I said before, I don't get a thing at what they say at MSDN, so I was hoping someone could clearly explain what PlaySound needs [which and what type of arguments].

The first argument is a string, a file name for example. The second argument will probably be NULL because MSDN says it's NULL unless the third argument is SND_RESOURCE. The third argument is whatever best matches the location of the sound from the first argument.

If you're playing a sound file like sound_load seems to be doing, PlaySound is called like this:

PlaySound(filename, NULL, SND_FILENAME);

Thanks a lot, it makes it a lot more clear. Two more small questions: If you instead of filename = "sound.mp3", filename = "sounds/sound.mp3" use, will the sound be here:
-location of DLL-\sounds\sound.mp3 where the location and the map 'sounds' are in the same map?
Second one: If I want to know more things about a sound, like it's current position, length, size, etc., what do I need for that, does a header exists for that?

Ragoune

*Bump*

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.