【问题标题】:the use of __stdcall and __cdecl in Windows CE DLLs在 Windows CE DLL 中使用 __stdcall 和 __cdecl
【发布时间】:2012-09-07 13:51:59
【问题描述】:

我有一个适用于 Windows CE 6.0 x86 的 Visual Studio 2008 C++03 应用程序。我遇到了一个问题,即从 DLL 调用函数会导致访问冲突异常,但仅限于调试模式。

// DLL header
extern "C" BOOL __stdcall Foo( const wchar_t*, const wchar_t*, wchar_t*, unsigned long );

// program
#include "foo.h"
#pragma comment( lib, "foo.lib" )
int main()
{
    wchar_t f[ 100 ];
    Foo( L"something", L"nothing", f, countof( f ) );    // access violation
    return 0;
}

我意识到这可能是由许多不同的事情引起的,但我对在 DLL 标头中使用 __stdcall 感到好奇。在 Windows CE 中,默认值(对于 Windows API)是__cdecl。为什么这个库会使用__stdcall?会不会产生不利影响?

实际上,为什么要指定调用约定?

谢谢

【问题讨论】:

    标签: c++ dll windows-ce calling-convention


    【解决方案1】:

    在 Windows CE 中,__stdcall 是解析为 __cdecl 的宏。也就是说,它们指定了相同的调用约定。你的问题出在其他地方。使用调试器进行调查。

    可能会指定调用约定,因为它需要为 DLL 的桌面版本指定,并且为两个目标保持相同的源代码比使用没有实际效果的条件编译来混乱它更容易。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-25
      • 2013-02-09
      • 2010-09-11
      • 2011-10-14
      • 2012-07-20
      相关资源
      最近更新 更多