动态地调用DLL [英] Dynamically P/Invoking a DLL

查看:197
本文介绍了动态地调用DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从.NET动态P / Invoke非托管代码的最佳方法是什么?

What is the best way to dynamically P/Invoke unmanaged code from .NET?

例如,我有一些非托管DLL,具有常见的C风格导出它们之间。我想通过一个DLL的路径,然后P / Invoke一个基于导出的名称的函数。在运行时,我不知道DLL名称。

For example, I have a number of unmanaged DLL's with common C-style exports between them. I would like to take the path to a DLL and then P/Invoke a function based on the exported name. I would not know the DLL name until runtime.

基本上,相当于 LoadLibrary GetProcAddress for .NET? (我有现有的代码,使用这些功能完成相同的目标,完全在非托管代码中)。

Basically, what is the equivalent of LoadLibrary and GetProcAddress for .NET? (I have existing code which uses these functions to accomplish the same goal, entirely in unmanaged code).

推荐答案

GetProcAddress的类型安全的托管包装应该可以帮助您。

This article describes a typesafe managed wrapper for GetProcAddress that should help you out.

http://blogs.msdn.com/jmstall/archive/2007/01/06/Typesafe-GetProcAddress.aspx

这篇关于动态地调用DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆