zoukankan      html  css  js  c++  java
  • Windows Phone Runtime Component 中的类型转换

    Windows Phone Runtime Component 是Windows Phone 平台用来写C++类库的项目类型。

    主要目的是让C#和C++进行互操作,引用历史的C++代码,保护知识产权,提供性能等。

    这里要注意可能会涉及到多种类型系统,分别是:

    • 标准C++类型系统。可能很少会用到,但也难免。如:char, bool, int 等。
    • 微软Win32类型系统。都是一些宏定义,看着就烦。如:TCHAR, CHAR, LPSTR 等。
    • 微软Windows Runtime类型系统。为了在C++/CX和C#/.NET之间交互的通信类型。如:HSTRING等。
    • C++/CX类型系统:微软用于开发商店应用和手机应用的C++语言系统。例如:UInt8等。
    • C#/.NET类型系统。虽然CLR和C#的类型描述不大一样,但基本是100%映射的。
     
    C# .net CLR std c++ c++/cx windows runtime win32 Length
    bool Boolean bool bool Boolean   1
    byte Byte char char Char CHAR 8
    char Char __wchar_t char16 Char16 wchar_t 16
    short Int16 short int16 Int16   16
    ushort Int32 unsigned short uint16 UInt16 WORD  16
    int Int32 int int Int32   32
    uint UInt32 unsigned int uint32 UInt32 DWORD 32
    long Int64 long long int64 Int64   64
    ulong UInt64 unsigned long long uint64 UInt64 DWORD64 64
    float Single float float32 Single FLOAT  
    double UInt64 double float64 Double    
    string String std:wstring, L"" String^ HSTRING    
                 

    最常见的是C++代码中的字符串都是单字节的,如 char等,而要与C#中的双字节字符串交互,就必须在单字节和双字节之间做转换。当然还有其他类型的转换。

    wchar_t 到char

        DWORD nWLength = WideCharToMultiByte(CP_OEMCP, NULL, wchar_s, -1, NULL, 0, NULL, FALSE);
        char_s = new char[nWLength];
        DWORD nCLength = WideCharToMultiByte(CP_OEMCP, NULL, wchar_s, -1, char_s, nWLength, NULL, FALSE);

    char 到wchar_t

        DWORD nWLength = MultiByteToWideChar(CP_ACP, 0, (LPCCH)char_s, -1, NULL, 0);
        wchar_t *pwValue = new wchar_t[nWLength];
        DWORD nCLength = MultiByteToWideChar(CP_ACP, 0, (LPCCH)char_s, -1, pwValue, nWLength);

    String^ 到 wchar_t*

    String::Data()
  • 相关阅读:
    Eureka Server的多级缓存和过期机制
    eureka-client拉取注册表
    Ribbon的调用流程
    EurekaServer启动
    eureka的注册
    Eureka的客户端是怎么启动的?
    Ribbon的负载均衡源码
    Ribbon是怎么重构URL的?
    Maven添加本地jar
    window 常用软件记录
  • 原文地址:https://www.cnblogs.com/icuit/p/3491605.html
Copyright © 2011-2022 走看看