• <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>

            上善若水,厚德載物

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

             

            將托管C++下的System::String 轉(zhuǎn)換為標(biāo)準(zhǔn)字符串

                   今晚在將自動(dòng)機(jī)與.Net下的繪圖工具窗口對(duì)接時(shí)遇到了C++托管下的string轉(zhuǎn)化為非托管的標(biāo)準(zhǔn)wstring問(wèn)題,好在終于在微軟的msdn上找到解決辦法,感覺(jué)很好很強(qiáng)大,需收藏下...

             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 

             
            輸出結(jié)果是:

            test
            abcd
            efgh

             

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

            評(píng)論

            # re: 將托管C++下的System::String 轉(zhuǎn)換為標(biāo)準(zhǔn)字符串 2009-05-31 18:54 none

            很勤奮 向你學(xué)習(xí)  回復(fù)  更多評(píng)論   

            # re: 將托管C++下的System::String 轉(zhuǎn)換為標(biāo)準(zhǔn)字符串[未登錄](méi) 2009-05-31 19:15 chenzb

            @none
            最近很懶...慚愧慚愧  回復(fù)  更多評(píng)論   

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿(6)

            隨筆分類(lèi)

            隨筆檔案

            收藏夾

            友情鏈接

            搜索

            積分與排名

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            久久这里只有精品18| 狠狠色丁香久久婷婷综合五月| 人妻无码久久一区二区三区免费| 亚洲国产欧美国产综合久久| 久久99国产综合精品女同| 国产精品日韩欧美久久综合| 久久久久国产成人精品亚洲午夜| 思思久久99热免费精品6| 久久精品国产亚洲av影院| segui久久国产精品| 久久只有这里有精品4| 久久狠狠高潮亚洲精品| 久久久WWW成人免费毛片| 亚洲中文字幕无码久久2017| 国产99久久久国产精品~~牛| 久久久国产亚洲精品| 久久国产精品久久精品国产| 久久综合视频网| 国产精品日韩深夜福利久久| 亚洲va久久久噜噜噜久久| 久久精品国产清自在天天线| 久久久久久亚洲AV无码专区| 综合久久一区二区三区| 久久久久免费精品国产| 欧美熟妇另类久久久久久不卡| 国产精品成人99久久久久| 久久99国产综合精品女同| 一本久久a久久精品vr综合| 四虎国产精品成人免费久久| 久久免费精品一区二区| 久久久久亚洲精品天堂| 亚洲人成网亚洲欧洲无码久久| 久久99精品久久久久久野外| 久久国产乱子精品免费女| 精品国际久久久久999波多野| 久久精品国产亚洲αv忘忧草| 欧美成a人片免费看久久| 久久久久国产成人精品亚洲午夜| 99久久无色码中文字幕| 久久福利青草精品资源站免费| 国产精品免费看久久久|