• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            上善若水,厚德載物

            大道無親 大象無形 大音希聲 大巧若拙 大智若愚 【From small beginnings comes great things.】

             

            將托管C++下的System::String 轉換為標準字符串

                   今晚在將自動機與.Net下的繪圖工具窗口對接時遇到了C++托管下的string轉化為非托管的標準wstring問題,好在終于在微軟的msdn上找到解決辦法,感覺很好很強大,需收藏下...

             1 // convert_system_string.cpp
             2 // compile with: /clr
             3 #include <string>
             4 #include <iostream>
             5 using namespace std;
             6 using namespace System;
             7 
             8 void MarshalString ( String ^ s, string& os )
             9  {
            10      using namespace Runtime::InteropServices;
            11      const char* chars =
            12            (const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();
            13      os = chars;
            14      Marshal::FreeHGlobal(IntPtr((void*)chars));
            15  }
            16 void MarshalString ( String ^ s, wstring& os )
            17  {
            18      using namespace Runtime::InteropServices;
            19      const wchar_t* chars =
            20            (const wchar_t*)(Marshal::StringToHGlobalUni(s)).ToPointer();
            21      os = chars;
            22      Marshal::FreeHGlobal(IntPtr((void*)chars));
            23  }
            24 int main() 
            25  {
            26     string a = "test";
            27     wstring b = L"test2";
            28     String ^ c = gcnew String("abcd");
            29     cout << a << endl;
            30     MarshalString(c, a);
            31     c = "efgh";
            32     MarshalString(c, b);
            33     cout << a << endl;
            34     wcout << b << endl;
            35  }
            36 

             
            輸出結果是:

            test
            abcd
            efgh

             

            posted on 2009-05-24 01:53 ChenZB 閱讀(2675) 評論(2)  編輯 收藏 引用 所屬分類: C++

            評論

            # re: 將托管C++下的System::String 轉換為標準字符串 2009-05-31 18:54 none

            很勤奮 向你學習  回復  更多評論   

            # re: 將托管C++下的System::String 轉換為標準字符串[未登錄] 2009-05-31 19:15 chenzb

            @none
            最近很懶...慚愧慚愧  回復  更多評論   

            導航

            統計

            常用鏈接

            留言簿(6)

            隨筆分類

            隨筆檔案

            收藏夾

            友情鏈接

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            欧美亚洲国产精品久久| 久久久久黑人强伦姧人妻| 精品免费久久久久国产一区| 人妻丰满AV无码久久不卡| 精品综合久久久久久97| 国产亚洲精午夜久久久久久 | 久久久精品久久久久久 | 久久精品免费一区二区| 日韩久久久久中文字幕人妻 | 国产成人精品综合久久久久| 久久久久久人妻无码| 久久无码人妻一区二区三区午夜 | 午夜久久久久久禁播电影| 新狼窝色AV性久久久久久| 亚洲精品蜜桃久久久久久| 欧美黑人又粗又大久久久| 久久国产乱子伦免费精品| a级成人毛片久久| 亚洲中文字幕久久精品无码APP| 成人综合久久精品色婷婷| 亚洲香蕉网久久综合影视| 久久男人Av资源网站无码软件| 久久国产精品一区二区| 99久久精品免费国产大片| 久久久91人妻无码精品蜜桃HD | 天天久久狠狠色综合| 久久免费99精品国产自在现线| 国产精品乱码久久久久久软件| 亚洲精品乱码久久久久久蜜桃不卡| 伊人久久综合无码成人网| 久久精品国产秦先生| 色综合久久中文字幕综合网| 狠狠色丁香久久婷婷综合五月| 日本精品一区二区久久久| 久久久久综合中文字幕| 久久精品人妻中文系列| 精品久久无码中文字幕| 国产精品久久影院| 三级三级久久三级久久| 色欲综合久久躁天天躁蜜桃| 欧美久久天天综合香蕉伊|