vb.net dllimport函数从C ++起,名称混乱(已导出随机函数名称) [英] vb.net dllimport Function from C++ with mangled name (random Function name exported )

查看:95
本文介绍了vb.net dllimport函数从C ++起,名称混乱(已导出随机函数名称)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个c ++ dll文件,它具有导出功能,但此功能的名称如下

I have a c++ dll file it have export Function but this Function have name like this

GetList @ Function @ Script @@ YA_NPEAUListInfo @@@ Z

GetList@Function@Script@@YA_NPEAUListInfo@@@Z

那么声明这种功能的方式又是什么.

so what the way to Declare this Kind of Function .

注意:函数的原始名称为GetList.

note: Function original name is GetList.

并且有一种方法可以动态调用此函数(LoadLib + GetProcAddr +调用Fucntion)

and is there a way to call this Function dynamically ( LoadLib + GetProcAddr + call the Fucntion )

推荐答案

与?GetList @ Function @ Script @@ YA_NPEAUListInfo @@@ Z"相对应的原始名称是"bool __cdecl Script :: Function :: GetList(struct ListInfo *)",它似乎是类的成员.如果它是非静态成员函数,则不能是 无需传递父 Function 对象的实例即可简单调用.您还必须构建 ListInfo 参数.

The original name that corresponds to "?GetList@Function@Script@@YA_NPEAUListInfo@@@Z" is "bool __cdecl Script::Function::GetList(struct ListInfo *)", which appears to be a member of a class. If it is a non-static member function, then it cannot be simply called without passing the instance of the parent Function object. You also have to build the ListInfo parameter.

但是如果您认为它是一个可调用的静态函数,请考虑这样的声明:

<DllImport("MyDll.dll", CallingConvention:=CallingConvention.Cdecl, EntryPoint:="?GetList@Function@Script@@YA_NPEAUListInfo@@@Z")>
Function GetList(ByRef listInfo As ListInfo) As Boolean
End Function

还定义 ListInfo 类或结构.

Also define the ListInfo class or structure.

也许在C ++/CLR中创建新的中间类库更容易. VB.NET项目(使用添加引用"功能)可以引用此类库,并且可以导出对象(使用 可以直接在VB中使用的公共引用类" ).根据需要设计该库的接口.在此C ++类中,您可以访问本机类和函数,例如 Script :: Function ListInfo .您还可以轻松地将从VB接收的数据转换为本机代码所需的数据,例如 ListInfo 结构,反之亦然.可以将本机代码(文件)放在该类库中(如果有源代码),或者可以使用常规方法访问本机DLL.

Maybe it is easier to create a new intermediate Class Library in C++/CLR. Such libraries can be referenced by VB.NET projects (using Add Reference feature) and can export objects (defined with ‘public ref class’) that can be directly used in VB. Design the interface of this library according to your needs. Inside this C++ classes you can access the native classes and functions, such as Script::Function and ListInfo. You can also easily convert the data, received from VB, to the data required by native code, such as the ListInfo structure, and vice versa. It is possible to put the native code (files) inside this Class Library (if you have the sources), or you can access the native DLL using usual ways.

还要注意,在某些情况下,可以在本机C ++中使用特殊的.DEF文件来简化整齐的名称,并使用更简单的导出名称,例如"GetList"而不是?GetList @ Function @ Script". @@ YA_NPEAUListInfo @@@ Z".


这篇关于vb.net dllimport函数从C ++起,名称混乱(已导出随机函数名称)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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