调用DLL [英] calling DLL

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

问题描述

我已成功使用VC ++ 6.0调用DLL',并使用VC ++ 7.1

(.NET)。我只提到这一点,因为我对

流程感到不舒服,但它确实有效。最近我开始从.NET应用程序调用一个非托管的

DLL。它工作正常。现在我遇到了这样的情况:我试图从另一个DLL调用一个DLL中的函数。两者都是不受管理的,并且使用VC ++ 7.1构建了
。在调用DLL中,我将属性

page / linker / general / additional library目录设置为指向包含MyDll.lib和MyDll.dll的目录

。找不到入口点。我

我确定签名是正确的,并且DLL导入/导出

修饰符是正确的。一切都被编译为C(而不是C ++)。

任何建议都是最受欢迎的。


TIA,


Bill

解决方案

" Bill Grigg" < Bill Gr***@discussions.microsoft.com >在消息中写道

news:86 ********************************** @ microsof t.com ...

我已成功使用VC ++ 6.0调用DLL'并使用了VC ++ 7.1
(.NET)。我只提到这一点,因为我从来没有对
过程感到满意,但它确实起作用了。最近我开始从.NET应用程序调用一个
非托管的DLL。它工作正常。现在我遇到的情况是我试图从另一个DLL调用一个DLL中的函数。两者都是不受管理的

是使用VC ++ 7.1构建的。在调用DLL中,我将属性
页面/链接器/常规/附加库目录设置为指向包含MyDll.lib和MyDll.dll的
目录。找不到入口点。
我确信签名是正确的,并且DLL导入/导出
修饰符是正确的。一切都被编译为C(而不是C ++)。
任何建议都是最受欢迎的。




这可能是编译器名称装饰的问题(又名对于包含您要调用的函数的DLL,请执行以下操作:


dumpbin / exports YourDllNameGoesHere.dll


找到与您要调用的那个最接近的导出函数的名称。

。发布在这里。然后还在调用模块中显示该函数的声明

,并说明

调用者是用C还是C ++编写的。有可能有人会发现错误。


问候,



好在这里它是来自dumpbin:


转储文件rnavandrpop.dll


文件类型:DLL


部分包含以下RNAVandRPOP.dll导出


0特征

428CED7C时间戳日期5月19日15:48:12 2005

0.00版本

1序数基础

3个功能数量

3个名称数量


序数提示RVA

名称


1

0 0001A78A Relnav_Exec

2

1 0001A131 fnRNAVandRPOP

3

2 000585F4 nRNAVandRPOP


我正在尝试调用Relnav_exec。在dll项目中,它以这种方式声明:


__declspec(dllexport)void Relnav_Exec(

RNAV_Initial * init,

RNAV_Inputs *输入,

RNAV_stateOutput *州,

RNAV_TelemetryOutputs * telem);

在尝试调用它的dll项目中,它被声明为方式:


__declspec(dllimport)void Relnav_Exec(

RNAV_Initial * init,

RNAV_Inputs *输入,

RNAV_stateOutput * state,

RNAV_TelemetryOutputs * telem);


两个dll项目都使用选项Compile as C code。来自

链接器的错误消息如下:


TEES错误LNK2019:未解析的外部符号__imp__Relnav_Exec引用
函数_WrapRelnavExec中的



实际上我只是注意到即使我删除了对包含.dll和.lib的

目录的引用,也会收到相同的错误消息。这个

意味着我不知道DLL是不是被定位而不是

函数声明不正确。正如我在第一篇文章中提到的那样,
将DLL的路径放在附加库目录中。帮助...

比尔


" William DePalo [MVP VC ++]"写道:

" Bill Grigg" < Bill Gr***@discussions.microsoft.com >在消息中写道
新闻:86 ********************************** @ microsof t.com。 ..

我使用VC ++ 6.0成功调用了DLL',并且还使用了VC ++ 7.1
(.NET)。我只提到这一点,因为我从来没有对
过程感到满意,但它确实起作用了。最近我开始从.NET应用程序调用一个
非托管的DLL。它工作正常。现在我遇到的情况是我试图从另一个DLL调用一个DLL中的函数。两者都是不受管理的

是使用VC ++ 7.1构建的。在调用DLL中,我将属性
页面/链接器/常规/附加库目录设置为指向包含MyDll.lib和MyDll.dll的
目录。找不到入口点。
我确信签名是正确的,并且DLL导入/导出
修饰符是正确的。一切都被编译为C(而不是C ++)。
任何建议都是最受欢迎的。



这可能是编译器名称修饰(又名修改)的问题。<对于包含您要调用的函数的DLL,请执行以下操作:

dumpbin / exports YourDllNameGoesHere.dll

查找导出的名称与您试图呼叫的那个最匹配的功能。发布在这里。然后还在调用模块中显示该函数的声明,并说明
调用者是用C还是C ++编写的。有可能会有人发现错误。

问候,



" Bill Grigg" ; <毕******* @ discussions.microsoft.com>在留言中写道

news:97 ********************************** @ microsof t.com ...

好的,这是来自dumpbin:

转储文件rnavandrpop.dll
...
0 0001A78A Relnav_Exec
...
我想调用Relnav_exec。在dll项目中,它以这样的方式声明:

__ declspec(dllexport)void Relnav_Exec(
RNAV_Initial * init,
RNAV_Inputs *输入,
RNAV_stateOutput *状态,
RNAV_TelemetryOutputs * telem);

在尝试调用它的dll项目中,它以这种方式声明:

__ declspec(dllimport)void Relnav_Exec (
RNAV_Initial * init,
RNAV_Inputs *输入,
RNAV_stateOutput *州,
RNAV_TelemetryOutputs * telem);

哦,男孩。在上面的''exec''中,小写'e'>
看起来像拼写错误,名字看起来还不错。

其实我只是注意到即使我删除了包含.dll和.lib的
目录的引用,我也会得到相同的错误消息。
这对我来说意味着不知道DLL是不是被找到了而不是
函数声明不正确。正如我在第一篇文章中提到的那样,我将DLL的路径放在附加库目录中。
帮助...




那么也许问题不在于DLL地狱那么多的名称。您应该在库目录中构建DLL时,将链接器创建的导入库(.lib文件)置于
。确保系统上只有一个

的DLL副本。然后,如果您正在调试可执行文件,

您可以将DLL放在与可执行文件相同的目录中。你之前没有
将DLL放在PATH的其他目录中吗?

你呢?


另外,如果你正在调试DLL,你可以转到你的项目'

调试属性设置。然后在标有Command的方框中。输入隐式加载DLL的可执行文件的名称

。您还可以输入任何

可选参数以及启动目录。


问候,



I have been successfully calling DLL''s using VC++ 6.0 and also using VC++7.1
(.NET). I only mention this because I have never felt comfortable with the
process, but nonetheless it did work. Recently I started calling an unmanaged
DLL from a .NET app. It worked fine. Now I have the situation where I am
trying to call a function in one DLL from another DLL. Both are unmanaged and
are built with VC++7.1. In the calling DLL I set the property
page/linker/general/additional library directories to point to the directory
that contains MyDll.lib and MyDll.dll. The entry point is NOT being found. I
am sure that the signature is correct and that the DLL import/export
modifiers are correct. Everything is being compiled as C (instead of C++).
Any suggestions would be most welcome.

TIA,

Bill

解决方案

"Bill Grigg" <Bill Gr***@discussions.microsoft.com> wrote in message
news:86**********************************@microsof t.com...

I have been successfully calling DLL''s using VC++ 6.0 and also using
VC++7.1
(.NET). I only mention this because I have never felt comfortable with the
process, but nonetheless it did work. Recently I started calling an
unmanaged
DLL from a .NET app. It worked fine. Now I have the situation where I am
trying to call a function in one DLL from another DLL. Both are unmanaged
and
are built with VC++7.1. In the calling DLL I set the property
page/linker/general/additional library directories to point to the
directory
that contains MyDll.lib and MyDll.dll. The entry point is NOT being found.
I
am sure that the signature is correct and that the DLL import/export
modifiers are correct. Everything is being compiled as C (instead of C++).
Any suggestions would be most welcome.



It may be an issue of compiler name decoration (aka mangling).

For the DLL that contains the function you are trying to call do this:

dumpbin /exports YourDllNameGoesHere.dll

Find the name of the exported function that most closely matches the one
that you are trying to call. Post that here. Then also show the declaration
of that function in the module that makes the call and state whether the
caller is written in C or C++. Chances are someone will spot the error.

Regards,
Will


OK here it is from dumpbin:

Dump of file rnavandrpop.dll

File Type: DLL

Section contains the following exports for RNAVandRPOP.dll

0 characteristics
428CED7C time date stamp Thu May 19 15:48:12 2005
0.00 version
1 ordinal base
3 number of functions
3 number of names

ordinal hint RVA
name

1
0 0001A78A Relnav_Exec
2
1 0001A131 fnRNAVandRPOP
3
2 000585F4 nRNAVandRPOP

I am trying to call Relnav_exec. In the dll project it is declared this way:

__declspec(dllexport) void Relnav_Exec(
RNAV_Initial *init,
RNAV_Inputs *inputs,
RNAV_stateOutput *state,
RNAV_TelemetryOutputs *telem);
In the dll project that is try to call it it is declared this way:

__declspec(dllimport) void Relnav_Exec(
RNAV_Initial *init,
RNAV_Inputs *inputs,
RNAV_stateOutput *state,
RNAV_TelemetryOutputs *telem);

Both dll projects use the option "Compile as C code". The error message from
the linker is the following:

TEES error LNK2019: unresolved external symbol __imp__Relnav_Exec referenced
in function _WrapRelnavExec

Actually I just noticed that even though I deleted the reference to the
directory that contains the .dll and .lib I get the same error message. This
implies to me that somehow the DLL is not being located as opposed to the
function declaration being incorrect. As I mentioned in my first post I
placed the path for the DLL in the "Additional libraries directories". Help...
Bill

"William DePalo [MVP VC++]" wrote:

"Bill Grigg" <Bill Gr***@discussions.microsoft.com> wrote in message
news:86**********************************@microsof t.com...

I have been successfully calling DLL''s using VC++ 6.0 and also using
VC++7.1
(.NET). I only mention this because I have never felt comfortable with the
process, but nonetheless it did work. Recently I started calling an
unmanaged
DLL from a .NET app. It worked fine. Now I have the situation where I am
trying to call a function in one DLL from another DLL. Both are unmanaged
and
are built with VC++7.1. In the calling DLL I set the property
page/linker/general/additional library directories to point to the
directory
that contains MyDll.lib and MyDll.dll. The entry point is NOT being found.
I
am sure that the signature is correct and that the DLL import/export
modifiers are correct. Everything is being compiled as C (instead of C++).
Any suggestions would be most welcome.



It may be an issue of compiler name decoration (aka mangling).

For the DLL that contains the function you are trying to call do this:

dumpbin /exports YourDllNameGoesHere.dll

Find the name of the exported function that most closely matches the one
that you are trying to call. Post that here. Then also show the declaration
of that function in the module that makes the call and state whether the
caller is written in C or C++. Chances are someone will spot the error.

Regards,
Will



"Bill Grigg" <Bi*******@discussions.microsoft.com> wrote in message
news:97**********************************@microsof t.com...

OK here it is from dumpbin:

Dump of file rnavandrpop.dll
...
0 0001A78A Relnav_Exec
...
I am trying to call Relnav_exec. In the dll project it is declared this
way:

__declspec(dllexport) void Relnav_Exec(
RNAV_Initial *init,
RNAV_Inputs *inputs,
RNAV_stateOutput *state,
RNAV_TelemetryOutputs *telem);
In the dll project that is try to call it it is declared this way:

__declspec(dllimport) void Relnav_Exec(
RNAV_Initial *init,
RNAV_Inputs *inputs,
RNAV_stateOutput *state,
RNAV_TelemetryOutputs *telem);
Oh boy. With the exception of what looks like a typo in the lower case ''e''
in ''exec'' above, the names look OK.
Actually I just noticed that even though I deleted the reference to the
directory that contains the .dll and .lib I get the same error message.
This
implies to me that somehow the DLL is not being located as opposed to the
function declaration being incorrect. As I mentioned in my first post I
placed the path for the DLL in the "Additional libraries directories".
Help...



Then maybe the problem is not so much name mangling as DLL Hell. You should
place the import library (.lib file) created by the linker at the time that
the DLL was built in the libraries directory. Make sure you have only one
copy of the DLL on your system. Then if you are debugging the executable,
you can put the DLL in the same directory as the executable. You didn''t
earlier place the DLL in one of the other directories along the PATH did
you?

Alternatively, if you are debugging the DLL, you can go to your project''s
Debug property settings. Then in the box labelled "Command" enter the name
of the executable that implicitly loads the DLL. You can also enter any
optional parameters as well as the startup directory.

Regards,
Will


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

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