A 有一个 C# 类,它简化了全局热键的处理。
此类使用 Win32-API 函数 RegisterHotKey()
来注册热键。
根据 MSDN,此函数需要一个 0x0000 到 0xBFFF 范围内的 ID 值
从应用程序调用和 0xC000 到 0xFFFF 范围内的 ID 值时
从共享 DLL 调用。 GlobalAddAtom()
可用于在运行时获取ID
在 DLL 中。
为了向类的用户隐藏这种区别,类本身应该决定哪个 注册热键时将使用 ID 范围。好吧,要做到这一点,类(class)必须 能够检测其代码是在应用程序内运行还是在 一个共享的 DLL。
但是如何做到这一点呢?执行此操作的最佳 C#/.NET 方法是什么?
最佳答案
试试这个:
bool isDll = this.GetType().Assembly.EntryPoint == null;
MSDN:
"Property Value A MethodInfo object that represents the entry point of this assembly. If no entry point is found (for example, the assembly is a DLL), a null reference (Nothing in Visual Basic) is returned. "
关于c# - 如何以编程方式检测代码是否在共享 DLL 或 exe 中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1633490/