简体   繁体   English

在C#应用程序中导入和使用C ++ DLL函数

[英]Import and use C++ DLL functions in C# application

I am developing an application that communicates with some hardware using the C++ DLL provided by the hardware provider. 我正在开发一个使用硬件提供程序提供的C ++ DLL与某些硬件进行通信的应用程序。 I also have a header file for this DLL, but no source file. 我也有此DLL的头文件,但没有源文件。 In my C# application, I'm trying to import and call the DLL's functions like this: 在我的C#应用​​程序中,我试图导入和调用DLL的函数,如下所示:

public class MyClass
{
    [DllImport("CaGe.dll")]
    public static extern long someLibraryFunction();

    public void callLibFunction()
    {
        Console.WriteLine("function call: " + someLibraryFunction());
    }
}

The library.dll file is located in the same folder as the MyClass.cs file and also the rest of the project files. library.dll文件与MyClass.cs文件位于同一文件夹中,并且与其他项目文件位于同一文件夹中。 When I start the debugging session however, I first receive a dialog window from system saying: CAGE InitDll: Erro on load library "CdbClientInit" and after I click OK on that, an unhalted exception on the line where I call the library function occours. 但是,当我开始调试会话时,我首先从系统收到一个对话框窗口:CAGE InitDll:加载库“ CdbClientInit”上的Erro,然后单击OK,在调用库函数的那一行中出现了未停止的异常。

The exception says: System.DllNotFoundException: Exception from HRESULT: 0x8007045A 异常显示:System.DllNotFoundException:HRESULT的异常:0x8007045A

I found on the internet that this may be caused by a missing DLL that the CaGe.dll needs, so I tried to put the DLL through the Dependency Walker, but the results are a little bit confusing for me. 我在互联网上发现这可能是由CaGe.dll所需的缺少DLL引起的,因此我尝试将DLL通过Dependency Walker进行放置,但结果令我有些困惑。 Under the CAGE.DLL there are WS32_32.DLL, VERSION.DLL, KERNEL.DLL and USER32.DLL tabs, I susspect that the libraries I need are somwhere under the USER32.DLL tab, but I don't recognize any of them (if a missing DLL is what is causing this problem). 在CAGE.DLL下有WS32_32.DLL,VERSION.DLL,KERNEL.DLL和USER32.DLL选项卡,我怀疑我需要的库位于USER32.DLL选项卡下,但我无法识别其中的任何一个(如果缺少的DLL是导致此问题的原因)。

Any advice would be much appretiated :) 任何建议将不胜感激:)

More help to use C++ function in C# please check below URL 有关在C#中使用C ++函数的更多帮助,请检查以下URL

http://www.codeproject.com/Questions/107152/Using-aC-dll-in-aC-application http://www.codeproject.com/Questions/107152/Using-aC-dll-in-aC-application

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM