Friday, 27 September 2013

Can't get Robert Giesecke's Unmanaged Exports to work when trying to export a C# function from a dll

Can't get Robert Giesecke's Unmanaged Exports to work when trying to
export a C# function from a dll

I created a dll in C# (in VS2012), that should export a function as
unmanaged. My C# code looks like this:
using RGiesecke.DllExport;
using System.Runtime.InteropServices;
using WMPLib;
namespace WMPNative
{
public class WMP
{
[DllExport]
public static string getCurrentlyPlayingSong()
{
WMPLib.WindowsMediaPlayer player = new
WMPLib.WindowsMediaPlayer();
if (null != player.currentMedia)
{
return player.currentMedia.name;
}
else
{
return null;
}
}
}
}
However, when I use dumpbin /exports, I don't see anything exported from
my dll. I also tried using [DllExport()],
[DllExport("getCurrentlyPlayingSong")] and
[DllExport("getCurrentlyPlayingSong", CallingConvention =
CallingConvention.Cdecl)], but neither produced different results. I'm
also getting 2 warnings, but they seem to me unrelated to the problem:
(Processing COM reference "WMPLib" from path
"C:\Windows\system32\wmp.dll". Type library importer encountered a
property getter 'sessionPlaylistCount' on type
'WMPLib.IWMPNowPlayingHelperDispatch' without a valid return type. The
importer will attempt to import this property as a method instead.
Processing COM reference "WMPLib" from path "C:\Windows\system32\wmp.dll".
At least one of the arguments for
'IWMPGraphEventHandler.NotifyAcquireCredentials' cannot be marshaled by
the runtime marshaler. Such arguments will therefore be passed as a
pointer and may require unsafe code to manipulate.
What am I doing wrong?

No comments:

Post a Comment