简体   繁体   中英

C# void pointer?

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)

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM