• CallingConvention理解


    CallingConvention理解

    有以下几个值可以使用:Cdecl, FastCall, StdCall, ThisCall, Winapi.

    Cdecl:由调用者清理栈资源。非常适合用在可变参数的函数调用上,例如printf.

    FastCall: Calling convention不支持。

    StdCall:由被调用者清理栈资源。这是调用native函数时默认的方式。

    ThisCall:第一个参数是this指针,会被存储在ECX寄存器里,而其它的参数会被压栈。这种方式通常用在调用未托管的DLL的方法或类。

    Winapi:实际上并不是一个calling convention,实际上会被默认的平台的calling convention替代。例如window上调用,会替换成StdCall,Windows CE.NET上则被替换成Cdecl.

    小例子:

    using namespace System;
    using namespace System::Runtime::InteropServices;
    public ref class LibWrap
    {
    public:
    
       // CallingConvention.Cdecl must be used since the stack is 
       // cleaned up by the caller.
       // int printf( const char *format [, argument]... )
    
       [DllImport("msvcrt.dll",CharSet=CharSet::Unicode, CallingConvention=CallingConvention::Cdecl)]
       static int printf( String^ format, int i, double d );
    
       [DllImport("msvcrt.dll",CharSet=CharSet::Unicode, CallingConvention=CallingConvention::Cdecl)]
       static int printf( String^ format, int i, String^ s );
    };
    
    int main()
    {
       LibWrap::printf( "
    Print params: %i %f", 99, 99.99 );
       LibWrap::printf( "
    Print params: %i %s", 99, "abcd" );
    }

    链接来源这里

  • 相关阅读:
    linux试题
    linux常用脚本
    nagios
    lvs/nginx/haproxy 负载均衡优缺点分析讲解
    一次SSLPeerUnverifiedException,SSLHandshakeException问题的分析
    [转]【安卓笔记】AsyncTask源码剖析
    linux下查看进程占用端口和端口占用进程命令
    which framework or library is best to use WebRTC
    [转]svn diff 替代工具
    [转]使用Subversion进行版本控制
  • 原文地址:https://www.cnblogs.com/cg88/p/9143866.html
Copyright © 2020-2023  润新知