Jump to content
Tuts 4 You

ufmod and c#


akusei

Recommended Posts

Posted

I'm trying to get ufmod to work with c#. I've followed their example and it works perfect! The problem is that if I add any images or icons to my c# app and compile those resources into the it with the build script then the application crashes every time.

I think it might be because the final link with the .res file which contains the .xm overwrites the previous images resources... maybe? Anyway, I'm lost and can't think of anything else to do. Does anyone have any experience with this? Here is what I'm doing:

1. Compile my .net resources with "resgen /compile MainForm.resx" which creates MainForm.resources

2. Run build.bat

MainForm.resources contains the .net app icon and an image for the form.

build.bat


@echo off
rem Build a mixed standalone CLI/C++ uFMOD examplerem *** CONFIG START
SET VC_ENV=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat
SET CSC_HOME=C:\Windows\Microsoft.NET\Framework\v4.0.30319
SET LNK_HOME=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin
rem *** CONFIG ENDif not exist "%VC_ENV%" goto Err1
if not exist "%CSC_HOME%\csc.exe" goto Err2
if not exist "%LNK_HOME%\link.exe" goto Err3
call "%VC_ENV%"
"%CSC_HOME%\csc" /res:MainForm.resources /target:module /addmodule:cliwrapper\i_ufmod.netmodule *.cs
"%LNK_HOME%\link" /LTCG /CLRIMAGETYPE:IJW /ENTRY:CCDKeygen.Program.Main /SUBSYSTEM:WINDOWS /ASSEMBLYMODULE:cliwrapper\i_ufmod.netmodule cliwrapper\i_ufmod.obj cliwrapper\ufmod.obj MainForm.netmodule mini.res kernel32.lib winmm.lib
goto TheEnd:Err1
echo Couldn't find the Visual Studio environment batch file:
echo %VC_ENV
goto TheEnd:Err2
echo csc.exe not found in %CSC_HOME%
goto TheEnd:Err3
echo link.exe not found in %LNK_HOME%:TheEnd
pause
@echo on
cls

mini.res is the resource file which contains the .xm data

It will crash with the above configuration. If I remove the .resources from the batch file and remove the references to the resources in code then no crash happens. Any help would be greatly appreciated.

-akusei

Posted

Is you version VC++ 2008 or higher if yes i thing you most remove this

// Remove CRT dependency in VC++ 2008

#pragma warning(disable:4483)

You sure you us the bsp:c#

// C++ wrapper for embedding unmanaged uFMOD code in .NET

// NOTE: ufmod.obj should be compiled in UNICODE flavour!

if you us this bsp:c# how is on the ufmod folder then us this bat file.

@echo off

rem Build a mixed standalone CLI/C++ uFMOD example

rem *** CONFIG START

SET VC_ENV=C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat

SET CSC_HOME=C:\Windows\Microsoft.NET\Framework\v2.0.50727

SET LNK_HOME=C:\Program Files\Microsoft Visual Studio 9.0\VC\bin

rem *** CONFIG END

if not exist "%VC_ENV%" goto Err1

if not exist "%CSC_HOME%\csc.exe" goto Err2

if not exist "%LNK_HOME%\link.exe" goto Err3

call "%VC_ENV%"

"%CSC_HOME%\csc" /target:module /addmodule:cliwrapper\i_ufmod.netmodule test.cs

"%LNK_HOME%\link" /LTCG /CLRIMAGETYPE:IJW /ENTRY:Program.Main /SUBSYSTEM:WINDOWS /ASSEMBLYMODULE:cliwrapper\i_ufmod.netmodule cliwrapper\i_ufmod.obj cliwrapper\ufmod.obj test.netmodule mini.res kernel32.lib winmm.lib

goto TheEnd

:Err1

echo Couldn't find the Visual Studio environment batch file:

echo %VC_ENV

goto TheEnd

:Err2

echo csc.exe not found in %CSC_HOME%

goto TheEnd

:Err3

echo link.exe not found in %LNK_HOME%

:TheEnd

pause

@echo on

cls

Posted (edited)

I'm not sure what you mean by bsp:c#?? I am using Microsoft Visual Studio 2010 and compiling the application with .NET framework 4.0. I am using the ufmod modules that came with ufmod, I did not recompile them and my app was written in C#. I am also using the .bat file from the example but I have modified it to work with my application.

I had to modify the bat file because my app has more than 1 .cs file and has resources. Also, I'm not sure where you want me to put "#pragma warning(disable:4483)", as I am not receiving any compile-time or link-time warnings.

thanks,

akusei

edit: my problem occurs at run-time, the application crashes because it tries to access non-existent resources. Those resources should be there because I compiled them in, but for some reason they are not.

Edited by akusei
EmberTheVulpix
Posted (edited)

akusei, I've only gotten ufmod to work in C# by recompiling ufmod as a DLL and using DMex by UFO-Pu55y to load the DLL from memory and map all the exports. I think there is an example about using DMex with ufmod to play music all from .NET resources in the DMex thread.

Edited by EmberTheVulpix
Posted (edited)

akusei, I've only gotten ufmod to work in C# by recompiling ufmod as a DLL and using DMex by UFO-Pu55y to load the DLL from memory and map all the exports. I think there is an example about using DMex with ufmod to play music all from .NET resources in the DMex thread.

this will work quite nicely, thanks!

-akusei

edit: unfortunately it doesn't work... I can't get dmex to load the DLL and so I tried to just drop the file to the filesystem and load it from there and it starts to play the music but stutters in an endless loop and freezes the app. I'm about to give up on this one!

Edited by akusei
EmberTheVulpix
Posted
drop the file to the filesystem and load it from there and it starts to play the music but stutters in an endless loop and freezes the app.
This also happened to me when using p/invoke. Very confusing as to why this is happening. It only worked when I used DMex. Anyways, looks like UFO-Pu55y replied with a fix for it.

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...