On February 5, a pig made me idle for a small experiment. This experiment is an unknown class library based on MS. It has been buried for a long time. It is a pity that no one has ever used it. The experiment uses sxs to bring out the bright spot of the buried grass. After a period of time (to be precise, the sxs was reviewed in 1 or 2 hours, and Google's MSCommunityTo kick a certain sxsArticleGradually, gradually, a kind of Impulse emerged. This is a very strong impulse. Of course, at last, it was restrained, now I am very happy to show you the results. (If you don't want to listen to me, you can simply read a few lines.Code).
In many cases, we will fall into the dll version control dilemma, and a set of hierarchical. netProgramThe configuration layout supports redirecting your Assembly. But in a typical Win32 environment, how does one solve this problem? Someone invented winsxs, a group of people realized winsxs, and others, such as me, have learned how to use winsxs, and finally explained how to use it with a thick face.
It is easy to create a winsxs, for example, the following example. However, when the environment becomes complex and the DLL becomes bloated, the configuration and debugging of winsxs and testing become very boring and time-consuming when EXE (COM) is involved. Someone has written a tool rumor that is very shit, and it can help you relieve your worries. Never trust it. Honestly, I have read the msdn chapter, and I will try to smell it like Chinese medicine, then hold your breath and swallow it in one breath... at this time, you can't say that you can do it with ease, but at least you can do it in the fight and know how to deal with it.
In a deeper sense, winsxs is as cheap as a dog skin plaster made for Windows DLLs, but it is a feasible method. There are always people and occasions in need. It has its own cache, which centrally manages the version of your files. There is an obscure rule to locate the files you really want in numerous paths, and then load them. It has a thread-related context to support dynamic calling. For example, the standard control version of Windows uses it to present different versions and styles.
For a long time, if you have found this code through Google, please ignore the above nonsense and directly look at the following codeJ
Class Program
{
[Dllimport ( " Kernel32.dll " , Setlasterror = True )]
Private Static Extern Intptr createactctxw ( Ref Actctx pactctx );
[Dllimport ("Kernel32.dll", Setlasterror= True)]
Private Static ExternIntptr createactctxa (RefActctx pactctx );
[Dllimport ( " Kernel32.dll " , Setlasterror = True )]
[ Return : Financialas (unmanagedtype. bool)]
Private Static Extern Bool Activateactctx (intptr hactctx, Out Intptr lpcookie );
[Structlayout (layoutkind. Sequential, pack = 4 , Charset = Charset. Unicode)]
Private Struct Actctx
{
Public Int Cbsize;
Public Uint Dwflags;
Public String Lpsource;
Public Ushort Wprocessorarchitecture;
Public Int16 wlangid;
Public String Lpassemblydirectory;
Public String Lpresourcename;
Public String Lpapplicationname;
Public Intptr hmodule;
}
Static VoidMain (String[] ARGs)
{
Actctx = New Actctx ();
Actctx. cbsize = Marshal. sizeof (actctx );
Actctx. lpsource = " Html2xhtml. dll " ;
Actctx. dwflags | = 0x008 ;
Actctx. lpresourcename = " #1 " ;
Intptr lpcookie;
VaR PTR = Createactctxw ( Ref Actctx );
VaR flag = Activateactctx (PTR, Out Lpcookie );
VaR utilities = New Xhtmlutilities ();
VaR txt = New WebClient (). downloadstring ( " Http://news.sina.com.cn " );
VaR result = Utilities. converttoxhtml (txt );
}
}
Next, I will put it into a Win32 resource and encapsulate it into a mixed-race. Net DLL using the load method of memory DLL. I believe more people will use it.