The previous article introduced how to use the DLL created in C ++. Net to create a shortcut. Now, we use the reflection mechanism in. Net to dynamically call this DLL file.
Using system. reflection;
Private void _ REF ()
{
// Load the DLL file of the class
Assembly ass = assembly. loadfrom ("export cut. dll ");
// Obtain the type
Type TP = ass. GetType ("shortcutlib. Shortcut ");
// Obtain Method
Methodinfo MI = TP. getmethod ("CreateLink ");
Propertyinfo [] _ pI = TP. getproperties ();
// Create an instance
Object OBJ = system. activator. createinstance (TP );
Foreach (propertyinfo _ p in _ PI)
{
If (_ p. Name = "filepath ")
{
_ P. setvalue (OBJ, "C: // windows // notepad.exe", null );
}
Else if (_ p. Name = "lnkpath ")
{
_ P. setvalue (OBJ, environment. getfolderpath (environment. specialfolder. desktop) + "// ABC. lnk", null );
}
Else if (_ p. Name = "lnkdesc ")
{
_ P. setvalue (OBJ, "This runs Notepad", null );
}
Else if (_ p. Name = "workdir ")
{
_ P. setvalue (OBJ, "C: //", null );
}
}
MessageBox. Show (MI. Invoke (OBJ, null). tostring ());
}