简体   繁体   中英

How to provide custom implementation for extern methods in .NET?

In C# the extern modifier is used to declare a method that is implemented externally. Usually it is used with DllImport attribute to call some function in unmanaged code.

I wonder if there is a way to provide custom implementation of extern method?

To understand better the problem consider the following use case. I have a set of functions implemented in unmanaged code and I'd like to supply pointers to these function in run-time (during the loading of assembly).

The same thing DllImport attribute does, but I'd like to provide pointers by myself.

This is possible although you would need to PInvoke several things ( LoadLibrary and GetProcAddress - see links below)... it is called "late binding native code"...

Some relevant links with source:

您将需要使用LoadLibraryGetProcAddress

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