Jump to content
Tuts 4 You

uFMOD & C++ (Visual)


Recommended Posts

Hey Hey, I'm using Visual C++ 9.0 Express Edition, i'm trying to add a XM to a program the example file supplied with uFMOD are getting me no where, i'm pretty n00b at C++, but any kind of help would be great ;)

Link to comment

Here's how you do it. Put ufmod.h in the same dir as your project, add an include to it in your project. Now add the .xm file to your resource section and in the code, use this API

uFMOD_PlaySong((void *)id(xm file id in resource section),hInstance(duh ? :P),XM_RESOURCE(read ufmod documentation, it means look for xm file in resource section btw));

and you are done.

Edited by STN
Link to comment

Either add ufmod.lib and winmm.lib to the list of library dependencies in the project settings

or add those 2 lines either to your main cpp file or to ufmod.h:

#pragma comment(lib, "ufmod.lib")
#pragma comment(lib, "winmm.lib")

I usually just put them into ufmod.h so I can copy the two files to a new project without having to deal with the project settings.

What's left is including the header....

As for playing music, it's fairly easy:

uFMOD_PlaySong((void *)1, 0, XM_RESOURCE);

// It appears to be working with 0 instead of the instance, better do it the way STN suggested tho :D

Where 1 is the resource ID of the xm file in the resources. It's saved as RC_DATA type.

Can't test it right now, but you should be able to insert a new resource and give it a name.

Just call it RC_DATA.

Attached the header + the lib files (taken from the MASM dir, works fine with VC++)

//Eeeek WTF took me so long...


Edited by Killboy
Link to comment

I'm getting build errors, yeah !_! plus i don't quite follow you


EDit Still looking at Killboy reply XD

Edited by mynes
Link to comment

Killboy explained it better than me hehe. Also you might need to include "MMSYSTEM.H" if you get errors in ufmod.h when compiling the project (HWAVEOUT not being recognized). I had to include it in VC 6 for getting it to work :) .

Edited by STN
Link to comment

Just looking at your screen-shot, I see that you've inadvertantly cut-off 5 of the 7 error messages. :oops:

Notice that you're trying to use the hInstance variable, which is not even declared. To use that, you need to be making a windows program; one with WinMain.

Also the id(d.xm) should be replaced with the Resource_Id# of the XM file you've included.

Care to repost the image, with all of the errors shown?

Link to comment

ooops on the screen shot indeed that was due to my bad coding here is the updated one with the only true 3 error messages,

this is what i got so far khi51ppfo77l3uy1q9pz.jpg

i should also point out that i'm not using form it a command line thing i'm "trying" to do, also how do i find the Resource_Id# of the XM

Link to comment


That's what I'd say about Delphi :D

Hm, you got MSN or anything ? Maybe we can sort it better that way...

ICQ and Yahoo is fine by me too, just PM he some number.

No obligation of course lol

Link to comment

dont insult c++ best language(except his classes) after asm.

delphi is lame.

and vs told you all about error.

figure it out or use ufmod included sources.

Link to comment

lol delphi aint lame XD. it has useful sources. we all are entitled to our opinions and id rather that this didnt go down the wrong way.

Edited by Encrypto
Link to comment

Found out some of the problems, there where type'o's in the uFMOD.h file (not my fault :P )

also seen as my version is express it doesn't allow res files

Edited by mynes
Link to comment

if you want compile something you need visual studio pro

due express is a joke, you can do **** in it.

it has stripped mfc,docs,masm that you can install later.

but without mfc you will not compile a lot from inet sources.

encrypto people learn delphi due they think its easier. but c++ isnt hard and is flexible. multiplatform. delphi only windows and pc.

next java,php use similiar to c++ syntax so its easier later.

Link to comment

the build errors he's getting aren't the fault of IDE anyway so it doesn't matter if he compiles that code in pro or express.

But i agree express is not for serious coding, as according to microsoft, its for hobbyists :P

Link to comment

Lol Mynes u could have asked me ^^ u see me each day on MSN XD

i have asource in case u want it... the errors was first that the hInstance isn't decleared actually unused in console mode second the lib winmn,lib must be included into source u can check project configs to do that....... lest but not last the project should have been created as a Win32 Program :)

anyway any serious troubles, i'll be happy to help u !

Link to comment

The compile errors he gets are not the fault of the IDE. They are the fault of the programmer. No offense intended or anything.

Firstly, the Express edition of Visual Studio does not include the resource editor. Your method of including the XM is incorrect which is why you get the error you get about the void* as it is:

1.) Not part of a resource so XM_RESOURCE will not work.

2.) Is directly added to the project and is also not even named '1'.

I suggest you either create a resource file and include it by hand, or just download the full version of Visual Studio or use a different IDE / Compiler.

Link to comment

doesn't matter if its a console mode or win32 gui application. It should compile fine. Wiccaan mentioned most of the errors but i'll be one step ahead of all you and provide working examples for vc6(which i always use) and vc2005 express done in console mode ;) .


hope it helps :)

Edited by STN
Link to comment
doesn't matter if its a console mode or win32 gui application. It should compile fine. Wiccaan mentioned most of the errors but i'll be one step ahead of all you and provide working examples for vc6(which i always use) and vc2005 express done in console mode ;) .


hope it helps :)

The code given above (not the link you provided) are specific to a console application based on the entry point. Without modding the entry point that will not compile as a Window application as the entry point for that would be WinMain.

Link to comment

I dont get the problem here...

Console apps compiled with VC++ are compiled to work on Windows...

And you can of course use the API even if you dont have WinMain, just takes the right include files and libraries.

Link to comment

That wasn't what I meant, when you use Visual Studio you are given the option on which type of Win32 application you wish to create:

1.) Console Application

2.) Window Based Application

Both of which use different default entrypoints which was what I was pointing out above.

Console Applications use 'int main' while Window Based Applications use 'int WinMain'. Attempting to use either in the others place will result in a compiler error saying it was unable to find the entry point.

Link to comment
Here ya go mynes,

straight out of the uFMod download. use with VS or DevCpp. Works fine with 2k8 express.

lol i am sure he already had this as it is provided with ufmod download. Besides its too complex for an example when you just want to see how uFMOD_PlaySong works :P .

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...