Loading DLLs with Microsoft Visual C# 2010 Express

房东的猫 提交于 2019-12-13 16:50:27

问题


I'm using Microsoft C# 2010 Express with the FrameLink Express drivers from Imperx. When I try to load the DLL at runtime, I get an exception:

Unable to load DLL 'VCECLB.dll': The specified module could not be found. (Exception from HRESULT:0x8007007E)

If I try to add the DLL as a reference, I get this message:

A reference to 'C:\\VCECLB.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.

Two questions:

  1. Is this an Express problem (i.e. some limitation with Express causing the problem)? I believe the source for the DLL is written in C++, but I wouldn't think that would matter.

  2. Is there a different way to reference the DLL and/or add it to the project? Something I'm doing wrong?

Finally, I've tried adding both the x86 and x64 versions, debug and release. Same failure to add as a reference every time.


回答1:


That DLL doesn't seem to be .NET (nor COM) code - therefore you cannot load it, nor add a reference to it.

Doesn't have anything to do with your Express version - it's just not a .NET "compatible" DLL and thus you can't load or reference it.

In order to use its functionality, you'll probably have to dive into more "arcane" (and more elaborate and more complicated) methods of calling raw C++ code from .NET - or find a .NET compatible counterpart or version of it.




回答2:


Actually, the answer appears to be in the first line of the message: Unable to load DLL 'VCECLB.dll': The specified module could not be found. (Exception from HRESULT:0x8007007E It says it cannot find the DLL, not that the DLL is not compatible. The DLL should be located with the other DLLs with your program, and you need to add the DLL to the solution.

If by some chance the DLL is compiled as Native C/C++ (i.e., Not .NET style), it can be called from a C/C++ that is a .NET style, but not a C# routine.

So, if the problem is that the module can be found but not loaded, you need to write a C++ (.NET) routine to call from your C# routine (.NET) to call the C++ (Not .NET).

All code that talks directly to hardware must do this at some level. Most do this for you using multiple DLLs.



来源:https://stackoverflow.com/questions/12886310/loading-dlls-with-microsoft-visual-c-sharp-2010-express

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!