Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Foobar Plugin: C++ only ? (Read 6282 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Foobar Plugin: C++ only ?

Is it possible to write foobar plugin DLL's in languages other then C++ ? For example, C# dll assemblies ?

Im asking this, because i wanted to use the .NET Remoting feature to relay info from foobar to other applications. The 'old' way of doing that in C++ seems to involve COM interoperability which is, quite frankly, a pain in the ass.

Foobar Plugin: C++ only ?

Reply #1
The only way you can make it happen is to wrap your C# code to use the C++ classes.

If you need the external code to call something which it cannot instantiate locally, you can write a C++ function in another source file which does the work.

If you need callbacks, you can design the callback service class in a C++ source file, then have it call functions in another file as necessary.

Hmm... Perhaps someone more versed in .NET has something to contribute?

Foobar Plugin: C++ only ?

Reply #2
I've written a component for Foobar in .NET and I'll offer a suggestion about remoting: not as easy as it seems.

A lot of things in Foobar aren't thread safe. You better be calling them from the right thread or bad things happen (I've done this too many times to count). I can't find any really good documentation on exactly how remoting is done, but it appears as if .NET does this in its own thread (or at least not in Foobar's thread, that part seems for sure). So if you remote something that is of the sort "play index number 5," .NET's remoting won't be in Foobar's thread and in general things mess up.

A possible alternative would be to create a hidden window on Foobar startup, as well as a seperate thread to handle remoting. When this seperate thread is asked to do something by remoting, you can pass messages off to your hidden window. This hidden window's window procedure will be in Foobar's main thread, and thus you can do whatever you please. But this method becomes nasty as you start to transfer more data around and have to use messages like WM_COPYDATA. Perhaps there is a better alternative to this? I dunno, if anyone has an idea that'd be awesome.

As far as using C#, kode54 is right on. You will need to write wrappers for all the Foobar features you wish to use in Managed C++. This actually isn't that hard if you know C++, but it sure is funky. I would tend to suggest that if you want to use .NET for Foobar, just write the entire thing in Managed C++.

Hopefully this helps.

Foobar Plugin: C++ only ?

Reply #3
If you are using COM, you can set the apartement mode to single-threaded, so the COM runtime will marshall all calls to objects created in that apartement automatically. This also seems to be available in .NET (STAThreadAttribute), however it only applies if you are using COM-Interop. I don't know enough about .NET threading to tell if there is a similar thing you can use without COM-Interop (and right now I don't have time to RTFMSDN ).

Foobar Plugin: C++ only ?

Reply #4
I ended up using native c++ instead, didnt want people having to install the framework just for one plugin. Thanks for the suggestions though.

About remoting, that could be - ive seen really big and useful implementations of remoting for these things, but im not sure how the threading works for those. What im pretty positive about, like foosion said, there are many attributes to determine just exactly WHAT .net will do with your calls.

Foobar Plugin: C++ only ?

Reply #5
I ended up using native c++ instead, didnt want people having to install the framework just for one plugin. Thanks for the suggestions though.


Framework 1.0 come with windowsXP and 1.1 come with windows updates. On this days you get lot of viruses if computer is not updated. So if people do not have it I think its not bigest problem howto get foobar plugin work

Foobar Plugin: C++ only ?

Reply #6
Fact is most people are still annoyed by having to install the framework, like people used to get annoyed installing the java virtual machine.

I develop in C# only lately, and i consider .NET a great thing, But for time being, until it becomes more standard (considering the framework will probably be integrated into vista) ill resort to bytecode ;]