__cdecl强制带下划线的前缀 [英] __cdecl forcing prefix with underscore

查看:220
本文介绍了__cdecl强制带下划线的前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的公司向第三方提供了一个DLL,为他们提供了可以用来连接我们的应用程序的API函数。该DLL是用VC9编写的,API函数使用VC的默认调用约定(__cdecl)。第三方已经在这个界面上构建了它们的应用程序。

My company provides a third party with a DLL which provides them with API functions they can use to connect to our application. The DLL was written in VC9, and the API functions used VC's default calling convention (__cdecl). The third party has built their application around this interface.

我现在已经有了编写DLL更新版本的任务。我们希望DLL具有与旧版本完全相同的界面,因此可以互换使用。不幸的是,我们的开发环境现在是CodeGear RAD Studio 2007,所以我必须使用它编写DLL。

I have now been tasked with writing an updated version of the DLL. We want the DLL to have exactly the same interface as the old one so they can be used interchangeably. Unfortunately, our development environment is now CodeGear RAD Studio 2007, so I have to write the DLL using that.

最好的解决方案是使旧的和新的DLL将其函数导出为__stdcall。然后可以重新链接第三方应用程序,以期望__stdcall函数,并且每个人都将快乐。不幸的是,由于各种原因,这不大可能发生。

The best solution would be to make both the old and new DLLs export their functions as __stdcall. The third-party application could then be re-linked to expect __stdcall functions and everyone would be happy. Unfortunately, for various reasons this is unlikely to happen.

或者,我可以将我的DLL中的函数声明为__cdecl。第三方期望__cdecl函数,这似乎是一个很好的解决方案。不幸的是,CodeGear坚持在__cdecl函数的名称上添加一个下划线('_')。这意味着第三方应用程序必须有条件地调用 MyApiFunction(...) _MyApiFunction(...),取决于他们使用哪个DLL。

Alternatively, I can declare the functions in my DLL as __cdecl. The third-party expects __cdecl functions so this would seem to be a good solution. Unfortunately CodeGear insists on appending an underscore ('_') to the name of __cdecl functions. This means that the third-party application would have to make conditionally call MyApiFunction(...) or _MyApiFunction(...), depending on which DLL they use.

所以我的问题是,如何从我的新DLL导出API函数,使它们是__cdecl并且不是以下划线('_')为前缀?

So my question is, how can I export the API functions from my new DLL in such a way that they are __cdecl and are not prefixed with an underscore ('_')?

推荐答案

您应该使用.DEF文件:

You should use .DEF file:

EXPORTS
    HTMLayoutClassNameA = HTMLayoutClassNameA
    HTMLayoutClassNameW = HTMLayoutClassNameW
    HTMLayoutClipboardCopy = HTMLayoutClipboardCopy
    ...

这里我们有

externalname = internalname 

这篇关于__cdecl强制带下划线的前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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