C#DLL运行时错误 - 构建,运行,但在尝试使用DLL函数时抛出未处理的异常 [英] C# DLL run-time error - builds, runs, but throws unhandled exception upon trying to use DLL functions

查看:497
本文介绍了C#DLL运行时错误 - 构建,运行,但在尝试使用DLL函数时抛出未处理的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译示例项目,显示了C#的 here 。它必须转换为VS2010,但是这样做不错。它构建,运行,但是当它尝试访问DLL函数时,它会死亡。

I am trying to compile the example project shown here for C#. It had to be converted to VS2010, but that worked fine. It builds, runs, but then dies when it tries to access a DLL function.

我制作了一系列图像显示我的步骤。您可以看到,我设计的设备是附加的,并且配置正确,但我真的不认为这与该问题有任何关系。在Form1.cs文件中,以下注释说明了如何使用DLL:

I made a series of images to show my steps. As you can see, the device I designed is attached and correctly configured, but I really don't think that has anything to do with the issue. Inside the Form1.cs file, the following comment explains how to use the DLL:

/*
PLEASE NOTE
You must add a reference to the FTChipIDNet.dll in order to use this sample
To do this:
1. Click on Solution explorer tab.
2. Right click the References tree.
3. Choose Add Reference option.
4. Browse to the FTChipIDNet.dll (as a personal preference I place this in my bin directory)
5. Click OK
*/

我遵循上面显示的说明,未定义的名称空间FTChipID的引用已修复。我还手动检查对象浏览器以确保GetNumDevices函数存在,并且它是。

I followed the instructions shown above and the undefined reference to the namespace FTChipID was fixed. I also manually checked the Object Browser to be sure the GetNumDevices function exists and it does.

单击按钮会产生此错误:

Clicking the button produces this error:


DLLNotFoundException未处理:

DLLNotFoundException was unhandled:

无法加载DLL'FTChipID.dll':找不到指定的模块。 (HRESULT的异常:0x8007007E)

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

在这一行代码:

FTChipID.ChipID.GetNumDevices(ref numDevices);

现在,您可能会想错误说需要FTChipID.dll,而不是FTChipIDNet.dll。 我想知道同样的事情。我有FTChipID.dll以及.lib和.h文件,但我不知道如何使用它们,或者他们需要为了这个程序找到它们。我尝试添加对FTChipID.dll的引用,但VS2010表示

Now, you may be thinking "the error says it needs FTChipID.dll, not FTChipIDNet.dll." I'm wondering the same thing. I have FTChipID.dll along with a .lib and .h file, but I don't know how to use them or where they need to be in order for this program to find them. I tried adding a reference to FTChipID.dll, but VS2010 said


无法添加对... \FTChipID.dll的引用。请确保该文件可访问,并且它是一个有效的程序集或COM组件。

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

我不知道意思是。有任何想法吗?谢谢提前。

I don't know what that means either. Any ideas? Thanks in advance.

推荐答案

FTChipIDNet.dll是FTChipID.dll的包装器,因此您需要添加对您的解决方案(如上所述),然后将FTChipID.dll复制到FTChipIDNet.dll所在的bin文件夹中。

FTChipIDNet.dll is a wrapper for the FTChipID.dll, so you need to add the reference to your solution (as you did above) and then copy the FTChipID.dll to the bin folder there FTChipIDNet.dll will be located.

这两个dll都应该位于您的解决方案的bin文件夹中,不能位于Windows \system32中。

Both dll's should be located in your solution's bin folder to operate and should not be located in windows\system32.

这篇关于C#DLL运行时错误 - 构建,运行,但在尝试使用DLL函数时抛出未处理的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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