zoukankan      html  css  js  c++  java
  • 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" );
    }

    链接来源这里

  • 相关阅读:
    进制转化
    递归小结
    Java异常处理面试题归纳
    字符串相加 内存分配
    递归与循环
    cookie
    会话管理
    在javaweb中通过servlet类和普通类读取资源文件
    JS中遍历EL表达式中后台传过来的Java集合
    Ztree加载完成后显示勾选节点
  • 原文地址:https://www.cnblogs.com/cg88/p/9143866.html
Copyright © 2011-2022 走看看