• <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 閱讀(2670) 評(píng)論(2)  編輯 收藏 引用 所屬分類: 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)

            隨筆分類

            隨筆檔案

            收藏夾

            友情鏈接

            搜索

            積分與排名

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            国产精品久久久久久五月尺| 久久综合狠狠色综合伊人| 国产精品免费久久久久久久久| 亚洲国产精品无码久久久蜜芽 | 久久综合视频网站| 亚洲欧美日韩精品久久| 91麻豆精品国产91久久久久久| 久久这里只有精品久久| 热久久国产精品| 久久久久亚洲AV无码去区首| 人妻少妇精品久久| 99久久免费国产精品特黄| 伊人久久大香线蕉亚洲| 久久久久人妻一区精品性色av| 狠狠色丁香久久综合五月| 99久久综合狠狠综合久久| 国产免费久久久久久无码| 合区精品久久久中文字幕一区| 亚洲欧洲精品成人久久曰影片 | 久久久久久久综合日本亚洲| 国产成人99久久亚洲综合精品| 久久久久久亚洲精品不卡 | 久久久无码精品亚洲日韩京东传媒 | 久久精品亚洲中文字幕无码麻豆| 久久亚洲精品无码AV红樱桃| 91麻豆精品国产91久久久久久| 中文成人无码精品久久久不卡| 久久久久亚洲av无码专区| 久久国产香蕉一区精品| 久久亚洲中文字幕精品有坂深雪| 青青草原综合久久| 久久99热这里只有精品66| 99久久久精品| 久久人人爽人人爽人人爽 | 日日狠狠久久偷偷色综合96蜜桃| 狠狠色婷婷久久一区二区| 久久97久久97精品免视看秋霞| 亚洲精品无码久久久久sm| 精品久久久久中文字幕一区| 久久伊人精品一区二区三区| 国产精品VIDEOSSEX久久发布|