dllimport无法加载dll

时间:2021-06-17 21:08:57

I found Stack Overflow is one among the best group for all our clarifications. I have the native dll written in C. I compiled the proj using VC++ (VS 2008), Using my C# application I called the dll functions through Dllimport. The problem is it fails to load the dll. It says unable to load the dll.

我发现Stack Overflow是我们所有澄清中最好的组之一。我有用C语言编写的本机dll。我使用VC ++编译了proj(VS 2008),使用我的C#应用​​程序我通过Dllimport调用了dll函数。问题是它无法加载DLL。它说无法加载DLL。

I have compiled to the platform from x86 to x64 both my dll and my application. It would be really great if you guys help me for resolving this issue.

我已经编译到从x86到x64的平台我的dll和我的应用程序。如果你们帮助我解决这个问题,那真的很棒。

Is there any possibility to check whether why the dll is not loaded.

有没有可能检查为什么没有加载DLL。

Thanks in advance.

提前致谢。

3 个解决方案

#1


Try using sysinternal's Process Monitor to see where you application is looking to load the dll from.

尝试使用sysinternal的Process Monitor来查看应用程序从哪里加载dll。

The Win32 documenation for LoadLibrary links to details on how it searches for the dll.

LoadLibrary的Win32文档链接到有关如何搜索dll的详细信息。

#2


I had a problem with this once along these lines. I had a C++ DLL that acted as an interface to a piece of hardware, that I needed to call from C#. However, it would fail the DllImport call if the piece of hardware was not plugged in. This is because the DLL initialisation function was returning a failure, so C# just said it couldn't load the DLL, it may not be to do with where the DLL is.

我曾经沿着这些方面遇到过这个问题。我有一个C ++ DLL作为一个硬件的接口,我需要从C#调用。但是,如果没有插入硬件,它将无法通过DllImport调用。这是因为DLL初始化函数返回失败,所以C#只是说它无法加载DLL,它可能与那里没有关系DLL是。

Check that you are not causing some sort of error when you are setting up the DLL in your C code.

在C代码中设置DLL时,请检查是否没有引起某种错误。

#3


The Dependency Walker is a nice tool to analyze the stuff a dll uses to load. For native executables it is aslo able to load the exe and use "Profile" menu entry to even show the dll that were loaded using delay load which will not show up if just the dll is loaded.

Dependency Walker是一个很好的工具来分析dll用来加载的东西。对于本机可执行文件,它也可以加载exe并使用“Profile”菜单条目甚至显示使用延迟加载加载的dll,如果仅加载dll则不会显示。

#1


Try using sysinternal's Process Monitor to see where you application is looking to load the dll from.

尝试使用sysinternal的Process Monitor来查看应用程序从哪里加载dll。

The Win32 documenation for LoadLibrary links to details on how it searches for the dll.

LoadLibrary的Win32文档链接到有关如何搜索dll的详细信息。

#2


I had a problem with this once along these lines. I had a C++ DLL that acted as an interface to a piece of hardware, that I needed to call from C#. However, it would fail the DllImport call if the piece of hardware was not plugged in. This is because the DLL initialisation function was returning a failure, so C# just said it couldn't load the DLL, it may not be to do with where the DLL is.

我曾经沿着这些方面遇到过这个问题。我有一个C ++ DLL作为一个硬件的接口,我需要从C#调用。但是,如果没有插入硬件,它将无法通过DllImport调用。这是因为DLL初始化函数返回失败,所以C#只是说它无法加载DLL,它可能与那里没有关系DLL是。

Check that you are not causing some sort of error when you are setting up the DLL in your C code.

在C代码中设置DLL时,请检查是否没有引起某种错误。

#3


The Dependency Walker is a nice tool to analyze the stuff a dll uses to load. For native executables it is aslo able to load the exe and use "Profile" menu entry to even show the dll that were loaded using delay load which will not show up if just the dll is loaded.

Dependency Walker是一个很好的工具来分析dll用来加载的东西。对于本机可执行文件,它也可以加载exe并使用“Profile”菜单条目甚至显示使用延迟加载加载的dll,如果仅加载dll则不会显示。