Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

c_stauffer's profile on WallpaperFusion.com
I have a script that modifies the system volume. It runs correctly in Visual Studio but not when run from DisplayFusion. Note that the function compiles in the "Edit Scripted Function" editor (had to back the syntax down a bit, what C# version does this compile against?)

Here is the code. When run (verbatim) from Visual Studio, it increments the system volume by 5. It runs in DisplayFusion but does not do anything to the volume. It relies on another dll, which is why I'm instantiating the Callables class in the reflected dll (cannot include the reference to the audio API calls I'm using from DisplayFusion). The handler for AssemblyResolve loads that second external dll when the first one fails due to being reflected. I hope this makes sense... I'm just curious what limitations the scripting interface has.

Edit: apologies for the poorly formatted code... I think it may be a limitation of the website. Pasting into a text editor should make it readable :)

Code

using System;
using System.Reflection;
using System.IO;

public static class DisplayFusionFunction
{
public static void Run()
{
//Your code goes here
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
Assembly asm = Assembly.LoadFile(@"C:\DisplayFusionFunctions\BkgFuncs.dll");
Type type = asm.GetType("BkgFuncs.Callables");
object obj = Activator.CreateInstance(type);
type.InvokeMember("IncrementVolume", BindingFlags.Default | BindingFlags.InvokeMethod, null, obj, new object[] { 5 });
}

static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
  {
string dllPath = @"C:\DisplayFusionFunctions";
string assemblyPath = Path.Combine(dllPath, args.Name.Substring(0,args.Name.IndexOf(',')) + ".dll");
return Assembly.LoadFrom(assemblyPath);
  }
}
Sep 24, 2014 (modified Sep 24, 2014)  • #1
c_stauffer's profile on WallpaperFusion.com
I fixed the script and it now modifies the volume. The issue? If you reflect assemblies through DisplayFusion, those assemblies can use a .NET version no greater than 3.5. 4.0 Client Profile and up do not work.

It also seems like the compiler being used is lower than C# 3.0, as the var implicit type keyword is not recognized in the editor.

All in all this functionality is awesome, can't wait to do more cool stuff with it :)
Sep 25, 2014  • #2
Jon Tackabury (BFS)'s profile on WallpaperFusion.com
You're in luck! We have a few ways that we're going to help you out in Beta 3:
- BFS.Audio will have built-in volume controls (up, down... etc)
- You can now reference external assemblies when editing a scripted function (no more need for reflection)

Both of those should help make your scripting much easier, stay tuned for Beta 3. :)
Sep 25, 2014  • #3
Jon Tackabury (BFS)'s profile on WallpaperFusion.com
Sorry, I missed your second question. The scripts are compiled internally using .NET 2.0 unless you are in Windows 8 and only have .NET 4.0 installed.
Sep 25, 2014  • #4
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(-)  Login to Vote(-)