All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
Asp.net直接保存文件到客户端_[Asp.Net教程]
Asp.net,水晶报表之打印和导出格式_[Asp.Net教程]
Visual,Studio,2005集成开发环境图解(一)_[Asp.Net教程]
配置整合Win+Apache+PHP+MySQL+Tcomcat(或Resin)完全手册_[PHP教程]
如何对PHP程序中的常见漏洞进行攻击_php资料_编程技术
PHPUnit袖珍指南之安装PHPUnit_[PHP教程]
MS-SQL数据库开发—精典_[SQL,Server教程]
如何改变asp.net项目名称_[Asp.Net教程]
C#中GDI+变形的矩阵表示形式
ASP.NET中的Response对象的方法_[Asp.Net教程]
Reading number is top 10 pictures
小学生考试又现神作--还有外国的
这才是真正的人体艺术5
福利是必须的
Discharge accidentally Actresses by the breast1
传奇套装
The world's ten biggest attractions of inventory super the moon
牛奶和人奶哪个好?
A man's favorite things3--ZhouWeiTong
Men don't mature ten sign
ashlynn brooke
Download software ranking
卡丁车单机版
Proficient in Eclipse
Proficient in JavaScript
Unix video tutorial10
Boxer vs Yellow5
星际争霸1.08硬盘免安装版
Boxer's Top ten classic battle8
Unix video tutorial4
DreamWeaver8
虚拟机汉化软件
delv published in(发表于) 2014/1/8 7:03:49 Edit(编辑)
在C#中动态调用native,dll的导出函数_[Asp.Net教程]

在C#中动态调用native,dll的导出函数_[Asp.Net教程]

在C#中动态调用native dll的导出函数_[Asp.Net教程]

在 C++ 中我们能够通过 LoadLibrary, GetProcAddress 来动态调用 dll 的导出函数.
在 C# 中也能够用这样的方式吗?
在 DotNet 2.0 里面这样是可以的, 这完全得益于 2.0新增的一个函数
Marshal.GetDelegateForFunctionPointer 方法
此方法在 .NET Framework 2.0 版中是新增的。


将非托管函数指针转换为委托。
实例代码如下:



public delegate int MsgBox(int hwnd,string msg,string cpp,int ok);


[DllImport("Kernel32")]
public static extern int GetProcAddress(int handle, String funcname);
[DllImport("Kernel32")]
public static extern int LoadLibrary(String funcname);
[DllImport("Kernel32")]
public static extern int FreeLibrary(int handle);


private static Delegate GetAddress(int dllModule, string functionname, Type t)
{
int addr = GetProcAddress(dllModule, functionname);
if (addr == 0)
return null;
else
return Marshal.GetDelegateForFunctionPointer(new IntPtr(addr), t);
}


private void button1_Click(object sender, EventArgs e)
{
int huser32 = 0;
huser32 = LoadLibrary("user32.dll");
MsgBox mymsg = (MsgBox)GetAddress(huser32, "MessageBoxA", typeof(MsgBox));
mymsg(this.Handle.ToInt32(), txtmsg.Text, txttitle.Text , 64);
FreeLibrary(huser32);
}


来源:网络







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.