使用的DllImport导入对象 [英] Using DLLImport to import an Object

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

问题描述

我有一个C ++类(SLABHIDDevice.dll)的DLL。我试图用这个DLL的功能在C#.net应用程序。这个DLL中包含了几种方法,我可以用这样的语句很容易地使用...



(我appolagize如果我得到一些术语错在这里我是新来使用dll文件)

 函数[DllImport(SLABHIDDevice.dll)] 
公共静态外部字节GetHidString
( INT32 deviceIndex,INT32 VID,PID的Int32,
字节hidStringType,字符串deviceString,
的Int32 deviceStringLength);

有关SLABHIDDevice.dll文档说,它也包含了一个类的对象,CHIDDevice。
和该对象具有成员函数整个列表如Open();



如果我尝试使用与上述相同的语法来导入打开(),我得到一个错误,指出它无法找到的Open()函数的入口点。这是因为Open()是CHIDDevice的成员?



这是从DUMPBIN DLL的妆...底部的三个功能是唯一我能够去上班?有谁知道语法我需要使用来获得其他的人?什么问号意味着前面函数名?



 文件SLABHIDDEVICE.dll 

的转储文件类型:DLL

节包含SLABHIDDevice.dll

00000000特性
47E13E0F时间日期戳周三03月19日12时23分43秒2008 $ b以下出口$ b 0.00版本
1序基地
26的功能
一批26名

序提示RVA名

4 0 00001000号?? 0CHIDDevice @@ QAE @ ABV0 @@ Z
5 1 00001330 ?? 0CHIDDevice @@ QAE @ XZ
6 2 00001430 ?? 1CHIDDevice @@ UAE @ XZ
7 3 00001080? 4CHIDDevice @@ QAEAAV0 @ ABV0 @@ Z
8 4 00020044 ?? _ 7CHIDDevice @@ 6B @
9 5 00001460?关闭@ CHIDDevice @@ QAEEXZ
10 6 00001C70?FlushBuffers @ CHIDDevice @@ QAEHXZ
11 7 00001CA0?GetFeatureReportBufferLength @ CHIDDevice @@ QAEGXZ
12 8 00001850?GetFeatureReport_Control @ CHIDDevice @@ QAEEPAEK @ Z
13 9 00001C80?GetInputReportBufferLength @ CHIDDevice @@ QAEGXZ
14一个00001BE0?GetInputReport_Control @ CHIDDevice @@ QAEEPAEK @ Z
15架b 00001A20?GetInputReport_Interrupt @ CHIDDevice @@ QAEEPAEKGPAK @ Z
16ç00001CB0?GetMaxReportRequest @ CHIDDevice @@ QAEKXZ
17ð00001C90?GetOutputReportBufferLength @ CHIDDevice @@ QAEGXZ
18Ë00001730?GetString的@ CHIDDevice @@ QAEEEPADK @ Z
19 F 00001CC0?GetTimeouts @ CHIDDevice @@ QAEXPAI0 @ Z
20 10 00001700?IsOpened @ CHIDDevice @@ QAEHXZ
21 11 000014A0?打开@ CHIDDevice @@ QAEEKGGG @ Z
22 12 00001360?ResetDeviceData @ CHIDDevice @@ AAEXXZ
23 13 00001810?SetFeatureReport_Control @ CHIDDevice @@ QAEEPAEK @ Z
24的14 00001B80?SetOutputReport_Control @ CHIDDevice @@ QAEEPAEK @ Z
25 15 000018C0?SetOutputReport_Interrupt @ CHIDDevice @@ QAEEPAEK @ Z
26 16 00001CE0?一个定时器,@ CHIDDevice @@ QAEXII @ Z
3 17 00001320 GetHidGuid
2 18 00001230 GetHidString
1 19 00001190 GetNumHidDevices

摘要

6000。数据
7000 .rdata
5000 .reloc节
4000 .rsrc
1C000的.text


解决方案

您无法使用P / Invoke来调用一个C ++类的实例方法。主要挂断的是,你不能创建一个类的对象,你无法找到所需的内存分配大小。传递隐含的this指针的实例方法是另一个问题,它需要一个寄存器传递。



您需要创建了一个托管包装类,需要使用C ++ / CLI语言。谷歌C ++ / CLI包装好的命中。


I have a dll for a c++ class (SLABHIDDevice.dll). I am trying to use the functions of this dll in a C#.net application. The dll contains several methods which I can use easily with statements such as this...

(I appolagize if i get some of the terminology wrong here I am new to using dlls)

[DllImport("SLABHIDDevice.dll")]
        public static extern byte GetHidString
            (Int32 deviceIndex, Int32 vid, Int32 pid,
            Byte hidStringType, String deviceString, 
            Int32 deviceStringLength);

The documentation for SLABHIDDevice.dll says that it also contains a class object, CHIDDevice. and that object has a whole list of member functions such as Open();

If I try to import Open() using the same syntax as above, I get an error saying that it can not find an entry point for the Open() function. Is this because Open() is a member of CHIDDevice?

This is the makeup of the dll from DUMPBIN... The bottom three functions are the only ones I am able to get to work? Does anyone know what syntax I need to use to get the other ones? What do the question marks mean that precede the function names?

Dump of file SLABHIDDEVICE.dll

File Type: DLL

  Section contains the following exports for SLABHIDDevice.dll

    00000000 characteristics
    47E13E0F time date stamp Wed Mar 19 12:23:43 2008
        0.00 version
           1 ordinal base
          26 number of functions
          26 number of names

    ordinal hint RVA      name

          4    0 00001000 ??0CHIDDevice@@QAE@ABV0@@Z
          5    1 00001330 ??0CHIDDevice@@QAE@XZ
          6    2 00001430 ??1CHIDDevice@@UAE@XZ
          7    3 00001080 ??4CHIDDevice@@QAEAAV0@ABV0@@Z
          8    4 00020044 ??_7CHIDDevice@@6B@
          9    5 00001460 ?Close@CHIDDevice@@QAEEXZ
         10    6 00001C70 ?FlushBuffers@CHIDDevice@@QAEHXZ
         11    7 00001CA0 ?GetFeatureReportBufferLength@CHIDDevice@@QAEGXZ
         12    8 00001850 ?GetFeatureReport_Control@CHIDDevice@@QAEEPAEK@Z
         13    9 00001C80 ?GetInputReportBufferLength@CHIDDevice@@QAEGXZ
         14    A 00001BE0 ?GetInputReport_Control@CHIDDevice@@QAEEPAEK@Z
         15    B 00001A20 ?GetInputReport_Interrupt@CHIDDevice@@QAEEPAEKGPAK@Z
         16    C 00001CB0 ?GetMaxReportRequest@CHIDDevice@@QAEKXZ
         17    D 00001C90 ?GetOutputReportBufferLength@CHIDDevice@@QAEGXZ
         18    E 00001730 ?GetString@CHIDDevice@@QAEEEPADK@Z
         19    F 00001CC0 ?GetTimeouts@CHIDDevice@@QAEXPAI0@Z
         20   10 00001700 ?IsOpened@CHIDDevice@@QAEHXZ
         21   11 000014A0 ?Open@CHIDDevice@@QAEEKGGG@Z
         22   12 00001360 ?ResetDeviceData@CHIDDevice@@AAEXXZ
         23   13 00001810 ?SetFeatureReport_Control@CHIDDevice@@QAEEPAEK@Z
         24   14 00001B80 ?SetOutputReport_Control@CHIDDevice@@QAEEPAEK@Z
         25   15 000018C0 ?SetOutputReport_Interrupt@CHIDDevice@@QAEEPAEK@Z
         26   16 00001CE0 ?SetTimeouts@CHIDDevice@@QAEXII@Z
          3   17 00001320 GetHidGuid
          2   18 00001230 GetHidString
          1   19 00001190 GetNumHidDevices

  Summary

        6000 .data
        7000 .rdata
        5000 .reloc
        4000 .rsrc
       1C000 .text

解决方案

You cannot use P/Invoke to call instance methods of a C++ class. The primary hang-up is that you can't create an object of the class, you cannot discover the required memory allocation size. Passing the implicit "this" pointer to the instance method is another problem, it needs to be passed in a register.

You'll need to create a managed wrapper for the class, that requires using the C++/CLI language. Google "C++/CLI wrapper" for good hits.

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

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