Reputation: 738
Is there anyway to call a memory address (like (void*) f = 0xFFFF; ) WITHOUT IntPtr or any native Win32 functions. I need to do this for an executable loader (It is for an OS that uses a open source project called COSMOS)
Upvotes: 1
Views: 1803
Reputation: 3740
There is no way to do it in a proper C# high level way without using Marshal.GetDelegateForFunctionPointer
:
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void CallMeDelegate(int i);
CallMeDelegate del = (CallMeDelegate)Marshal.GetDelegateForFunctionPointer(new IntPtr(0xffff), typeof(CallMeDelegate));
Note that IntPtr isn't native Windows just because of its name: It is the typical pointer value for the current compilation target (32 or 64 bit).
You don't get around using that API I think, because you have to specify a calling convention for being able to use it in normal C# delegate syntax. Be happy with the fact, that Marshal.GetDelegateForFunctionPointer does all the dirty work for you, platform independently!
Upvotes: 1