Can you use .net 3.5 Action or Func as Marshalled unmanaged delegates?
After reading Dynamic call of unmanaged dll in .net
I am trying to modify the code to my liking. I created a class that implements idisposable to wrap upload requests and release them when needed. However, I cannot understand the syntax if anonymous delegates can be used 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 to indicate that the specified type should not be a generic type definition. Is there a way to get around this or should I provide a named delegate in order to do something unmanageable?
For the reference of anyone interested in what you can do by default in windows with unmanaged code - Link (create shortcuts, load DLLs dynamically)
+2
source to share