本文介绍了如何在程序集加载时在程序集中运行某些代码,即可以自定义.net程序集入口点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dll的入口点名为DllMain.我们可以在此函数中编写一些代码来执行一些操作初始化作业,例如初始化库的私有堆.

Dll's  developed by VC++ have entry point named DllMain. We can write some code in this function to do someinitialization job, like initialize library's private heap.

现在,我希望一些代码在.NET程序集加载时运行.  可能吗?

Now, I want some code to run at a .NET assembly load time.  Does it possible?

推荐答案

在托管代码中最接近DllMain的是模块构造函数(在'< module>'类上具有特殊名称'.cctor'的方法).我不了解VB,但C ++/CLI和ilasm支持生成模块构造函数,但C#却不支持.

The closest thing to DllMain in managed code is the module constructor (a method with the special name '.cctor' on the '<module>' class). I don't know about VB, but C++/CLI and ilasm support generating a module constructor but C# does not.

https://blogs.msdn.microsoft. com/junfeng/2005/11/19/module-initializer-aka-module-constructor/


这篇关于如何在程序集加载时在程序集中运行某些代码,即可以自定义.net程序集入口点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 21:46