views:

139

answers:

1

After reading Dynamically calling unmanaged dlls in .net

I've been trying to modify the code to my liking. I made a class that implements idisposable to wrap load calls in and free them when needed. However I can't seem to figure out the syntax if it is possible to use anonymous delegates with it.

var loaded=DynamicLibraryLoader.TryLoad("User32.dll");
var beeper=loaded.GetProcAddress("MessageBeep");
var type=typeof(Action<UInt32>);
Action<UInt32> beepAction2=(Action<UInt32>) Marshal.GetDelegateForFunctionPointer(beeper,type);

The last line throws an argument exception saying that the specified Type must not be a generic type definition. Is there a way around this or do I have to provide a named delegate to do anything unmanaged?

For reference of any interested in what you can do by default in windows with unmanaged code - Link (create shortcuts,dynamically load a DLL)

A: 

As the exception indicates, you must use a non-generic delegate when converting a native function pointer to managed code.

JaredPar
so there's no syntax or way around it?
Maslow
@Maslow, no there is not at this time
JaredPar
I guess since there are no other answers, I'll accept the answer that just reads back to me what the exception says, I would have preferred some resources,reference or some type of workaround ideas.
Maslow
@Maslow, unfortunately there's not much more to give. It's simply an unsupported scenario at this point
JaredPar