using System.Runtime.InteropServices;
internal delegate bool Delegate_Beep(uint dwFreq, uint dwDuration);
[DllImport("kernel32.dll")]
internal static extern IntPtr LoadLibrary(string lpLibFileName);
[DllImport("kernel32.dll")]
internal static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
[DllImport("kernel32.dll")]
internal static extern bool FreeLibrary(IntPtr hLibModule);
private void button1_Click(object sender, EventArgs e)
{
IntPtr vLibraryHandle = LoadLibrary("Kernel32.dll");
IntPtr vProcAddress = GetProcAddress(vLibraryHandle, "Beep");
Delegate_Beep Beep = Marshal.GetDelegateForFunctionPointer(
vProcAddress, typeof(Delegate_Beep)) as Delegate_Beep;
Beep(100, 100);
FreeLibrary(vLibraryHandle);
}
这个是我在网上找到的,可是无奈看不懂不知道怎么改,不管用什么办法,只要能动态调用这个API就行
internal delegate bool Delegate_Beep(uint dwFreq, uint dwDuration);
[DllImport("kernel32.dll")]
internal static extern IntPtr LoadLibrary(string lpLibFileName);
[DllImport("kernel32.dll")]
internal static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
[DllImport("kernel32.dll")]
internal static extern bool FreeLibrary(IntPtr hLibModule);
private void button1_Click(object sender, EventArgs e)
{
IntPtr vLibraryHandle = LoadLibrary("Kernel32.dll");
IntPtr vProcAddress = GetProcAddress(vLibraryHandle, "Beep");
Delegate_Beep Beep = Marshal.GetDelegateForFunctionPointer(
vProcAddress, typeof(Delegate_Beep)) as Delegate_Beep;
Beep(100, 100);
FreeLibrary(vLibraryHandle);
}
这个是我在网上找到的,可是无奈看不懂不知道怎么改,不管用什么办法,只要能动态调用这个API就行
把DLL放到你程序的目录下,它会自动搜索到的
[DllImport("CipherParse.dll")]
这样的方法他提示我找不到这个文件
internal delegate bool Delegate_g(string str1, string str2);
[DllImport("kernel32.dll")]
internal static extern IntPtr LoadLibrary(string lpLibFileName);
[DllImport("kernel32.dll")]
internal static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
[DllImport("kernel32.dll")]
internal static extern bool FreeLibrary(IntPtr hLibModule);
private void button1_Click(object sender, EventArgs e)
{
IntPtr vLibraryHandle = LoadLibrary("E:\\Work\\WebSiteVB\\Bin\\CipherParse.dll");
IntPtr vProcAddress = GetProcAddress(vLibraryHandle, "G_EncryptStr");
Delegate_g g = Marshal.GetDelegateForFunctionPointer(
vProcAddress, typeof(Delegate_g)) as Delegate_g;
g("str1", "str2");
FreeLibrary(vLibraryHandle);
}
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/
[DllImport("E:\\Work\\WebSiteVB\\Bin\\CipherParse.dll")]
static extern string G_EncryptStr(string str1, string str2);直接用G_EncryptStr这个方法是有返回的值的
[DllImport("kernel32.dll")]
internal static extern IntPtr LoadLibrary(string lpLibFileName);
[DllImport("kernel32.dll")]
internal static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
[DllImport("kernel32.dll")]
internal static extern bool FreeLibrary(IntPtr hLibModule);IntPtr vLibraryHandle = LoadLibrary(Server.MapPath("bin/CipherParse.dll"));
IntPtr vProcAddress = GetProcAddress(vLibraryHandle, "G_EncryptStr");
Delegate_g g = Marshal.GetDelegateForFunctionPointer(vProcAddress, typeof(Delegate_g)) as Delegate_g;
string str = g("123", "");
FreeLibrary(vLibraryHandle); 这样写就有返回值了,谢谢大家帮忙了,问题解决,散分了,str是我最后需要的值