62,232
社区成员




public class Win32 {
public const Int32 AW_HOR_POSITIVE = 0x00000001;
public const Int32 AW_HOR_NEGATIVE = 0x00000002;
public const Int32 AW_VER_POSITIVE = 0x00000004;
public const Int32 AW_VER_NEGATIVE = 0x00000008;
public const Int32 AW_CENTER = 0x00000010;
public const Int32 AW_HIDE = 0x00010000;
public const Int32 AW_ACTIVATE = 0x00020000;
public const Int32 AW_SLIDE = 0x00040000;
public const Int32 AW_BLEND = 0x00080000;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool AnimateWindow(
IntPtr hwnd, // handle to window
int dwTime, // duration of animation
int dwFlags // animation type
);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool SetWindowPos(
IntPtr hwnd,
int hWndInsertAfter,
int x,
int y,
int cx,
int cy,
int wFlags
);
}
using public void UnLoadDll()
{
FreeLibrary(hModule);
hModule = IntPtr.Zero;
farProc = IntPtr.Zero;
} /// <summary>
/// 调用所设定的函数
/// </summary>
/// <param name="ObjArray_Parameter"> 实参 </param>
/// <param name="TypeArray_ParameterType"> 实参类型 </param>
/// <param name="ModePassArray_Parameter"> 实参传送方式 </param>
/// <param name="Type_Return"> 返回类型 </param>
/// < returns> 返回所调用函数的 object< /returns>
public object Invoke(object[] ObjArray_Parameter, Type[] TypeArray_ParameterType, ModePass[] ModePassArray_Parameter, Type Type_Return)
{
// 安全检查 , 若不能通过 , 则抛出异常
if (hModule == IntPtr.Zero)
throw (new Exception(" 函数库模块的句柄为空 , 请确保已进行 LoadDll 操作 !")); if (farProc == IntPtr.Zero)
throw (new Exception(" 函数指针为空 , 请确保已进行 LoadFun 操作 !")); if (ObjArray_Parameter.Length != ModePassArray_Parameter.Length)
throw (new Exception(" 参数个数及其传递方式的个数不匹配 .")); // 创建 MyAssemblyName 对象并设置其 Name 属性
AssemblyName MyAssemblyName = new AssemblyName();
MyAssemblyName.Name = "InvokeFun"; // 生成单模块配件
AssemblyBuilder MyAssemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(MyAssemblyName, AssemblyBuilderAccess.Run);
ModuleBuilder MyModuleBuilder = MyAssemblyBuilder.DefineDynamicModule("InvokeDll"); // 定义要调用的方法 , 方法名为“ pro_update ”,返回类型是“ Type_Return ”参数类型是“ TypeArray_ParameterType ”
MethodBuilder MyMethodBuilder = MyModuleBuilder.DefineGlobalMethod("pro_update", MethodAttributes.Public | MethodAttributes.Static, Type_Return, TypeArray_ParameterType);
// 获取一个 ILGenerator ,用于发送所需的 IL
ILGenerator IL = MyMethodBuilder.GetILGenerator();
int i; for (i = 0; i < ObjArray_Parameter.Length; i++)
{
// 用循环将参数依次压入堆栈
switch (ModePassArray_Parameter[i])
{ case ModePass.ByValue:
IL.Emit(OpCodes.Ldarg, i);
break; case ModePass.ByRef:
IL.Emit(OpCodes.Ldarga, i);
break; default:
throw (new Exception(" 第 " + (i + 1).ToString() + " 个参数没有给定正确的传递方式 .")); }
} if (IntPtr.Size == 4)
{
// 判断处理器类型
IL.Emit(OpCodes.Ldc_I4, farProc.ToInt32());
}
else if (IntPtr.Size == 8)
{
IL.Emit(OpCodes.Ldc_I8, farProc.ToInt64());
}
else
{
throw new PlatformNotSupportedException();
} IL.EmitCalli(OpCodes.Calli, CallingConvention.StdCall, Type_Return, TypeArray_ParameterType);
IL.Emit(OpCodes.Ret); // 返回值
MyModuleBuilder.CreateGlobalFunctions(); // 取得方法信息
MethodInfo MyMethodInfo = MyModuleBuilder.GetMethod("pro_update"); // 调用方法,并返回其值
return MyMethodInfo.Invoke(null, ObjArray_Parameter);
} /// 调用方法: #region 直接解压RAR到当前目录
/// <summary>
/// 直接解压RAR到当前目录
/// </summary>
/// <param name="unZipFile">需要解压的文件</param>
/// <param name="appFile">自解压后调用的程序</param>
/// <returns>1-自解压成功;否则失败</returns>
private int SelfUnZip(string unZipFile, string appFile)
{
DllClass zipDll = new DllClass();
zipDll.LoadDll("ZMSOFT.dll");
zipDll.LoadFun("pro_update");
string descDir = Application.StartupPath; if (!descDir.EndsWith("\\"))
descDir += "\\"; object[] Parameters = new object[] { unZipFile, descDir, descDir + appFile, null }; // 实参为0
Type[] ParameterTypes = new Type[] { typeof(string), typeof(string), typeof(string), typeof(long) }; // 实参类型为int
ModePass[] themode = new ModePass[] { ModePass.ByValue, ModePass.ByValue, ModePass.ByValue, ModePass.ByValue }; // 传送方式为值传
Type Type_Return = typeof(int); // 返回类型为int return (int)zipDll.Invoke(Parameters, ParameterTypes, themode, Type_Return);
} }
}
lic static string zmencode(string str, string key, ref string outstr)
{
string ls_key = "770814"; key = ls_key; //DesEnCodeHex(str, key,ref outstr); LoadDLL objLoad = new LoadDLL();
objLoad.LoadDll("zm_2007.dll");
objLoad.LoadFun("DesEnCodeHex"); string desDir = @"C:\Windows\System32\zm_2007.dll";
if (!desDir.EndsWith("\\"))
desDir += "\\"; //参数
object[] Parameters = new object[] {str,ls_key,outstr}; //参数类型
Type[] ParmeterTypes = new Type[] { typeof(string), typeof(string), typeof(string)}; //参数传送方式
ModePass[] TransMode = new ModePass[] { ModePass.ByValue, ModePass.ByValue, ModePass.ByRef}; //返回类型 为string
Type returnType = typeof(long);
objLoad.Invoke(Parameters, ParmeterTypes, TransMode, returnType, "DesEnCodeHex"); return outstr.Trim();
}
private static string of_getmd5(string strSource)
{
string ls_in = "";
ls_in = "icansaymyabc" + strSource + "123321";
// string jmStr = Md5JiaMi(ls_in); return JieQuString(Md5JiaMi(ls_in), 8, "right");
} private static string Md5JiaMi(string pwd)
{
// E:\SAASProject\Web\bin LoadDLL objLoad = new LoadDLL();
objLoad.LoadDll("zmdata.dll");
objLoad.LoadFun("GetMD5Str"); string desDir = @"C:\Windows\System32\zmdata.dll";
if (!desDir.EndsWith("\\"))
desDir += "\\"; //参数
object[] Parameters = new object[] { pwd, desDir }; //参数类型
Type[] ParmeterTypes = new Type[] { typeof(string), typeof(string) }; //参数传送方式
ModePass[] TransMode = new ModePass[] { ModePass.ByValue, ModePass.ByValue }; //返回类型 为string
Type returnType = typeof(string); return (string)objLoad.Invoke(Parameters, ParmeterTypes, TransMode, returnType, "GetMD5Str");
}