DLL"导出"问题.

firela 2002-09-09 06:19:32
我写的DLL导出的函数名前都加了"_"(下划线),为什麽?

编译是加入了.DEF文件.

用LCC编译.

...全文
39 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
firela 2002-09-11
  • 打赏
  • 举报
回复
我用的是LCC没有C++的说,只有C,哪里还有EXTERN "C"?

结贴了.
firela 2002-09-10
  • 打赏
  • 举报
回复
终于搞定了,

我改了一下.DEF
LIBRARY ttdll
EXPORTS
xx
axxzz=axxzz
就行了

导出的PROC如下:
ttdll.dll
_LibMain@12
_axxzz@8
_xx@0
axxzz

其中:
int WINAPI __declspec(dllexport) axxzz(int x,int y)
{
return y;
}
int WINAPI xx()
{
i++;
return i;
}

为什么要写成axxzz=axxzz就行了?
没答案就算了,我就当他是LCC编译问题,要是有答案,我另开贴给分.

此贴明天结...
SmallPigII 2002-09-10
  • 打赏
  • 举报
回复
用extern "C"或者在一个倒出文件里写明
firela 2002-09-10
  • 打赏
  • 举报
回复
知道为什麽加(_)了,就是怎么才能去掉(_)?
firela 2002-09-10
  • 打赏
  • 举报
回复
glassshark(追赶蜗牛)
怎么在.DEF中"规定强制输出函数名",
我在.DEF中EXPORTS MYPROC了.还是有下划线.怎么去掉呢?
我在<WINDOWS系统编程>中看到加EXPORTS就行了,可是LCC编译后还有"_"的.

freelybird(阿愚)
__stdcall __cdecl __fastcall???
那怎么去掉下划线呢?

dou_ya 2002-09-10
  • 打赏
  • 举报
回复
因为C++支持名字分裂。也就是说,在C++中定义的变量名,或者是函数名,
编译以后的 .obj 文件中可以不是原来的名字。

要强制使用原来的名字的话,在函数定义前加上 extern "C"
比如:

extern "C" int haha()
{
return 0;
}
killhs 2002-09-09
  • 打赏
  • 举报
回复
说白了你去MSDN看看吧!!!
snsins 2002-09-09
  • 打赏
  • 举报
回复
啊~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
freelybird 2002-09-09
  • 打赏
  • 举报
回复
__fastcall
Home | Overview | How Do I

Microsoft Specific —>

The __fastcall calling convention specifies that arguments to functions are to be passed in registers, when possible. The following list shows the implementation of this calling convention.

Element Implementation
Argument-passing order The first two DWORD or smaller arguments are passed in ECX and EDX registers; all other arguments are passed right to left.
Stack-maintenance responsibility Called function pops the arguments from the stack.
Name-decoration convention At sign (@) is prefixed to names; an at sign followed by the number of bytes (in decimal) in the parameter list is suffixed to names.
Case-translation convention No case translation performed.


Note Future compiler versions may use different registers to store parameters.

Using the /Gr compiler option causes each function in the module to compile as fastcall unless the function is declared with a conflicting attribute, or the name of the function is main.

END Microsoft Specific

Example
In the following example, the function named DeleteAggrWrapper is passed arguments in registers:

// Example of the __fastcall keyword
#define FASTCALL __fastcall

void FASTCALL DeleteAggrWrapper(void* pWrapper);

freelybird 2002-09-09
  • 打赏
  • 举报
回复
__cdecl
Home | Overview | How Do I

Microsoft Specific —>

This is the default calling convention for C and C++ programs. Because the stack is cleaned up by the caller, it can do vararg functions. The __cdecl calling convention creates larger executables than __stdcall, because it requires each function call to include stack cleanup code. The following list shows the implementation of this calling convention.

Element Implementation
Argument-passing order Right to left
Stack-maintenance responsibility Calling function pops the arguments from the stack
Name-decoration convention Underscore character (_) is prefixed to names
Case-translation convention No case translation performed


Note For related information, see Decorated Names.

Place the __cdecl modifier before a variable or a function name. Because the C naming and calling conventions are the default, the only time you need to use __cdecl is when you have specified the /Gz (stdcall) or /Gr (fastcall) compiler option. The /Gd compiler option forces the __cdecl calling convention.

Example
In the following example, the compiler is instructed to use C naming and calling conventions for the system function:

// Example of the __cdecl keyword
_CRTIMP int __cdecl system(const char *);

END Microsoft Specific
freelybird 2002-09-09
  • 打赏
  • 举报
回复
__stdcall
Home | Overview | How Do I

Microsoft Specific —>

The __stdcall calling convention is used to call Win32 API functions. The callee cleans the stack, so the compiler makes vararg functions __cdecl. Functions that use this calling convention require a function prototype. The following list shows the implementation of this calling convention.

Element Implementation
Argument-passing order Right to left.
Argument-passing convention By value, unless a pointer or reference type is passed.
Stack-maintenance responsibility Called function pops its own arguments from the stack.
Name-decoration convention An underscore (_) is prefixed to the name. The name is followed by the at sign (@) followed by the number of bytes (in decimal) in the argument list. Therefore, the function declared as int func( int a, double b ) is decorated as follows: _func@12
Case-translation convention None


The /Gz compiler option specifies __stdcall for all functions not explicitly declared with a different calling convention.

Functions declared using the __stdcall modifier return values the same way as functions declared using __cdecl.

END Microsoft Specific

Example
In the following example, use of __stdcall results in all WINAPI function types being handled as a standard call:

// Example of the __stdcall keyword
#define WINAPI __stdcall

glassshark 2002-09-09
  • 打赏
  • 举报
回复
C语言的规定,你可以DEF中规定强制输出函数名。

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧