在没有外部声明的情况下调用dll函数 [英] Calling dll function without extern declaration

查看:108
本文介绍了在没有外部声明的情况下调用dll函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
这是santosh,
在处理dll时,我从用户定义文件夹动态加载dll,而所有与此相关的信息仅是从此代码项目中获得的.

现在我想调用dll功能而不需要dll

Hi All,
This is santosh,
While dealing dlls i load dll dynamically from user define folder all information related i got from this code project only.

now i want to call dll fuction function without extern dfination of dll

推荐答案

.
您对问题的表述具有误导性,这就是人们为什么这样评论您的问题的原因.
实际上,我认为您可以做您想做的事.我不需要外部声明.

注意:外部声明本身不是定义,而只是声明.它说:这是一个函数原型(不带函数体"),用于给出调用的语法,其定义将在其他地方找到.是的,您实际上并不需要它.您只能使用函数类型.

当您已经加载了DLL之后,您需要执行GetProcAddress http://msdn.microsoft.com/en-us/library/ms683212(v=vs.85).aspx [
This is not about if it is possible or not, this is about the concept and perhaps, terminology.
Your formulation of the problem is misleading, that''s why people commented your Question like this.

In fact, I think you can do what you want. I don''t need external declaration.

Pay attention: external declaration is itself not a definition but only a declaration. It says: this is a function prototype (without the "function body") used to give a syntax for a call, and the definition will be found elsewhere. Yes, you don''t really need it. You can use only a function type.

When you already loaded the DLL you need to do GetProcAddress http://msdn.microsoft.com/en-us/library/ms683212(v=vs.85).aspx[^].

So you have the code, why not calling it? You need just some syntax for call. Here you need a function type. Usually, with C++ you use a lib file and *.h file, but you can do without it. A function type is enough.

For example, this is an example of function type from the code sample of "GetProcAddress Function" MSDN help page http://msdn.microsoft.com/en-us/library/ms683212(v=vs.85).aspx[^]:

typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);



现在,查看完整的代码示例(请参见上面的参考).您需要做的只是声明一个指向PGNSI的指针(请参见pGNSI),以通过对GetProcAddress的调用结果进行强制转换的类型来获取此指针的值.当您得到非空结果时,您就完成了.现在您可以呼叫pGNSI.

我希望现在就明白了.

—SA



Now, look at the full code sample (see reference above). All you need is to declare a pointer to PGNSI (see pGNSI) to obtain the value of this pointer though a type cast from the result of the call to GetProcAddress. When you get non-null result, your are done. Now you can call pGNSI.

I hope it''s clear now.

—SA


这篇关于在没有外部声明的情况下调用dll函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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