0
0

Hello everyone,
I am interested in using FMOD in MS.NET platform.
I currently use C# as the development environment.
OK I can import FMOD.dll functions but, i cannot seem to use them.


//function declaration
[DllImport(@”c:\fmod.dll”, CharSet = CharSet.Auto)]
public static extern string FSOUND_Init(int mixrate, int maxsoftwarechannels, int flags);

//a sample procedure using this function
private void button1_Click(object sender, System.EventArgs e)
{
label1.Text = FSOUND_Init(44100, 32, 0);
}


Any suggestions?
Thanks

  • You must to post comments
0
0

[quote="Longinus"]
Declare Auto Function FSOUND_Init Lib “fmod.dll” (ByVal rate As Integer, ByVal channels As Integer, ByVal flags As Integer) As Boolean

I start the fsound_init, gets TRUE… so it’s started.

But when I try the streamopen, I get 0 returned….and -1 in streamplay… and no sound, of course…. Everything is right (filepath, etc)quote]

I just tried a simple playback with vb.net and everything appears as if it should have worked, FSOUND_Init and FSOUND_Stream_Play both returned true boolean values, FSOUND_Stream_OpenFile returned valid long value (also tested it to return IntPtr), but no sound is being played.

Anyways, someone in the forum has converted the FMOD VB samples to VB.NET to take care of all the Declare functions, or you can try it yourself by upgrading the fmod.bas VB file to a VB.NET module. Other than that, I haven’t any other suggestions as to what could be wrong. Try searching the VB/Delphi forum, I know I saw the post.

Ron

  • You must to post comments
0
0

It’s working now!!
I did what you said..converted the fmod.bas to vb.net
And for some strange, odd reason, it workds….. using the same calls, the same declaration….

Well… thanks, and sorry for all the trouble..
Yes…. I found the post where someone had already converted to vb.net….. If I only searched more I would have find it in the first place..

  • You must to post comments
0
0

The first thing I notice is the path… wouldn’t that be “c:\fmod.dll”? I’m not familiar with C#, but if it’s anything like C or C++, you’ll need the double backslashes.

  • You must to post comments
0
0

When using DllImport, the .dll (fmod.dll) needs to be placed in the same directory as the application executable (Bin/Debug in VS.NET). Then you just refer to the name of the .dll

[DllImport( “fmod.dll”, EntryPoint=”FSOUND_Init” )]
public static extern bool FSOUND_Init( int rate, int channels, int flags );

[DllImport( “fmod.dll”, EntryPoint=”FSOUND_Stream_OpenFile” )]
public static extern IntPtr FSOUND_StreamOpenFile( string filepath, int mode, int memLength );

[DllImport( “fmod.dll”, EntryPoint=”FSOUND_Stream_Play” )]
public static extern int FSOUND_StreamPlay( int channel, IntPtr hstream );

Then in the constuctor of your WinForm or class that uses FMOD, call the FMOD_Init(…), in the Dispose or destructor, call FSOUND_Close()

I usually put all my PInvoke methods in a separate class, FMODWrapper for instance, as I gain further knowledge of FMOD, I’ll probably wrap them in full-blown classes.

From the above example:

public Form1()
{
FMODWrapper.FSOUND_Init( 44100, 16, 0 );
// other code
}

private void button1_click( object sender, EventArgs e )
{
OpenFileDialog ofd = new OpenFileDialog();
if ( ofd.ShowDialog() == DialogResult.OK )
{
IntPtr hstream = FMODWrapper.FSOUND_StreamOpenFile( ofd.FileName, (int)FMODWrapper.FSOUND_MODE.FSOUND_2D, 0 );
FMODWrapper.FSOUND_StreamPlay( -1, hstream );
}
}

Ron

  • You must to post comments
0
0

RonCY, thanks for your code…. It helped a lot..
The only problem is I can’t make it work in VB.Net…… it worked perfectly in C#..

In VB.net I’m not using dllimport (I can’t get it to work)… so I used this instead, for the 3 calls..

Declare Auto Function FSOUND_Init Lib “fmod.dll” (ByVal rate As Integer, ByVal channels As Integer, ByVal flags As Integer) As Boolean

I start the fsound_init, gets TRUE… so it’s started.

But when I try the streamopen, I get 0 returned….and -1 in streamplay… and no sound, of course…. Everything is right (filepath, etc)…… So what might be wrong?

Thanks a lot….

  • You must to post comments
0
0

Whoops, sorry for the double-post. It seems the forums only allow me to delete the most recent post I made, not my previous ones. So, I was forced to edit this one out.

  • You must to post comments
0
0

Shouldn’t the parameters be defined as Longs? As far as I’m aware, VB Integers are only 16-bit. However, Windows C/C++ ints and longs are the same size: 32 bits.

…or is it different in VB.NET?

Also, you’ve declared FSOUND_Init as returning a VB Boolean. The problem is, FSOUND_Init returns true and false in the C sense (1 = true, 0 = false). In VB however, true = -1 and false = 0. It might mean nothing, but this [b:ssk4dh4i]could[/b:ssk4dh4i] potentially lead to problems…

  • You must to post comments
0
0

In Vb.net Integers are now 32bits also… And I think the new boolean is also 0 and 1.
I also tried used alias, like Vb6 uses in the fmod.bas
Alias “_FSOUND_Stream_OpenFile@12”

But it doesn’t work either..
Well.. i’ll try something else

  • You must to post comments
0
0

[b:1yf5nqyf]RonCY[/b:1yf5nqyf], did you succeeded to use callbacks in C# ?

Thanks for your help,

Corrado

  • You must to post comments
0
0

CBetter….I did just like RonCY wrote, and it worked.

  • You must to post comments
Showing 10 results
Your Answer

Please first to submit.