锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久婷婷五月综合成人D啪,高清免费久久午夜精品,久久久精品2019免费观看http://www.shnenglu.com/aaxron/category/17910.html璁板綍淇鐨勫嵃璁? zh-cnWed, 26 Jun 2019 10:57:07 GMTWed, 26 Jun 2019 10:57:07 GMT60c#鏉′歡緙栬瘧http://www.shnenglu.com/aaxron/archive/2019/06/26/216462.html澶╀笅澶╀笅Wed, 26 Jun 2019 10:03:00 GMThttp://www.shnenglu.com/aaxron/archive/2019/06/26/216462.htmlhttp://www.shnenglu.com/aaxron/comments/216462.htmlhttp://www.shnenglu.com/aaxron/archive/2019/06/26/216462.html#Feedback0http://www.shnenglu.com/aaxron/comments/commentRss/216462.htmlhttp://www.shnenglu.com/aaxron/services/trackbacks/216462.html Conditional compilation symbols
緙栬瘧鍣ㄥ懡浠よ閫夐」錛堜緥濡傦紝/define:DEBUG錛?
    鍙互鍦╒S2008鐨処DE榪涜璁劇疆, Project Property--->Build--->Conditional compilation symbols(濡傛灉澶氫釜縐戠爺浣跨敤閫楀彿闅斿紑)
    緋葷粺榛樿璁劇疆浜?DEBUG 鍜?TRACE
鎿嶄綔緋葷粺澶栧3紼嬪簭涓殑鐜鍙橀噺錛堜緥濡傦紝set DEBUG=1錛夈?/div>
婧愪唬鐮佷腑鐨勬潅娉紙渚嬪錛岀敤浜庡畾涔夌紪璇戝彉閲忕殑 #define DEBUG錛屼互鍙婄敤浜庡彇娑堝畾涔夊畠鐨?#undef DEBUG錛夈?/div>
     蹇呴』鍦╢ile鐨勬渶鍓嶆柟璁劇疆,#define debug鎴栬呯粍鍚堟搷浣?/div>
    #if (Debug && Trace)
        #define DebugAndTrace 
    #endif
ps:Conditional浣嶄簬using System.Diagnostics;
浠涔堟儏鍐典笅浣跨敤璇ユ爣璇嗙?
褰撶▼搴忎腑涓涓柟娉曟垨灞炴т笉鎯沖啀浣跨敤鏃?濡傛灉鎶婂畠鍒犳帀灝遍渶瑕佹妸寮曠敤鐨勫湴鏂逛竴涓竴涓叏閮ㄥ垹鎺変笉鐒跺氨浼氱紪璇戦敊璇?榪欐椂鎴戜滑灝卞彲浠ュ湪濉旂殑涓婇潰鍔犱竴涓猍Conditional("string")] 鐒跺悗紼嬪簭榪愯鏃跺氨浼氬拷鐣ュ畠
ps:[Conditional("string")]閲岄潰瀛楃涓查殢鎰忓彇  
濡傛灉鎯沖啀嬈¤皟鐢ㄩ偅涓柟娉曟垨灞炴ф庝箞鍔?
榪欎釜寰堢畝鍗?浣犲彧闇鍦ㄥ紩鐢ㄥ懡鍚嶇┖闂撮偅涓湴鏂硅繘琛屼竴涓畯瀹氫箟鎶婁綘鍦╗Conditional("string")]閲岄潰鐨勫瓧絎︿覆瀹氫箟鍑烘潵灝辮兘鐢ㄤ簡
C#-#define鏉′歡緙栬瘧
C#鐨勯澶勭悊鍣ㄦ寚浠や粠鏉ヤ笉浼氳漿鍖栦負鍙墽琛屼唬鐮佺殑鍛戒護錛屼絾鏄細褰卞搷緙栬瘧榪囩▼鐨勫悇涓柟闈紝甯哥敤鐨勯澶勭悊鍣ㄦ寚浠ゆ湁#define銆?undef銆?if,#elif,#else鍜?endif絳夌瓑錛屼笅闈粙緇岰#涓嬌鐢?define榪涜鏉′歡緙栬瘧鐨勫疄渚嬨?/div>
C#涓潯浠剁紪璇戞寚浠ょ敤浜庢寜鏉′歡鍖呭惈鎴栨帓闄ゆ簮鏂囦歡涓殑鏌愪簺閮ㄥ垎銆傚湪Visual Studio涓紝浼氱湅鍒拌鎺掗櫎鐨勪唬鐮佹樉紺轟負鐏拌壊銆?/div>
涓銆?define鍙互鐢ㄦ潵鍋氫粈涔?/div>
1銆佸綋璁″垝鍙戝竷涓や釜鐗堟湰鐨勪唬鐮佺殑鏃跺欍傚嵆鍩烘湰鐗堝拰鎷ユ湁鏇村鐗堟湰鐨勪紒涓氱増錛屽氨鍙互鐢ㄥ埌鏉′歡緙栬瘧鎸囦護錛?/div>
2銆佷緥濡傚悓涓涓枃浠剁粰silverlight銆亀pf銆亀inform絳変嬌鐢紝騫朵笖榪樿冭檻Debug鍜孯elease絳夛紝鏈夊ぇ閮ㄥ垎浠g爜鏄竴鏍風殑錛?/div>
3銆佹寚瀹氬嚱鏁板拰灞炴ф槸鍚︾紪璇戝埌鏈緇堜駭鍝佷腑鍘匯?/div>
浜屻?define鐢ㄦ硶
璇硶錛?define 鍚嶇О
娉ㄦ剰錛氳繖閲屽悕縐板彇Debug錛屼綘涔熷彲浠ュ彇鍏朵粬鍚嶇О濡侱ragon
1 #define Debug
璇存槑錛?/div>
1銆丏ebug鍙互鐪嬪仛鏄0鏄庣殑涓涓彉閲忥紝浣嗘鍙橀噺娌℃湁鐪熸鐨勫鹼紝瀛樺湪鏃?if Debug緇撴灉涓簍rue錛屽惁鍒欎負false錛?/div>
2銆?define鍗曠嫭鐢ㄦ病浠涔堟剰涔夛紝涓鑸槸鍜?if鎴栬匔onditional鐗規(guī)х粨鍚堜嬌鐢紱
3銆?define蹇呴』瀹氫箟鍦ㄦ墍鏈塽sing鍛藉悕絀洪棿鍓嶉潰錛?/div>
4銆丏ebug涓嶥EBUG鏄笉鍚岀殑錛孋#鍖哄垎澶у皬鍐?/div>
 


澶╀笅 2019-06-26 18:03 鍙戣〃璇勮
]]>C# invoke,BeginInvoke,EndInvokehttp://www.shnenglu.com/aaxron/archive/2016/09/08/214261.html澶╀笅澶╀笅Thu, 08 Sep 2016 02:16:00 GMThttp://www.shnenglu.com/aaxron/archive/2016/09/08/214261.htmlhttp://www.shnenglu.com/aaxron/comments/214261.htmlhttp://www.shnenglu.com/aaxron/archive/2016/09/08/214261.html#Feedback0http://www.shnenglu.com/aaxron/comments/commentRss/214261.htmlhttp://www.shnenglu.com/aaxron/services/trackbacks/214261.html 

C# invoke,BeginInvoke,EndInvoke
鍦ㄥ綰跨▼緙栫▼涓紝鎴戜滑緇忓父瑕佸湪宸ヤ綔綰跨▼涓幓鏇存柊鐣岄潰鏄劇ず錛岃屽湪澶氱嚎紼嬩腑鐩存帴璋冪敤鐣岄潰鎺т歡鐨勬柟娉曟槸閿欒鐨勫仛娉曪紝Invoke 鍜?nbsp;BeginInvoke 灝辨槸涓轟簡瑙e喅榪欎釜闂鑰屽嚭鐜扮殑錛屼嬌浣犲湪澶氱嚎紼嬩腑瀹夊叏鐨勬洿鏂扮晫闈㈡樉紺恒?br />姝g‘鐨勫仛娉曟槸灝嗗伐浣滅嚎紼嬩腑娑夊強鏇存柊鐣岄潰鐨勪唬鐮佸皝瑁呬負涓涓柟娉曪紝閫氳繃 Invoke 鎴栬?nbsp;BeginInvoke 鍘昏皟鐢紝涓よ呯殑鍖哄埆灝辨槸涓涓鑷村伐浣滅嚎紼嬬瓑寰咃紝鑰屽彟澶栦竴涓垯涓嶄細銆?br />鍐嶄婦涓畝鍗曚緥瀛愯鏄庝笅浣跨敤鏂規(guī)硶,姣斿浣犲湪鍚姩涓涓嚎紼?鍦ㄧ嚎紼嬬殑鏂規(guī)硶涓兂鏇存柊紿椾綋涓殑涓涓猅extBox.. 

using System.Threading;
//鍚姩涓涓嚎紼?nbsp;
Thread thread=new Thread(new ThreadStart(DoWork)); 
thread.Start(); 
//綰跨▼鏂規(guī)硶 
private void DoWork() 

    
this.TextBox1.Text="鎴戞槸涓涓枃鏈"

濡傛灉浣犲儚涓婇潰鎿嶄綔,鍦╒S2005鎴?008閲屾槸浼氭湁寮傚父鐨?img src="http://www.shnenglu.com/Images/dot.gif" alt="" /> 


姝g‘鐨勫仛娉曟槸鐢↖nvoke\BeginInvoke
using System.Threading;
namespace test
{
    
public partial class Form1 : Form
    {
        
public delegate void MyInvoke(string str1,string str2);
        
public Form1()
        {
            InitializeComponent();
        }
        
public void DoWork()
        {
            MyInvoke mi 
= new MyInvoke(UpdateForm);
            
this.BeginInvoke(mi, new Object[] {"鎴戞槸鏂囨湰妗?/span>","haha"});
        }
        
public void UpdateForm(string param1,string parm2)
        {
            
this.textBox1.Text = param1+parm2;
        }
        
private void button1_Click(object sender, EventArgs e)
        {
            Thread thread 
= new Thread(new ThreadStart(DoWork));
            thread.Start();
        }
    }
}


鐩稿叧璧勬枡錛欼nvoke 鍜?nbsp;BeginInvoke 鐨勭湡姝f兜涔?nbsp;銆佸湪澶氱嚎紼嬩腑濡備綍璋冪敤Winform
Control.BeginInvoke 鏂規(guī)硶  Visual Studio 2010Visual Studio 
2010 
鍦ㄥ垱寤烘帶浠剁殑鍩虹鍙ユ焺鎵鍦ㄧ嚎紼嬩笂寮傛鎵ц濮旀墭銆?br />鍏叡鏂規(guī)硶 BeginInvoke(Delegate) 鍦ㄥ垱寤烘帶浠剁殑鍩虹鍙ユ焺鎵鍦ㄧ嚎紼嬩笂寮傛鎵ц鎸囧畾濮旀墭銆?nbsp;
鍏叡鏂規(guī)硶 BeginInvoke(Delegate,Object[])  鍦ㄥ垱寤烘帶浠剁殑鍩虹鍙ユ焺鎵鍦ㄧ嚎紼嬩笂錛岀敤鎸囧畾鐨勫弬鏁板紓姝ユ墽琛屾寚瀹氬鎵樸?nbsp;
public Object EndInvoke(IAsyncResult asyncResult)
鍙傛暟錛歛syncResult 綾誨瀷錛歋ystem.IAsyncResult 
IAsyncResult錛岃〃紺虹壒瀹氱殑璋冪敤寮傛鎿嶄綔錛屽湪璋冪敤 BeginInvoke 鏃惰繑鍥炪?nbsp;

 



澶╀笅 2016-09-08 10:16 鍙戣〃璇勮
]]>
String.Formathttp://www.shnenglu.com/aaxron/archive/2016/09/02/214252.html澶╀笅澶╀笅Fri, 02 Sep 2016 06:23:00 GMThttp://www.shnenglu.com/aaxron/archive/2016/09/02/214252.htmlhttp://www.shnenglu.com/aaxron/comments/214252.htmlhttp://www.shnenglu.com/aaxron/archive/2016/09/02/214252.html#Feedback0http://www.shnenglu.com/aaxron/comments/commentRss/214252.htmlhttp://www.shnenglu.com/aaxron/services/trackbacks/214252.html 

姣忎釜鏍煎紡欏歸兘閲囩敤涓嬮潰鐨勫艦寮忓茍鍖呭惈浠ヤ笅緇勪歡錛?/span>

{绱㈠紩[,瀵歸綈][:鏍煎紡瀛楃涓?/span>]}

蹇呴』浣跨敤鎴愬鐨勫ぇ鎷彿錛?/span>“{”鍜?/span>“}”錛夈?/span>

杞箟澶ф嫭鍙?/span>

宸﹀ぇ鎷彿鍜屽彸澶ф嫭鍙瘋瑙i噴涓烘牸寮忛」鐨勫紑濮嬪拰緇撴潫銆傚洜姝わ紝蹇呴』浣跨敤杞箟搴忓垪鏄劇ず鏂囨湰宸﹀ぇ鎷彿鎴栧彸澶ф嫭鍙楓傚湪鍥哄畾鏂囨湰涓寚瀹氫袱涓乏澶ф嫭鍙?/span> ("{{") 浠ユ樉紺轟竴涓乏澶ф嫭鍙?/span> ("{")錛屾垨鎸囧畾涓や釜鍙沖ぇ鎷彿 ("}}") 浠ユ樉紺轟竴涓彸澶ф嫭鍙?/span> ("}")銆傛寜鐓у湪鏍煎紡欏逛腑閬囧埌澶ф嫭鍙風殑欏哄簭渚濇瑙i噴瀹冧滑銆備笉鏀寔瑙i噴宓屽鐨勫ぇ鎷彿銆?/span>

 

涓嬭〃鎻忚堪浜嗘瘡涓爣鍑嗘牸寮忚鏄庣鐨勬爣鍑嗘牸寮忔ā寮忥紝浠ュ強鍙氳繃璁劇疆鏉ヤ慨鏀規(guī)爣鍑嗘牸寮忕殑鍏寵仈 NumberFormatInfo 灞炴с?/span>

ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.chs/fxref_mscorlib/html/b42c00a5-84e5-51a1-b7e4-6aaae8dac25b.htm

ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.chs/dv_fxfund/html/580e57eb-ac47-4ffd-bccd-3a1637c2f467.htm

鏍煎紡妯″紡

璇存槑鍜屽叧鑱斿睘鎬?/span>

c銆?/span>C

璐у竵鏍煎紡

d銆?/span>D

鍗佽繘鍒舵牸寮?/span>

e銆?/span>E

縐戝璁℃暟錛堟寚鏁幫級鏍煎紡

f銆?/span>F

鍥哄畾鐐規(guī)牸寮?/span>

g銆?/span>G

甯歌鏍煎紡

n銆?/span>N

鏁板瓧鏍煎紡

p銆?/span>P

鐧懼垎姣旀牸寮?/span>

r銆?/span>R

寰榪旀牸寮?/span>

x銆?/span>X

鍗佸叚榪涘埗鏍煎紡

 



澶╀笅 2016-09-02 14:23 鍙戣〃璇勮
]]>
C#鍩虹鐭ヨ瘑鍔犲己錛屽肩被鍨嬶紝搴旂敤綾誨瀷http://www.shnenglu.com/aaxron/archive/2016/09/02/214251.html澶╀笅澶╀笅Fri, 02 Sep 2016 01:18:00 GMThttp://www.shnenglu.com/aaxron/archive/2016/09/02/214251.htmlhttp://www.shnenglu.com/aaxron/comments/214251.htmlhttp://www.shnenglu.com/aaxron/archive/2016/09/02/214251.html#Feedback0http://www.shnenglu.com/aaxron/comments/commentRss/214251.htmlhttp://www.shnenglu.com/aaxron/services/trackbacks/214251.htmlusing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TK;
namespace ConsoleTester
{
    class Program
    {
        public class SomeRef
        {
            public Int32 x;
        }
        public struct SomeVal
        {
            public Int32 x;
        }
        static void Main(string[] args)
        {
            var r1 = new SomeRef(); //鍫嗕笂鍒嗛厤
            var v1 = new SomeVal(); //鏍堜笂鍒嗛厤錛屽悓鏃剁‘淇濆肩被鍨嬪瓧孌靛垵濮嬪寲涓?.

            r1.x = 5;
            v1.x = 6;

            SomeRef r2 = r1;
            r2.x = 7;
            Console.WriteLine("r1.x={0}", r1.x);
            Console.WriteLine("r2.x={0}", r2.x);

            var v2 = v1;
            v2.x = 8;

            Console.WriteLine("v1.x={0}", v1.x);
            Console.WriteLine("v2.x={0}", v2.x);

            Console.Read();


        }
    }
}


澶╀笅 2016-09-02 09:18 鍙戣〃璇勮
]]>C++ CLI 鍙彉鍙傛暟http://www.shnenglu.com/aaxron/archive/2016/09/01/214249.html澶╀笅澶╀笅Thu, 01 Sep 2016 06:48:00 GMThttp://www.shnenglu.com/aaxron/archive/2016/09/01/214249.htmlhttp://www.shnenglu.com/aaxron/comments/214249.htmlhttp://www.shnenglu.com/aaxron/archive/2016/09/01/214249.html#Feedback0http://www.shnenglu.com/aaxron/comments/commentRss/214249.htmlhttp://www.shnenglu.com/aaxron/services/trackbacks/214249.htmlnamespace TK 
{
    public enum class LogLevel { Kernel, Fatal, Error, Warning, Infomation, Debug};
    public ref class LogHelper
    {
    public:
        static bool Open(String^ filename);
        static void Close();
        static bool Write(LogLevel level,String^ format, array<Object^>^ args);
        static bool WriteLine(LogLevel level,String^ format, array<Object^>^ args);
        static void SetLevel(LogLevel level);
    };
}


static void MarshalString(String^ net, CString& os) {
    LPCTSTR chars = (LPCTSTR)(Marshal::StringToHGlobalUni(net)).ToPointer();
    os = chars;
    Marshal::FreeHGlobal(IntPtr((void*)chars));
}
#pragma unmanaged
static CStringA CStrW2CStrA(const CStringW &cstrSrcW)
{
    int len = WideCharToMultiByte(CP_UTF8, 0, LPCWSTR(cstrSrcW), -1, NULL, 0, NULL, NULL);
    char *str = new char[len];
    memset(str, 0, len);
    WideCharToMultiByte(CP_UTF8, 0, LPCWSTR(cstrSrcW), -1, str, len, NULL, NULL);
    CStringA cstrDestA = str;
    delete[] str;

    return cstrDestA;
}
#pragma managed


澶╀笅 2016-09-01 14:48 鍙戣〃璇勮
]]>Dev Express 涓浜汿ipshttp://www.shnenglu.com/aaxron/archive/2016/07/21/214020.html澶╀笅澶╀笅Thu, 21 Jul 2016 01:54:00 GMThttp://www.shnenglu.com/aaxron/archive/2016/07/21/214020.htmlhttp://www.shnenglu.com/aaxron/comments/214020.htmlhttp://www.shnenglu.com/aaxron/archive/2016/07/21/214020.html#Feedback0http://www.shnenglu.com/aaxron/comments/commentRss/214020.htmlhttp://www.shnenglu.com/aaxron/services/trackbacks/214020.html
Dev Express

Skin Libraries
Skins 
for DevExpress components are shipped in compiled libraries. To apply a skin, ensure that a corresponding library is added to the References section of your project.

Common Skins
The DevExpress.Utils.v15.
2.dll library contains common skins such as the DevExpress Style, Office 2013, VS2010, Office 2010 Blue, etc. This library is automatically added to the References section of your project when any DevExpress control/component is added to the form.

Extra Skins
Certain additional skins are available 
in the DevExpress.BonusSkins.v15.2.dll library, which must be manually added to the References section if you need to use any of these bonus skins.

Custom Skins
You can customize any common or extra skin by creating a custom skin 
using the WinForms Skin Editor utility. The WinForms Skin Editor creates a skin library (.dll) containing custom skins. The created library must be manually added to the References section of your project.

Note
To use any extra or custom skin at runtime, you need to add the skin library registration code. See the Bonus and Custom Skin Registration topic to learn more.
[STAThread]
static void Main() {
    
// Skin registration.
    DevExpress.UserSkins.BonusSkins.Register();
    Application.Run(
new Form1());
}


浣垮姩鎬佺毊鑲ゅ嵆鍒葷敓鏁?br />It 
is possible to call the EnableFormSkins() method later, after the application startup. In this instance, the DevExpress.LookAndFeel.LookAndFeelHelper.ForceDefaultLookAndFeelChanged method needs to be called after the call to EnableFormSkins(). This forces the form's title bar to be repainted.
DevExpress.Skins.SkinManager.EnableFormSkins();
DevExpress.LookAndFeel.LookAndFeelHelper.ForceDefaultLookAndFeelChanged();
鎴栬?br />DevExpress.Skins.SkinManager.DisableFormSkins();
DevExpress.LookAndFeel.LookAndFeelHelper.ForceDefaultLookAndFeelChanged();


鍔ㄦ佹崲鐨偆
//娣誨姞鎺т歡 comboBoxEdit1
public partial class Form1 :  DevExpress.XtraEditors.XtraForm
{
    
public Form1()
    {
        InitializeComponent();
        
foreach (SkinContainer cnt in SkinManager.Default.Skins)
            comboBoxEdit1.Properties.Items.Add(cnt.SkinName);
        comboBoxEdit1.SelectedIndexChanged 
+= new EventHandler(comboBoxEdit1_SelectedIndexChanged);
    }
    
void comboBoxEdit1_SelectedIndexChanged(object sender, EventArgs e)
    {
        ComboBoxEdit comboBox 
= sender as ComboBoxEdit;
        
string skinName = comboBox.Text;
        
//DevExpress.LookAndFeel.UserLookAndFeel.Default.SkinName = skinName;
        this.LookAndFeel.SkinName = skinName;
    }
}


//using DevExpress.XtraBars.Helpers;
    public partial class Form1 :  DevExpress.XtraEditors.XtraForm
    {
        
public Form1()
        {
            InitializeComponent();
            
this.barManager1.ForceInitialize();
            alertControl1.BeforeFormShow 
+= alertControl1_BeforeFormShow;

            
//紱佹barManage鍙抽敭鏄劇ず
            this.barManager1.AllowCustomization = false;
            
this.barManager1.AllowShowToolbarsPopup = false;
            
//鍘婚櫎barManage鍙寵竟灝忎笁瑙?nbsp;鑷畾鍒?/span>
            this.barManager1.AllowQuickCustomization = false;


            
this.LookAndFeel.UseDefaultLookAndFeel = true;
            
//娣誨姞涓涓狟arSubItem DevExpress.XtraBars.BarSubItem mPaintStyle;
            
//娣誨姞鎹㈣偆
            SkinHelper.InitSkinPopupMenu(mPaintStyle);

            
//鏍囬鏍忔敮鎸佺毊鑲?/span>
            DevExpress.Skins.SkinManager.EnableFormSkins();
        }
}


澶╀笅 2016-07-21 09:54 鍙戣〃璇勮
]]>C#鍏抽敭瀛梚mplicit 鍜?explicithttp://www.shnenglu.com/aaxron/archive/2016/06/17/213744.html澶╀笅澶╀笅Fri, 17 Jun 2016 06:06:00 GMThttp://www.shnenglu.com/aaxron/archive/2016/06/17/213744.htmlhttp://www.shnenglu.com/aaxron/comments/213744.htmlhttp://www.shnenglu.com/aaxron/archive/2016/06/17/213744.html#Feedback0http://www.shnenglu.com/aaxron/comments/commentRss/213744.htmlhttp://www.shnenglu.com/aaxron/services/trackbacks/213744.htmlC#鍏抽敭瀛梚mplicit 鍜?nbsp;explicit

explicit錛圕# 鍙傝冿級
explicit 鍏抽敭瀛楃敤浜庡0鏄庡繀欏諱嬌鐢ㄥ己鍒惰漿鎹㈡潵璋冪敤鐨勭敤鎴峰畾涔夌殑綾誨瀷杞崲榪愮畻絎︺?nbsp;渚嬪錛屽湪涓嬮潰鐨勭ず渚嬩腑錛屾榪愮畻絎﹀皢鍚嶄負 Fahrenheit 鐨勭被杞崲涓哄悕涓?nbsp;Celsius 鐨勭被錛?br />// Must be defined inside a class called Fahrenheit:
public static explicit operator Celsius(Fahrenheit fahr)
{
    
return new Celsius((5.0f / 9.0f* (fahr.degrees - 32));
}
鍙互濡備笅鎵紺鴻皟鐢ㄦ杞崲榪愮畻絎︼細
Fahrenheit fahr 
= new Fahrenheit(100.0f);
Console.Write(
"{0} Fahrenheit", fahr.Degrees);
Celsius c 
= (Celsius)fahr;
杞崲榪愮畻絎﹀皢婧愮被鍨嬭漿鎹負鐩爣綾誨瀷銆?nbsp;婧愮被鍨嬫彁渚涜漿鎹㈣繍綆楃銆?nbsp;涓庨殣寮忚漿鎹笉鍚岋紝蹇呴』閫氳繃寮哄埗杞崲鐨勬柟寮忔潵璋冪敤鏄懼紡杞崲榪愮畻絎︺?nbsp;濡傛灉杞崲鎿嶄綔鍙兘瀵艱嚧寮傚父鎴栦涪澶變俊鎭紝鍒欏簲灝嗗叾鏍囪涓?nbsp;
explicit銆?nbsp;榪欏彲浠ラ槻姝㈢紪璇戝櫒鏃犳彁紺哄湴璋冪敤鍙兘浜х敓鏃犳硶棰勮鍚庢灉鐨勮漿鎹㈡搷浣溿?br />鐪佺暐姝ゅ己鍒惰漿鎹㈠皢瀵艱嚧緙栬瘧鏃墮敊璇?nbsp;CS0266銆?br />
implicit錛圕# 鍙傝冿級
implicit 鍏抽敭瀛楃敤浜庡0鏄庨殣寮忕殑鐢ㄦ埛瀹氫箟綾誨瀷杞崲榪愮畻絎︺?nbsp;濡傛灉鍙互紜繚杞崲榪囩▼涓嶄細閫犳垚鏁版嵁涓㈠け錛屽垯鍙嬌鐢ㄨ鍏抽敭瀛楀湪鐢ㄦ埛瀹氫箟綾誨瀷鍜屽叾浠栫被鍨嬩箣闂磋繘琛岄殣寮忚漿鎹€?br />闅愬紡杞崲鍙互閫氳繃娑堥櫎涓嶅繀瑕佺殑綾誨瀷杞崲鏉ユ彁楂樻簮浠g爜鐨勫彲璇繪с?nbsp;浣嗘槸錛屽洜涓洪殣寮忚漿鎹笉闇瑕佺▼搴忓憳灝嗕竴縐嶇被鍨嬫樉寮忓己鍒惰漿鎹負鍙︿竴縐嶇被鍨嬶紝鎵浠ヤ嬌鐢ㄩ殣寮忚漿鎹㈡椂蹇呴』鏍煎灝忓績錛屼互鍏嶅嚭鐜版剰澶栫粨鏋溿?nbsp;涓鑸儏鍐典笅錛岄殣寮忚漿鎹㈣繍綆楃搴斿綋浠庝笉寮曞彂寮傚父騫朵笖浠庝笉涓㈠け淇℃伅錛屼互渚垮彲浠ュ湪紼嬪簭鍛樹笉鐭ユ檽鐨勬儏鍐典笅瀹夊叏浣跨敤瀹冧滑銆?nbsp;濡傛灉杞崲榪愮畻絎︿笉鑳芥弧瓚抽偅浜涙潯浠訛紝鍒欏簲灝嗗叾鏍囪涓?nbsp;explicit銆?nbsp;
class Digit
{
    
public Digit(double d) { val = d; }
    
public double val;
    
// other members

    
// User-defined conversion from Digit to double
    public static implicit operator double(Digit d)
    {
        
return d.val;
    }
    
//  User-defined conversion from double to Digit
    public static implicit operator Digit(double d)
    {
        
return new Digit(d);
    }
}

class Program
{
    
static void Main(string[] args)
    {
        Digit dig 
= new Digit(7);
        
//This call invokes the implicit "double" operator
        double num = dig;
        
//This call invokes the implicit "Digit" operator
        Digit dig2 = 12;
        Console.WriteLine(
"num = {0} dig2 = {1}", num, dig2.val);
        Console.ReadLine();
    }
}


澶╀笅 2016-06-17 14:06 鍙戣〃璇勮
]]>鍔ㄦ佽皟鐢╓ebService(C#)http://www.shnenglu.com/aaxron/archive/2016/06/17/213743.html澶╀笅澶╀笅Fri, 17 Jun 2016 02:53:00 GMThttp://www.shnenglu.com/aaxron/archive/2016/06/17/213743.htmlhttp://www.shnenglu.com/aaxron/comments/213743.htmlhttp://www.shnenglu.com/aaxron/archive/2016/06/17/213743.html#Feedback0http://www.shnenglu.com/aaxron/comments/commentRss/213743.htmlhttp://www.shnenglu.com/aaxron/services/trackbacks/213743.html鍔ㄦ佽皟鐢╓ebService(C#)杞嚜:http://www.cnblogs.com/xuwb/archive/2012/09/25/2701629.html閫氬父鎴戜滑鍦ㄧ▼搴忎腑闇瑕佽皟鐢╓ebService...  闃呰鍏ㄦ枃

澶╀笅 2016-06-17 10:53 鍙戣〃璇勮
]]>
WebService鎿嶄綔http://www.shnenglu.com/aaxron/archive/2016/06/17/213742.html澶╀笅澶╀笅Fri, 17 Jun 2016 02:33:00 GMThttp://www.shnenglu.com/aaxron/archive/2016/06/17/213742.htmlhttp://www.shnenglu.com/aaxron/comments/213742.htmlhttp://www.shnenglu.com/aaxron/archive/2016/06/17/213742.html#Feedback0http://www.shnenglu.com/aaxron/comments/commentRss/213742.htmlhttp://www.shnenglu.com/aaxron/services/trackbacks/213742.htmlWebService鎿嶄綔
杞嚜:
http://blog.csdn.net/hi_kong/article/details/46356801

http://www.cnblogs.com/wayne-ivan/archive/2014/07/14/3842341.html


涓銆佹湇鍔″櫒绔細
鍦╒S2010涓柊寤洪」鐩紝棣栧厛閫夋嫨.net framework2.
0錛岀劧鍚庡啀閫夋嫨web鏈嶅姟搴旂敤紼嬪簭銆傚鍥炬墍紺猴細
鐒跺悗鍦⊿ervice.cs鏂囦歡涓坊鍔犺嚜宸辯殑鏂規(guī)硶鍗沖彲銆?br />浜屻丆#winform璋冪敤webservice鏈嶅姟

鏂板緩C#winfrom宸ョ▼錛屽彸閿紩鐢?/span>-銆嬫坊鍔犳湇鍔″紩鐢?/span>-銆嬮珮綰?/span>-銆嬫坊鍔爓eb寮曠敤錛屽湪URL鍚庢坊鍔犻渶瑕佽繛鎺ョ殑url錛堣繍琛屼笂闈eb鏈嶅姟紼嬪簭嫻忚鍣ㄤ腑灝變細鍑虹幇榪炴帴鐨剈rl錛夛紝鐒跺悗鐐瑰嚮鍚庨潰鐨勭澶達紝鍐嶇偣娣誨姞寮曠敤鍗沖彲銆?br />鍋囪寮曠敤鐨勬湇鍔″悕涓篧ebReference錛岀被鍚嶇О涓篠ervice錛?br />using System.Web.Services;
using System.Web.Services.Description;
鍦ㄤ唬鐮佷腑濡備笅鎿嶄綔錛?br />
WebReference.Service1 helloWord 
= new WebReference.Service1();
helloWord .Url 
=WebUrl;//璁劇疆url
helloWord.helloWord錛堬級;//璋冪敤webservice涓殑鏂規(guī)硶
緇撴潫銆?br />

WebService澶勭悊澶ф暟鎹噺鏁版嵁
鍦ㄩ氳繃WebService澶勭悊澶ф暟鎹噺鏁版嵁鏃跺嚭鐜板涓嬮敊璇細
soap fault: 榪愯閰嶇疆鏂囦歡涓寚瀹氱殑鎵╁睍鏃跺嚭鐜板紓甯搞?nbsp;
---> 瓚呰繃浜嗘渶澶ц姹傞暱搴︺?nbsp;
瑙e喅鏂規(guī)硶錛?br />鍥犱負涓婁紶鐨勬枃浠跺ぇ浜庣郴緇熼粯璁ら厤緗殑鍊鹼紝asp.net web service榛樿鐨勮姹傞暱搴︽槸4M銆?br />
1銆侀拡瀵瑰崟涓」鐩紝鍙渶淇敼Web.config灝卞彲浠ヤ簡錛?br />淇敼閰嶇疆鍙互鍦╳eb.config涓噸鏂拌緗紝濡備笅錛?
<configuration>
<system.web>
<httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
</system.web>
</configuration>



澶╀笅 2016-06-17 10:33 鍙戣〃璇勮
]]>
綺劇畝鐗堟湰WCF DEMOhttp://www.shnenglu.com/aaxron/archive/2016/06/16/213727.html澶╀笅澶╀笅Thu, 16 Jun 2016 01:46:00 GMThttp://www.shnenglu.com/aaxron/archive/2016/06/16/213727.htmlhttp://www.shnenglu.com/aaxron/comments/213727.htmlhttp://www.shnenglu.com/aaxron/archive/2016/06/16/213727.html#Feedback0http://www.shnenglu.com/aaxron/comments/commentRss/213727.htmlhttp://www.shnenglu.com/aaxron/services/trackbacks/213727.htmlusing System;
using System.ServiceModel; //娣誨姞System.ServiceModel寮曠敤
using System.ServiceModel.Channels;

namespace ConsoleApplication1
{
    [ServiceContract]
    
public interface IHelloWCF
    {
        [OperationContract]
        
void Say(string input);
    }
    
public sealed class HelloService : IHelloWCF
    {
        
public void Say(string input)
        {
            Console.WriteLine(
"Hello {0}", input);
        }
    }
    
class Program
    {
        
static void Main(string[] args)
        {
            Uri address 
= new Uri("http://127.0.0.1:8733/IHelloWCF");
            BasicHttpBinding binding 
= new BasicHttpBinding();
            ServiceHost svc 
= new ServiceHost(typeof(HelloService));
            svc.AddServiceEndpoint(
typeof(IHelloWCF), binding, address);
            svc.Opened 
+= delegate {
                Console.WriteLine(
"The HelloWCF receiving application is ready");
            };
            svc.Open();

            ChannelFactory
<IHelloWCF> factory = new ChannelFactory<IHelloWCF>(binding,new EndpointAddress(address));
            IHelloWCF proxy 
= factory.CreateChannel();
            proxy.Say(
"寮犱笁");
            proxy.Say(
"鏉庡洓");
            proxy.Say(
"鐜嬩簩楹誨瓙");


            Console.ReadLine();
            svc.Close();
        }
    }
}


澶╀笅 2016-06-16 09:46 鍙戣〃璇勮
]]>WCF鍏冩暟鎹叕甯冪殑2縐嶆柟寮忥細httpGetEnabled涓巑exhttp://www.shnenglu.com/aaxron/archive/2016/06/15/213718.html澶╀笅澶╀笅Wed, 15 Jun 2016 07:42:00 GMThttp://www.shnenglu.com/aaxron/archive/2016/06/15/213718.htmlhttp://www.shnenglu.com/aaxron/comments/213718.htmlhttp://www.shnenglu.com/aaxron/archive/2016/06/15/213718.html#Feedback0http://www.shnenglu.com/aaxron/comments/commentRss/213718.htmlhttp://www.shnenglu.com/aaxron/services/trackbacks/213718.htmlWCF鍏冩暟鎹叕甯冪殑2縐嶆柟寮忥細httpGetEnabled涓巑ex
涓銆佸厓鏁版嵁鍗砏SDL錛屾弿榪頒簡鏈嶅姟鐨勭粏鑺傦紝浠ヤ究瀹㈡埛绔嬌鐢ㄣ?br />浜屻佸繀欏諱負鏈嶅姟閰嶇疆ServiceMetadata琛屼負錛屾墠鑳戒負鍏剁敓鎴怶SDL錛屾墠鑳藉啀浣跨敤httpGetEnabled鎴杕ex灝嗗叾鍏竷鍑哄幓
涓夈佽繖涓ょ鏂瑰紡鍏竷鍑哄幓鐨刉SDL鏃犲尯鍒備絾鍏竷鐨勬柟寮忔湁鍖哄埆
1銆乭ttpGetEnabled=true錛岀被浼肩殑榪樻湁httpsGetEnabled=true
姝ゆ柟寮忛氳繃鍦ㄦ湇鍔″湪鐨刄RL鍚庡姞“
?wsdl”鐨勬柟寮忓叕甯僕SDL錛屽彲鐩存帴閫氳繃HTTP璁塊棶寰楀埌銆?br />
2銆乵ex
姝ゆ柟寮忎互涓鑸殑緇堢粨鐐規(guī)柟寮忓叕甯冿紝鏀寔鍚勭鍗忚錛歨ttp銆乼cp銆丯amedPipe


澶╀笅 2016-06-15 15:42 鍙戣〃璇勮
]]>WCF 鏁版嵁濂戠害錛圖ataContract錛?/title><link>http://www.shnenglu.com/aaxron/archive/2016/06/13/213700.html</link><dc:creator>澶╀笅</dc:creator><author>澶╀笅</author><pubDate>Mon, 13 Jun 2016 09:52:00 GMT</pubDate><guid>http://www.shnenglu.com/aaxron/archive/2016/06/13/213700.html</guid><wfw:comment>http://www.shnenglu.com/aaxron/comments/213700.html</wfw:comment><comments>http://www.shnenglu.com/aaxron/archive/2016/06/13/213700.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/aaxron/comments/commentRss/213700.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/aaxron/services/trackbacks/213700.html</trackback:ping><description><![CDATA[<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">鏁版嵁濂戠害錛圖ataContract錛?br />鏈嶅姟濂戠害瀹氫箟浜嗚繙紼嬭闂璞″拰鍙緵璋冪敤鐨勬柟娉曪紝鏁版嵁濂戠害鍒欐槸鏈嶅姟绔拰瀹㈡埛绔箣闂磋浼犻佺殑鑷畾涔夋暟鎹被鍨嬨?br />涓鏃﹀0鏄庝竴涓被鍨嬩負DataContract錛岄偅涔堣綾誨瀷灝卞彲浠ヨ搴忓垪鍖栧湪鏈嶅姟绔拰瀹㈡埛绔箣闂翠紶閫侊紝濡備笅鎵紺恒?br />     [DataContract]<br />     </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> UserInfo<br />     {<br />          </span><span style="color: #008000">//</span><span style="color: #008000">….</span><span style="color: #008000"><br /></span><span style="color: #000000">     }<br />鍙湁澹版槑涓篋ataContract鐨勭被鍨嬬殑瀵硅薄鍙互琚紶閫侊紝涓斿彧鏈夋垚鍛樺睘鎬т細琚紶閫掞紝鎴愬憳鏂規(guī)硶涓嶄細琚紶閫掋俉CF瀵瑰0鏄庝負DataContract鐨勭被鍨嬫彁渚涙洿鍔犵粏鑺傜殑鎺у埗錛屽彲浠ユ妸涓涓垚鍛樻帓闄ゅ湪搴忓垪鍖栬寖鍥翠互澶栵紝涔熷氨鏄錛屽鎴風紼嬪簭涓嶄細鑾峰緱琚帓闄ゅ湪澶栫殑鎴愬憳鐨勪換浣曚俊鎭紝鍖呮嫭瀹氫箟鍜屾暟鎹傞粯璁ゆ儏鍐典笅錛屾墍鏈夌殑鎴愬憳灞炴ч兘琚帓闄ゅ湪澶栵紝鍥犳闇瑕佹妸姣忎竴涓浼犻佺殑鎴愬憳澹版槑涓篋ataMember錛屽涓嬫墍紺恒?br />    [DataContract]<br />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> UserInfo<br />    {<br />        [DataMember]<br />        </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">string</span><span style="color: #000000"> UserName<br />        {<br />            </span><span style="color: #0000ff">get</span><span style="color: #000000">;<br />            </span><span style="color: #0000ff">set</span><span style="color: #000000">;<br />        }<br />        [DataMember]<br />        </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">int</span><span style="color: #000000"> Age<br />        {<br />            </span><span style="color: #0000ff">get</span><span style="color: #000000">;<br />            </span><span style="color: #0000ff">set</span><span style="color: #000000">;<br />        }<br />        [DataMember]<br />        </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">string</span><span style="color: #000000"> Location<br />        {<br />            </span><span style="color: #0000ff">get</span><span style="color: #000000">;<br />            </span><span style="color: #0000ff">set</span><span style="color: #000000">;<br />        }<br />        </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">string</span><span style="color: #000000"> Zodiac<br />        {<br />            </span><span style="color: #0000ff">get</span><span style="color: #000000">;<br />            </span><span style="color: #0000ff">set</span><span style="color: #000000">;<br />        }<br />}<br />涓婇潰榪欐浠g爜鎶奤serInfo綾誨0鏄庝負DataContract錛屽皢UserName銆丄ge銆丩ocation榪?涓睘鎬у0鏄庝負DataMember錛堟暟鎹垚鍛橈級銆俍odiac鎴愬憳娌℃湁琚0鏄庝負DataMember錛屽洜姝ゅ湪浜ゆ崲鏁版嵁鏃訛紝涓嶄細浼犺緭Zodiac鐨勪換浣曚俊鎭?br />DataContract涔熸敮鎸丯ame</span><span style="color: #000000">/</span><span style="color: #000000">Namespace灞炴э紝濡傚悓ServiceContract錛孨ame鍜孨amespace鍙互鑷畾涔夊悕縐板拰鍛藉悕絀洪棿錛屽鎴風灝嗕嬌鐢ㄨ嚜瀹氫箟鐨勫悕縐板拰鍛藉悕絀洪棿瀵笵ataContract綾誨瀷榪涜璁塊棶銆?br />澹版槑涓篋ataMember鐨勬垚鍛樹篃鍙互鑷畾涔夊鎴風鍙鐨勫悕縐幫紝渚嬪錛?br />[DataMember(Name</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">Name</span><span style="color: #000000">"</span><span style="color: #000000">)]<br /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">string</span><span style="color: #000000"> UserName<br />{<br />     </span><span style="color: #0000ff">get</span><span style="color: #000000">;<br />     </span><span style="color: #0000ff">set</span><span style="color: #000000">;<br />}<br />[DataMember(Name</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">Age</span><span style="color: #000000">"</span><span style="color: #000000">)]<br /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">int</span><span style="color: #000000"> UserAge<br />{<br />          </span><span style="color: #0000ff">get</span><span style="color: #000000">;<br />          </span><span style="color: #0000ff">set</span><span style="color: #000000">;<br />}<br />闄や簡Name鍜孨amespace浠ュ錛孌ataMember榪樻湁浠ヤ笅鍙傛暟錛屽畠浠殑鍚箟鍒嗗埆濡備笅銆?br />錛?/span><span style="color: #000000">1</span><span style="color: #000000">錛塈sRequired錛氬間負true鏃訛紝瑕佹眰搴忓垪鍖栧紩鎿庢鏌ュ璞℃槸鍚﹀瓨鍦ㄨ鍊鹼紱鑻ユ棤錛屽垯浼氭湁寮傚父鎶涘嚭銆?br />錛?/span><span style="color: #000000">2</span><span style="color: #000000">錛塐rder錛歜ool綾誨瀷鍊鹼紝鍊間負true鏃訛紝搴忓垪鍖栧拰鍙嶅簭鍒楀寲榪囩▼灝嗕細鎸夋垚鍛樺畾涔夌殑欏哄簭榪涜錛岃繖瀵逛緷璧栦簬鎴愬憳浣嶇疆鐨勫弽搴忓垪鍖栬繃紼嬫棤姣旈噸瑕併?br />錛?/span><span style="color: #000000">3</span><span style="color: #000000">錛塃mitDefaultvalue錛氫負鎴愬憳灞炴ц緗竴涓粯璁ゅ箋?/span></div><img src ="http://www.shnenglu.com/aaxron/aggbug/213700.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/aaxron/" target="_blank">澶╀笅</a> 2016-06-13 17:52 <a href="http://www.shnenglu.com/aaxron/archive/2016/06/13/213700.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>char*鍜寃char_t* 杞琒tring^http://www.shnenglu.com/aaxron/archive/2015/12/21/212530.html澶╀笅澶╀笅Mon, 21 Dec 2015 11:07:00 GMThttp://www.shnenglu.com/aaxron/archive/2015/12/21/212530.htmlhttp://www.shnenglu.com/aaxron/comments/212530.htmlhttp://www.shnenglu.com/aaxron/archive/2015/12/21/212530.html#Feedback0http://www.shnenglu.com/aaxron/comments/commentRss/212530.htmlhttp://www.shnenglu.com/aaxron/services/trackbacks/212530.html#include "stdafx.h"
#include <msclr/marshal.h>
#using <mscorlib.dll>
using namespace System;
using namespace System::Text;
using namespace System::Runtime::InteropServices;

#ifdef _MANAGED
#endif

void abc123()
{
    using namespace msclr::interop;
    const char* msg1 = "Test String to Marshal";
    const wchar_t* msg2= L"Good Luck Aaron";
    String^ aMsg = marshal_as<String^>(msg1);
    String^ uMsg = marshal_as<String^>(msg2);
    Console::WriteLine(aMsg);
    Console::WriteLine(uMsg);
}
#pragma unmanaged
int _tmain(int argc, _TCHAR* argv[])
{
    abc123();
    system("pause");
    return 0;
}
#pragma managed 


澶╀笅 2015-12-21 19:07 鍙戣〃璇勮
]]>鐣ヨ皥GCHandle銆愯漿銆?/title><link>http://www.shnenglu.com/aaxron/archive/2015/12/21/212529.html</link><dc:creator>澶╀笅</dc:creator><author>澶╀笅</author><pubDate>Mon, 21 Dec 2015 10:36:00 GMT</pubDate><guid>http://www.shnenglu.com/aaxron/archive/2015/12/21/212529.html</guid><wfw:comment>http://www.shnenglu.com/aaxron/comments/212529.html</wfw:comment><comments>http://www.shnenglu.com/aaxron/archive/2015/12/21/212529.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/aaxron/comments/commentRss/212529.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/aaxron/services/trackbacks/212529.html</trackback:ping><description><![CDATA[<br /><br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->鐣ヨ皥GCHandle銆愯漿銆?br />http:<span style="color: #008000; ">//</span><span style="color: #008000; ">blog.163.com/vk_01313/blog/static/17219228200912491729457/</span><span style="color: #008000; "><br /></span>鎴戜滑鍦ㄤ嬌鐢╟#鎵樼浠g爜鏃訛紝鍐呭瓨鍦板潃鍜孏C鍥炴敹閭d笉鏄垜浠叧蹇冪殑錛孋LR宸茬粡緇欐垜浠殫綆辨搷浣溿?br />浣嗘槸濡傛灉鎴戜滑鍦╟#涓皟鐢ㄤ簡涓涓潪鎵樼浠g爜錛屾瘮濡倂c鐨凞LL,鑰屼笖浠栨湁涓洖璋冨嚱鏁幫紝闇瑕佸紩鐢╟#涓殑鏌愪釜瀵硅薄騫舵搷浣滐紝<br />榪欐椂鍊欎綘灝卞緱瑕佸皬蹇冧簡銆?br />瑕佹槸闈炴墭綆′唬鐮佷腑鐢ㄥ埌寰楁墭綆′唬鐮侀偅涓璞¤GC緇欏洖鏀朵簡錛岃繖鏃跺欏氨浼氭姤鍐呭瓨閿欒銆?br />鎵浠ユ垜浠氨瑕佹妸閭d釜瀵硅薄“閽?#8221;浣?pin)錛岃瀹冪殑鍐呭瓨鍦板潃鍥哄畾錛岃屼笉琚瀮鍦懼洖鏀舵帀錛岀劧鍚庢渶鍚庢垜浠嚜宸辯鐞嗭紝鑷繁閲婃斁鍐呭瓨,榪欐椂鍊欏氨闇瑕丟CHandle,鏉ョ湅涓猰sdn涓婄殑渚嬪瓙:<br /><br /><br /><span style="color: #0000FF; ">using</span> System.Runtime.InteropServices;<br /><br /><span style="color: #0000FF; ">namespace</span> ConsoleApplication1<br />{<br /><br />    <span style="color: #008000; ">//</span><span style="color: #008000; ">C#</span><span style="color: #008000; "><br /></span>    <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">delegate</span> <span style="color: #0000FF; ">bool</span> CallBack(<span style="color: #0000FF; ">int</span> handle, IntPtr param);<br />    <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">class</span> LibWrap<br />    {<br />        [DllImport("user32.dll")]<br />        <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">static</span> <span style="color: #0000FF; ">extern</span> <span style="color: #0000FF; ">bool</span> EnumWindows(CallBack cb, IntPtr param);<br />    }<br /><br />    <span style="color: #0000FF; ">class</span> Program<br />    {<br />        <span style="color: #0000FF; ">static</span> <span style="color: #0000FF; ">void</span> Main(<span style="color: #0000FF; ">string</span>[] args)<br />        {<br />            TextWriter tw = System.Console.Out;<br />            GCHandle gch = GCHandle.Alloc(tw);<br />            CallBack cewp = <span style="color: #0000FF; ">new</span> CallBack(CaptureEnumWindowsProc);<br />            LibWrap.EnumWindows(cewp, (IntPtr)gch);<br />            gch.Free();<br />            Console.Read();<br /><br />        }<br />        <span style="color: #0000FF; ">private</span> <span style="color: #0000FF; ">static</span> <span style="color: #0000FF; ">bool</span> CaptureEnumWindowsProc(<span style="color: #0000FF; ">int</span> handle, IntPtr param)<br />        {<br />            GCHandle gch = (GCHandle)param;<br />            TextWriter tw = (TextWriter)gch.Target;<br />            tw.WriteLine(handle);<br />            <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">true</span>;<br />        }<br /><br />    } <br />}<br /><br /><br />瀵逛笂闈㈢殑浠g爜錛岀暐鍔犺В閲婏細gch 浼氶拤浣?pin)tw榪欎釜瀵硅薄錛屼嬌鍏朵笉鍙桮C綆$悊錛屽憡璇夊畠錛屼互鍚庝綘宕╃鎴戯紝鎴戜篃涓嶇敤緇欎綘涓婄◣,鍏跺疄綆$悊鏉冨凡緇忕粰gch錛岄氳繃free鏉ラ噴鏀懼唴瀛樸?br />榪欑鎯呭喌涓昏鐢ㄥ湪鎵樼鍜岄潪鎵樼浠g爜浜や簰鐨勬椂鍊欙紝闃叉鍐呭瓨娉勯湶鏉ヤ嬌鐢℅CHandle銆?/div><img src ="http://www.shnenglu.com/aaxron/aggbug/212529.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/aaxron/" target="_blank">澶╀笅</a> 2015-12-21 18:36 <a href="http://www.shnenglu.com/aaxron/archive/2015/12/21/212529.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>pin_ptr 鍜?interior_ptrhttp://www.shnenglu.com/aaxron/archive/2015/12/21/212528.html澶╀笅澶╀笅Mon, 21 Dec 2015 09:11:00 GMThttp://www.shnenglu.com/aaxron/archive/2015/12/21/212528.htmlhttp://www.shnenglu.com/aaxron/comments/212528.htmlhttp://www.shnenglu.com/aaxron/archive/2015/12/21/212528.html#Feedback0http://www.shnenglu.com/aaxron/comments/commentRss/212528.htmlhttp://www.shnenglu.com/aaxron/services/trackbacks/212528.htmlCLR璇硶涓紝鍊肩被鍨嬫寚閽堝垎涓轟袱縐嶇被鍨嬶細V*錛堥檺浜庨潪 CLR 鍫嗕綅緗級鍜屽唴閮ㄦ寚閽?nbsp;interior_ptr<V>錛堝厑璁鎬絾涓嶈姹傛墭綆″爢鍐呯殑鍦板潃錛夈?br />

閽変綇鎸囬拡
閫氬父錛屽湪鍘嬬緝闃舵錛屽瀮鍦懼洖鏀跺櫒鍙夋嫨灝嗛┗鐣欏湪 CLR 鍫嗕笂鐨勫璞$Щ鍔ㄥ埌鍫嗗唴鐨勪笉鍚屼綅緗傝繖縐嶇Щ鍔ㄥ浜庤窡韙彞鏌勩佽窡韙紩鐢ㄥ拰鍐呴儴鎸囬拡鑰岃█涓嶆槸闂錛屽畠浠兘閫忔槑鍦版洿鏂拌繖浜涘疄浣撱備絾鏄紝濡傛灉鐢ㄦ埛鍦ㄨ繍琛屾椂鐜澶栦紶閫掍簡 CLR 鍫嗕笂瀵硅薄鐨勫湴鍧錛岃繖縐嶇Щ鍔ㄥ氨浼氬鑷撮棶棰樸傚湪榪欑鎯呭喌涓嬶紝瀵硅薄鐨勪笉紼沖畾榪愬姩鍙兘瀵艱嚧榪愯鏃跺け璐ャ傝閬垮厤姝ょ被瀵硅薄鐨勭Щ鍔紝蹇呴』鍦ㄦ湰鍦板皢瀹冧滑閽夊湪鑷繁鐨勪綅緗笂浠ヤ緵澶栭儴浣跨敤銆?br />
鍦ㄦ墭綆℃墿灞曚腑錛?#8220;閽変綇鎸囬拡”鏄氳繃浣跨敤 __pin 鍏抽敭瀛楅檺瀹氭寚閽堝0鏄庢潵澹版槑鐨勩備笅闈㈡槸涓涓潵鑷墭綆℃墿灞曡鑼冪殑緇忚繃鐣ュ井淇敼鐨勭ず渚嬶細

  澶嶅埗浠g爜 
__gc struct H { int j; };

int main() 
{
   H * h = new H;
   int __pin * k = & h -> j;
  
   // …
};
 

鍦ㄦ柊鐨勮璦璁捐涓紝閽変綇鎸囬拡鏄嬌鐢ㄧ被浼間簬鍐呴儴鎸囬拡鐨勮娉曟潵澹版槑鐨勩?br />
  澶嶅埗浠g爜 
ref struct H
{
public:
   int j;
};

int main()
{
   H^ h = gcnew H;
   pin_ptr<int> k = &h->j;

   // …
}



interior_ptr
Declares a pointer to inside a reference type, but not to the object itself. An interior pointer can point to a reference handle, value type, boxed type handle, member of a managed type, or to an element of a managed array. 
cli::interior_ptr<cv_qualifier type> var = &initializer;

Remarks
A native pointer is not able to track an item as its location changes on the managed heap, which results from the garbage collector moving instances of an object. In order for a pointer to correctly refer to the instance, the runtime needs to update the pointer to the newly positioned object.

An interior_ptr represents a superset of the functionality of a native pointer. Therefore, anything that can be assigned to a native pointer can also be assigned to an interior_ptr. An interior pointer is permitted to perform the same set of operations as native pointers, including comparison and pointer arithmetic.

An interior pointer can only be declared on the stack. An interior pointer cannot be declared as a member of a class.

Since interior pointers exist only on the stack, taking the address of an interior pointer yields an unmanaged pointer.

interior_ptr has an implicit conversion to bool, which allows for its use in conditional statements.

For information on how to declare an interior pointer that points into an object that cannot be moved on the garbage-collected heap, see pin_ptr.

interior_ptr is in the cli namespace. See cli Namespace for more information.


//Example
// interior_ptr.cpp
// compile with: /clr
using namespace System;

ref class MyClass {
public:
   int data;
};

int main() {
   MyClass ^ h_MyClass = gcnew MyClass;
   h_MyClass->data = 1;
   Console::WriteLine(h_MyClass->data);

   interior_ptr<int> p = &(h_MyClass->data);
   *p = 2;
   Console::WriteLine(h_MyClass->data);

   // alternatively
   interior_ptr<MyClass ^> p2 = &h_MyClass;
   (*p2)->data = 3;
   Console::WriteLine((*p2)->data);
}

 


 


澶╀笅 2015-12-21 17:11 鍙戣〃璇勮
]]>StructLayout鐗規(guī)?/title><link>http://www.shnenglu.com/aaxron/archive/2015/12/21/212527.html</link><dc:creator>澶╀笅</dc:creator><author>澶╀笅</author><pubDate>Mon, 21 Dec 2015 08:27:00 GMT</pubDate><guid>http://www.shnenglu.com/aaxron/archive/2015/12/21/212527.html</guid><wfw:comment>http://www.shnenglu.com/aaxron/comments/212527.html</wfw:comment><comments>http://www.shnenglu.com/aaxron/archive/2015/12/21/212527.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/aaxron/comments/commentRss/212527.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/aaxron/services/trackbacks/212527.html</trackback:ping><description><![CDATA[<div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->StructLayout鐗規(guī)?br /><br />     鍏叡璇█榪愯搴撳埄鐢⊿tructLayoutAttribute鎺у埗綾繪垨緇撴瀯鐨勬暟鎹瓧孌靛湪鎵樼鍐呭瓨涓殑鐗╃悊甯冨眬,鍗崇被鎴栫粨鏋勯渶瑕佹寜鏌愮鏂瑰紡鎺掑垪銆傚鏋滆灝嗙被浼犻掔粰闇瑕佹寚瀹氬竷灞鐨勯潪鎵樼浠g爜錛屽垯鏄懼紡鎺у埗綾誨竷灞鏄噸瑕佺殑銆傚畠鐨勬瀯閫犲嚱鏁頒腑鐢?nbsp;LayoutKind鍊煎垵濮嬪寲 StructLayoutAttribute 綾葷殑鏂板疄渚嬨?nbsp;LayoutKind.Sequential 鐢ㄤ簬寮哄埗灝嗘垚鍛樻寜鍏跺嚭鐜扮殑欏哄簭榪涜欏哄簭甯冨眬銆?br /> <br />  StructLayout鐗規(guī)у厑璁告垜浠帶鍒禨tructure璇彞鍧楃殑鍏冪礌鍦ㄥ唴瀛樹腑鐨勬帓鍒楁柟寮?浠ュ強褰撹繖浜涘厓绱犺浼犻掔粰澶栭儴DLL鏃訛紝榪愯搴撴帓鍒楄繖浜涘厓绱犵殑鏂瑰紡銆俈isual   Basic緇撴瀯鐨勬垚鍛樺湪鍐呭瓨涓殑欏哄簭鏄寜鐓у畠浠嚭鐜板湪婧愪唬鐮佷腑鐨勯『搴忔帓鍒楃殑錛屽敖綆$紪璇戝櫒鍙互鑷敱鐨勬彃鍏ュ~鍏呭瓧鑺傛潵瀹夋帓榪欎簺鎴愬憳錛屼互渚夸嬌寰?6浣嶆暟鍊肩敤瀛愯竟鐣屽榻愶紝32浣嶆暟鍊肩敤鍙屽瓧杈圭晫瀵歸綈銆?nbsp;    <br />    <br />  浣跨敤榪欑鎺掑垪錛堟湭鍘嬬緝甯冨眬錛夋彁渚涚殑鎬ц兘鏈浣熾?nbsp;    <br />        <br />閫氳繃System.Runtime.InteropServices.StructLayout   鐗規(guī)х簿紜殑鎺у埗姣忎竴涓粨鏋勬垚鍛樼殑浣嶇疆銆?br />System.Runtime.InteropServices.StructLayout   鍏佽鐨勫兼湁:<br /><strong><span style="color: red;">StructLayout.Auto   </span><br /><span style="color: red;">StructLayout.Sequential   </span><br /><span style="color: red;">StructLayout.Explicit  </span></strong>  <br /><br />1.Sequential,欏哄簭甯冨眬,姣斿<br /><span style="color: #0000FF; ">struct</span> S1<br />{<br />  <span style="color: #0000FF; ">int</span> a;<br />  <span style="color: #0000FF; ">int</span> b;<br />}<br />閭d箞榛樿鎯呭喌涓嬪湪鍐呭瓨閲屾槸鍏堟帓a,鍐嶆帓b<br />涔熷氨鏄鏋滆兘鍙栧埌a鐨勫湴鍧,鍜宐鐨勫湴鍧,鍒欑浉宸竴涓猧nt綾誨瀷鐨勯暱搴?4瀛楄妭<br />[StructLayout(LayoutKind.Sequential)] <br /><span style="color: #0000FF; ">struct</span> S1<br />{<br />  <span style="color: #0000FF; ">int</span> a;<br />  <span style="color: #0000FF; ">int</span> b;<br />}<br />榪欐牱鍜屼笂涓涓槸涓鏍風殑.鍥犱負榛樿鐨勫唴瀛樻帓鍒楀氨鏄疭equential,涔熷氨鏄寜鎴愬憳鐨勫厛鍚庨『搴忔帓鍒?<br />2.Explicit,綺劇‘甯冨眬<br />闇瑕佺敤FieldOffset()璁劇疆姣忎釜鎴愬憳鐨勪綅緗?br />榪欐牱灝卞彲浠ュ疄鐜扮被浼糲鐨勫叕鐢ㄤ綋(union)鐨勫姛鑳?br />[StructLayout(LayoutKind.Explicit)] <br /><span style="color: #0000FF; ">struct</span> S1<br />{<br />    [FieldOffset(0)] <span style="color: #0000FF; ">int</span> a;<br />    [FieldOffset(0)] <span style="color: #0000FF; ">int</span> b;<br />}<br />榪欐牱a鍜宐鍦ㄥ唴瀛樹腑鍦板潃鐩稿悓 <br />    <br />  StructLayout鐗規(guī)ф敮鎸佷笁縐嶉檮鍔犲瓧孌碉細CharSet銆丳ack銆丼ize銆?nbsp;    <br />·   CharSet瀹氫箟鍦ㄧ粨鏋勪腑鐨勫瓧絎︿覆鎴愬憳鍦ㄧ粨鏋勮浼犵粰DLL鏃剁殑鎺掑垪鏂瑰紡銆傚彲浠ユ槸Unicode銆丄nsi鎴朅uto銆?nbsp;    <br />  榛樿涓篈uto錛屽湪WIN   NT/2000/XP涓〃紺哄瓧絎︿覆鎸夌収Unicode瀛楃涓茶繘琛屾帓鍒楋紝鍦╓IN   95/98/Me涓垯琛ㄧず鎸夌収ANSI瀛楃涓茶繘琛屾帓鍒椼?nbsp;    <br />·   Pack瀹氫箟浜嗙粨鏋勭殑灝佽澶у皬銆傚彲浠ユ槸1銆?銆?銆?銆?6銆?2銆?4銆?28鎴栫壒孌婂?銆傜壒孌婂?琛ㄧず褰撳墠鎿嶄綔騫沖彴榛樿鐨勫帇緙╁ぇ灝忋?nbsp;    <br /> <br /><br />  [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]<br />    <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">struct</span> LIST_OPEN<br />    {<br />        <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">int</span> dwServerId;<br />        <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">int</span> dwListId;<br />        <span style="color: #0000FF; ">public</span> System.UInt16 wRecordSize;<br />        <span style="color: #0000FF; ">public</span> System.UInt16 wDummy;<br />        <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">int</span> dwFileSize;<br />        <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">int</span> dwTotalRecs;<br />        <span style="color: #0000FF; ">public</span> NS_PREFETCHLIST sPrefetch;<br />        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 24)] <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">string</span> szSrcMach;<br />        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 24)] <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">string</span> szSrcComp;<br />    }<br /><br />姝や緥涓敤鍒癕ashalAs鐗規(guī)э紝瀹冪敤浜庢弿榪板瓧孌點佹柟娉曟垨鍙傛暟鐨勫皝閫佸鐞嗘牸寮忋傜敤瀹冧綔涓哄弬鏁板墠緙騫舵寚瀹氱洰鏍囬渶瑕佺殑鏁版嵁綾誨瀷銆?br />渚嬪錛屼互涓嬩唬鐮佸皢涓や釜鍙傛暟浣滀負鏁版嵁綾誨瀷闀挎寚閽堝皝閫佺粰 Windows API 鍑芥暟鐨勫瓧絎︿覆 (LPStr)錛?nbsp;<br />[MarshalAs(UnmanagedType.LPStr)] String existingfile; <br /><br />[MarshalAs(UnmanagedType.LPStr)] String newfile; <br /><br />娉ㄦ剰緇撴瀯浣滀負鍙傛暟鏃跺欙紝涓鑸墠闈㈣鍔犱笂ref淇グ絎︼紝鍚﹀垯浼氬嚭鐜伴敊璇細瀵硅薄鐨勫紩鐢ㄦ病鏈夋寚瀹氬璞$殑瀹炰緥銆?br />[ DllImport( "kernel32", EntryPoint="GetVersionEx" )] <br /><span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">static</span> <span style="color: #0000FF; ">extern</span> <span style="color: #0000FF; ">bool</span> GetVersionEx2( <span style="color: #0000FF; ">ref</span> OSVersionInfo2 osvi );<br /><br /><br /><span style="color: #0000FF; ">string</span> result;<br />IntPtr strPtr = <span style="color: #0000FF; ">new</span> IntPtr() ;<span style="color: #008000; ">//</span><span style="color: #008000; "> unmanaged api TestStringAsResultIntPrt(1);</span><span style="color: #008000; "><br /></span>result = Marshal.PtrToStringUni(strPtr);<br />result = Marshal.PtrToStringAnsi(strPtr);<br />Marshal.FreeCoTaskMem(strPtr);</div><img src ="http://www.shnenglu.com/aaxron/aggbug/212527.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/aaxron/" target="_blank">澶╀笅</a> 2015-12-21 16:27 <a href="http://www.shnenglu.com/aaxron/archive/2015/12/21/212527.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>濡備綍錛氬皢 System::String 杞崲涓烘爣鍑嗗瓧絎︿覆http://www.shnenglu.com/aaxron/archive/2015/12/14/212478.html澶╀笅澶╀笅Mon, 14 Dec 2015 07:46:00 GMThttp://www.shnenglu.com/aaxron/archive/2015/12/14/212478.htmlhttp://www.shnenglu.com/aaxron/comments/212478.htmlhttp://www.shnenglu.com/aaxron/archive/2015/12/14/212478.html#Feedback0http://www.shnenglu.com/aaxron/comments/commentRss/212478.htmlhttp://www.shnenglu.com/aaxron/services/trackbacks/212478.html//銆婄簿閫?NET浜掓搷浣滐細P/Invoke銆丆++ Interop鍜孋OM Interop銆?br />//ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.chs/dv_vccore/html/79e2537e-d4eb-459f-9506-0e738045b59e.htm
// convert_system_string.cpp
// compile with: /clr
#include <string>
#include <iostream>
using namespace std;
using namespace System;

void MarshalString ( String ^ s, string& os ) {
   using namespace Runtime::InteropServices;
   const char* chars = 
      (const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();
   os = chars;
   Marshal::FreeHGlobal(IntPtr((void*)chars));
}

void MarshalString ( String ^ s, wstring& os ) {
   using namespace Runtime::InteropServices;
   const wchar_t* chars = 
      (const wchar_t*)(Marshal::StringToHGlobalUni(s)).ToPointer();
   os = chars;
   Marshal::FreeHGlobal(IntPtr((void*)chars));
}

int main() {
   string a = "test";
   wstring b = L"test2";
   String ^ c = gcnew String("abcd");

   cout << a << endl;
   MarshalString(c, a);
   c = "efgh";
   MarshalString(c, b);
   cout << a << endl;
   wcout << b << endl;
}


澶╀笅 2015-12-14 15:46 鍙戣〃璇勮
]]>C++鐨刣ll璋冪敤C#鐨刣llhttp://www.shnenglu.com/aaxron/archive/2015/12/07/212433.html澶╀笅澶╀笅Mon, 07 Dec 2015 12:23:00 GMThttp://www.shnenglu.com/aaxron/archive/2015/12/07/212433.htmlhttp://www.shnenglu.com/aaxron/comments/212433.htmlhttp://www.shnenglu.com/aaxron/archive/2015/12/07/212433.html#Feedback0http://www.shnenglu.com/aaxron/comments/commentRss/212433.htmlhttp://www.shnenglu.com/aaxron/services/trackbacks/212433.htmlC++鐨刣ll璋冪敤C#鐨刣ll
1錛夌敤C#鍐欎換浣曠殑綾誨簱錛屽錛歂eoWayMesCommon.dll
2錛塁++鐨刣ll涓寮曠敤姝ょ被搴擄紝娉ㄦ剰涓嶈兘鍦╯tdafx.h涓紩鐢紝鏈鍚庢槸鍦╟pp鏂囦歡涓紩鐢ㄣ?br />#using <mscorlib.dll>
#using "../Debug/NeoWayMesCommon.dll"  //寮曠敤姝ょ被搴?/span>
using namespace NeoWayMes;
using namespace System;
3) C++ 緙栬瘧璁劇疆涓瀹氳緗負錛氭敮鎸佸叕鍏辮璦榪愯鏃舵敮鎸?/clr)
4) 蹇呴』灝咰#鐨刣ll鎷瘋礉鑷砎C宸ョ▼榪愯鐨勭洰褰曪紝鍚﹀垯鎶ュ紓甯擱敊璇?br />5) 鍏朵粬鐨勫弬瑙乧++/cli璇硶鏍囧噯


澶╀笅 2015-12-07 20:23 鍙戣〃璇勮
]]>Double Thunkinghttp://www.shnenglu.com/aaxron/archive/2015/12/01/212375.html澶╀笅澶╀笅Tue, 01 Dec 2015 03:14:00 GMThttp://www.shnenglu.com/aaxron/archive/2015/12/01/212375.htmlhttp://www.shnenglu.com/aaxron/comments/212375.htmlhttp://www.shnenglu.com/aaxron/archive/2015/12/01/212375.html#Feedback0http://www.shnenglu.com/aaxron/comments/commentRss/212375.htmlhttp://www.shnenglu.com/aaxron/services/trackbacks/212375.html
By default, when compiling with /clr (not /clr:pure), the definition of a managed function causes the compiler to generate a managed entry point and a native 

entry point. This allows the managed function to be called from native and managed call sites. However, when a native entry point exists, it can be the entry 
point for all calls to the function. If a calling function is managed, the native entry point will then call the managed entry point. In effect, two calls 
are required to invoke the function (hence, double thunking). For example, virtual functions are always called through a native entry point.
One resolution is to tell the compiler not to generate a native entry point for a managed function, that the function will only be called from a managed 
context, by using the __clrcall calling convention.
Similarly, if you export (dllexport, dllimport) a managed function, a native entry point is generated and any function that imports and calls that function 
will call through the native entry point. To avoid double thunking in this situation, do not use native export/import semantics; simply reference the 
metadata via #using (see The #using Directive).
In Visual C++ 2005 the compiler was updated to reduce unnecessary double thunking. For example, any function with a managed type in the signature (including 
return type) will implicitly be marked as __clrcall. For more information on double thunk elimination, see 
http://msdn.microsoft.com/msdnmag/issues/05/01/COptimizations/default.aspx.
Example
The following sample demonstrates double thunking. When compiled native (without /clr), the call to the virtual function in main generates one call to T's 
copy constructor and one call to the destructor. Similar behavior is achieved when the virtual function is declared with /clr and __clrcall. However, when 
just compiled with /clr, the function call generates a call to the copy constructor but there is another call to the copy constructor due to the 
native-to-managed thunk.
綰?MSIL 紼嬪簭闆嗗彲浠ヨ皟鐢ㄩ潪鎵樼鍑芥暟錛屼絾涓嶈兘鐢遍潪鎵樼鍑芥暟璋冪敤銆傚洜姝わ紝涓庨潪鎵樼鍑芥暟浣跨敤鐨勬湇鍔″櫒浠g爜鐩告瘮錛岀函 MSIL 鏇撮傚悎浜庝嬌鐢ㄩ潪鎵樼鍑芥暟鐨勫鎴風浠g爜銆?/div>
褰撴垜浠嬌鐢?clr閫夐」錛堜笉鏄?clr:pure錛夎繘琛岀紪璇戠殑鏃跺欙紝涓涓墭綆″嚱鏁?managed function)錛屼細瀵艱嚧緙栬瘧鍣ㄧ敓鎴愪竴涓墭綆$殑鍏ュ彛鐐?managed entry point)鍜屼竴涓師鐢熺殑鍏ュ彛鐐?/div>
(native entry point)錛岃繖鏍峰彲浠ヤ嬌寰楁墭綆″嚱鏁版棦鍙互琚墭綆′唬鐮佽皟鐢紝涔熷彲浠ヨ鍘熺敓浠g爜璋冪敤銆備絾鏄紝褰撲竴涓師鐢熺殑鍏ュ彛鐐瑰瓨鍦ㄧ殑鏃跺欙紝瀹冨皢鎴愪負鎵鏈夎皟鐢ㄧ殑鍏ュ彛鐐廣備篃灝辨槸璇?/div>
濡傛灉璋冪敤鑰呮槸鎵樼鐨勶紝瀹冭繕鏄細鍏堝幓璋冪敤鍘熺敓鍏ュ彛鐐癸紝鐒跺悗鍘熺敓鐨勫叆鍙g偣鍐嶅幓璋冪敤鎵樼鐨勫叆鍙g偣錛岃繖灝辨剰鍛崇潃璋冪敤浜嗕袱嬈″嚱鏁板叆鍙g偣錛圖ouble Thunking錛夈?nbsp;



c++ cli 鏍囧噯


澶╀笅 2015-12-01 11:14 鍙戣〃璇勮
]]>濡備綍錛氫嬌鐢?C++ Interop 灝侀?ANSI 瀛楃涓?/title><link>http://www.shnenglu.com/aaxron/archive/2015/12/01/212373.html</link><dc:creator>澶╀笅</dc:creator><author>澶╀笅</author><pubDate>Tue, 01 Dec 2015 03:09:00 GMT</pubDate><guid>http://www.shnenglu.com/aaxron/archive/2015/12/01/212373.html</guid><wfw:comment>http://www.shnenglu.com/aaxron/comments/212373.html</wfw:comment><comments>http://www.shnenglu.com/aaxron/archive/2015/12/01/212373.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/aaxron/comments/commentRss/212373.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/aaxron/services/trackbacks/212373.html</trackback:ping><description><![CDATA[<div style="font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; background-color: #eeeeee;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008000; ">//</span><span style="color: #008000; "> MarshalANSI1.cpp<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; "> compile with: /clr</span><span style="color: #008000; "><br /></span>#include <iostream><br />#include <stdio.h><br /><br /><span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> std;<br /><span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> System;<br /><span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> System::Runtime::InteropServices;<br /><br />#pragma unmanaged<br /><br /><span style="color: #0000FF; ">void</span> NativeTakesAString(<span style="color: #0000FF; ">const</span> <span style="color: #0000FF; ">char</span>* p) {<br />   printf_s("(native) received '%s'\n", p);<br />}<br /><br />#pragma managed<br /><br /><span style="color: #0000FF; ">int</span> main() {<br />   String^ s = gcnew String("sample string");<br />   IntPtr ip = Marshal::StringToHGlobalAnsi(s);<br />   <span style="color: #0000FF; ">const</span> <span style="color: #0000FF; ">char</span>* str = static_cast<<span style="color: #0000FF; ">const</span> <span style="color: #0000FF; ">char</span>*>(ip.ToPointer());<br /><br />   Console::WriteLine("(managed) passing string<img src="http://www.shnenglu.com/Images/dot.gif" alt="" />");<br />   NativeTakesAString( str );<br /><br />   Marshal::FreeHGlobal( ip );<br />}<br /> <br /><br />涓嬮潰鐨勭ず渚嬫紨紺鴻闂敱闈炴墭綆″嚱鏁拌皟鐢ㄧ殑鎵樼鍑芥暟涓殑 ANSI 瀛楃涓叉墍闇鐨勬暟鎹皝閫佸鐞嗐傛墭綆″嚱鏁板湪鎺ユ敹鍒版湰鏈哄瓧絎︿覆鏃訛紝鍙互鐩存帴浣跨敤璇ュ瓧絎︿覆錛屼篃鍙互鎸夋墍紺烘柟寮忎嬌鐢?nbsp;PtrToStringAnsi 鏂規(guī)硶灝嗗叾杞崲涓烘墭綆″瓧絎︿覆銆?br /><br />  澶嶅埗浠g爜 <br /><span style="color: #008000; ">//</span><span style="color: #008000; "> MarshalANSI2.cpp<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; "> compile with: /clr</span><span style="color: #008000; "><br /></span>#include <iostream><br />#include <vcclr.h><br /><br /><span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> std;<br /><br /><span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> System;<br /><span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> System::Runtime::InteropServices;<br /><br />#pragma managed<br /><br /><span style="color: #0000FF; ">void</span> ManagedStringFunc(<span style="color: #0000FF; ">char</span>* s) {<br />   String^ ms = Marshal::PtrToStringAnsi(static_cast<IntPtr>(s));<br />   Console::WriteLine("(managed): received '{0}'", ms);<br />}<br /><br />#pragma unmanaged<br /><br /><span style="color: #0000FF; ">void</span> NativeProvidesAString() {<br />   cout << "(native) calling managed func<img src="http://www.shnenglu.com/Images/dot.gif" alt="" />\n";<br />   ManagedStringFunc("test string");<br />}<br /><br />#pragma managed<br /><br /><span style="color: #0000FF; ">int</span> main() {<br />   NativeProvidesAString();<br />}<br /> </div><img src ="http://www.shnenglu.com/aaxron/aggbug/212373.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/aaxron/" target="_blank">澶╀笅</a> 2015-12-01 11:09 <a href="http://www.shnenglu.com/aaxron/archive/2015/12/01/212373.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>濡備綍錛氬皢 System::String 杞崲涓?wchar_t* 鎴?char*http://www.shnenglu.com/aaxron/archive/2015/12/01/212372.html澶╀笅澶╀笅Tue, 01 Dec 2015 03:08:00 GMThttp://www.shnenglu.com/aaxron/archive/2015/12/01/212372.htmlhttp://www.shnenglu.com/aaxron/comments/212372.htmlhttp://www.shnenglu.com/aaxron/archive/2015/12/01/212372.html#Feedback0http://www.shnenglu.com/aaxron/comments/commentRss/212372.htmlhttp://www.shnenglu.com/aaxron/services/trackbacks/212372.html
ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.chs/dv_vccore/html/385da01b-5649-4543-8076-e3e251243ff0.htm
// convert_string_to_wchar.cpp
// compile with: /clr
#include < stdio.h >
#include < stdlib.h >
#include < vcclr.h >

using namespace System;

int main() {
   String ^str = "Hello";

   // Pin memory so GC can't move it while native function is called
   pin_ptr<const wchar_t> wch = PtrToStringChars(str);
   printf_s("%S\n", wch);

   // Conversion to char* :
   
// Can just convert wchar_t* to char* using one of the 
   
// conversion functions such as: 
   
// WideCharToMultiByte()
   
// wcstombs_s()
   
//  etc
   size_t convertedChars = 0;
   size_t  sizeInBytes = ((str->Length + 1) * 2);
   errno_t err = 0;
   char    *ch = (char *)malloc(sizeInBytes);

   err = wcstombs_s(&convertedChars, 
                    ch, sizeInBytes,
                    wch, sizeInBytes);
   if (err != 0)
      printf_s("wcstombs_s  failed!\n");

    printf_s("%s\n", ch);
}


澶╀笅 2015-12-01 11:08 鍙戣〃璇勮
]]>C# using 涓夌浣跨敤鏂瑰紡http://www.shnenglu.com/aaxron/archive/2015/11/10/212234.html澶╀笅澶╀笅Tue, 10 Nov 2015 02:45:00 GMThttp://www.shnenglu.com/aaxron/archive/2015/11/10/212234.htmlhttp://www.shnenglu.com/aaxron/comments/212234.htmlhttp://www.shnenglu.com/aaxron/archive/2015/11/10/212234.html#Feedback0http://www.shnenglu.com/aaxron/comments/commentRss/212234.htmlhttp://www.shnenglu.com/aaxron/services/trackbacks/212234.htmlC# using 涓夌浣跨敤鏂瑰紡
1.using鎸囦護銆?span style="color: #0000FF; ">using + 鍛藉悕絀洪棿鍚嶅瓧錛岃繖鏍峰彲浠ュ湪紼嬪簭涓洿鎺ョ敤鍛戒護絀洪棿涓殑綾誨瀷錛岃屼笉蹇呮寚瀹氱被鍨嬬殑璇︾粏鍛藉悕絀洪棿錛岀被浼間簬Java鐨刬mport錛岃繖涓姛鑳戒篃鏄渶甯哥敤鐨勶紝鍑犱箮姣忎釜cs鐨勭▼搴忛兘浼氱敤鍒般?nbsp;
渚嬪錛?span style="color: #0000FF; ">using System; 涓鑸兘浼氬嚭鐜板湪*.cs涓?br />
2.using鍒悕銆?span style="color: #0000FF; ">using + 鍒悕 = 鍖呮嫭璇︾粏鍛藉悕絀洪棿淇℃伅鐨勫叿浣撶殑綾誨瀷銆?nbsp;
榪欑鍋氭硶鏈変釜濂藉灝辨槸褰撳悓涓涓猚s寮曠敤浜嗕袱涓笉鍚岀殑鍛藉悕絀洪棿錛屼絾涓や釜鍛藉悕絀洪棿閮藉寘鎷簡涓涓浉鍚屽悕瀛楃殑綾誨瀷鐨勬椂鍊欍傚綋闇瑕佺敤鍒拌繖涓被鍨嬬殑鏃跺欙紝灝辨瘡涓湴鏂歸兘瑕佺敤璇︾粏鍛藉悕絀洪棿鐨勫姙娉曟潵鍖哄垎榪欎簺鐩稿悓鍚嶅瓧鐨勭被鍨嬨傝岀敤鍒悕鐨勬柟娉曚細鏇寸畝媧侊紝鐢ㄥ埌鍝釜綾誨氨緇欏摢涓被鍋氬埆鍚嶅0鏄庡氨鍙互浜嗐傛敞鎰忥細騫朵笉鏄涓や釜鍚嶅瓧閲嶅錛岀粰鍏朵腑涓涓敤浜嗗埆鍚嶏紝鍙﹀涓涓氨涓嶉渶瑕佺敤鍒悕浜嗭紝濡傛灉涓や釜閮借浣跨敤錛屽垯涓や釜閮介渶瑕佺敤using鏉ュ畾涔夊埆鍚嶇殑銆?br />using Row = Newtonsoft.Json.Linq.JObject;
using Rows = Newtonsoft.Json.Linq.JArray;

3.using璇彞錛屽畾涔変竴涓寖鍥達紝鍦ㄨ寖鍥寸粨鏉熸椂澶勭悊瀵硅薄銆?nbsp;
鍦烘櫙錛?nbsp;
褰撳湪鏌愪釜浠g爜孌典腑浣跨敤浜嗙被鐨勫疄渚嬶紝鑰屽笇鏈涙棤璁哄洜涓轟粈涔堝師鍥狅紝鍙紱誨紑浜嗚繖涓唬鐮佹灝辮嚜鍔ㄨ皟鐢ㄨ繖涓被瀹炰緥鐨凞ispose銆?nbsp;
瑕佽揪鍒拌繖鏍風殑鐩殑錛岀敤trycatch鏉ユ崟鎹夊紓甯鎬篃鏄彲浠ョ殑錛屼絾鐢╱sing涔熷緢鏂逛究銆?br />
using (Class1 cls1 = new Class1(), cls2 = new Class1())
{
  // the code using cls1, cls2
// call


澶╀笅 2015-11-10 10:45 鍙戣〃璇勮
]]>MySQL綆鍗曞皝瑁?/title><link>http://www.shnenglu.com/aaxron/archive/2015/07/30/211434.html</link><dc:creator>澶╀笅</dc:creator><author>澶╀笅</author><pubDate>Thu, 30 Jul 2015 11:59:00 GMT</pubDate><guid>http://www.shnenglu.com/aaxron/archive/2015/07/30/211434.html</guid><wfw:comment>http://www.shnenglu.com/aaxron/comments/211434.html</wfw:comment><comments>http://www.shnenglu.com/aaxron/archive/2015/07/30/211434.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/aaxron/comments/commentRss/211434.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/aaxron/services/trackbacks/211434.html</trackback:ping><description><![CDATA[<div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">using</span> System;<br /><span style="color: #0000FF; ">using</span> System.Collections.Generic;<br /><span style="color: #0000FF; ">using</span> System.ComponentModel;<br /><span style="color: #0000FF; ">using</span> System.Data;<br /><span style="color: #0000FF; ">using</span> System.Drawing;<br /><span style="color: #0000FF; ">using</span> System.Linq;<br /><span style="color: #0000FF; ">using</span> System.Text;<br /><span style="color: #0000FF; ">using</span> System.Windows.Forms;<br /><span style="color: #0000FF; ">using</span> MySql.Data.MySqlClient;<br /><span style="color: #0000FF; ">using</span> System.Xml;<br /><span style="color: #0000FF; ">using</span> Row = System.Collections.Generic.Dictionary<<span style="color: #0000FF; ">string</span>, <span style="color: #0000FF; ">string</span>>;<br /><br /><span style="color: #0000FF; ">namespace</span> NeowayFixPlatform<br />{<br />    <br />    <span style="color: #0000FF; ">class</span> MysqlFunction<br />    {<br />        <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">static</span> <span style="color: #0000FF; ">string</span> table_fix = "nw_fix_record";<br /><br />        <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">bool</span> IsConnected()<br />        {<br />            <span style="color: #0000FF; ">return</span> (mysql.State == ConnectionState.Open);<br />        }<br />        <span style="color: #0000FF; ">public</span> MysqlFunction()<br />        {<br />            <span style="color: #0000FF; ">if</span> (mysql.State != ConnectionState.Open)<br />                mysql.Open();<br />        }<br /><br />        ~MysqlFunction()<br />        {<br />            <span style="color: #0000FF; ">if</span> (mysql.State == ConnectionState.Open)<br />                mysql.Dispose();<br />        }<br />        <span style="color: #0000FF; ">private</span> <span style="color: #0000FF; ">static</span> String mysqlcon = GetConfigString();<br />        MySqlConnection mysql = <span style="color: #0000FF; ">new</span> MySqlConnection(mysqlcon);<br /><br /><br />        <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">string</span> quote(<span style="color: #0000FF; ">ref</span> <span style="color: #0000FF; ">string</span> value)<br />        {<br />            value = value.Replace(@"\", @"\\").Replace("'", @"\'");<br />            <span style="color: #0000FF; ">return</span> value;<br />        }<br />        <span style="color: #0000FF; ">public</span> StringBuilder quote(<span style="color: #0000FF; ">ref</span> StringBuilder value)<br />        {<br />            value = value.Replace(@"\", @"\\").Replace("'", @"\'");<br />            <span style="color: #0000FF; ">return</span> value;<br />        }<br /><br />        <span style="color: #0000FF; ">public</span> StringBuilder GetPairSQLString(Row row)<br />        {<br />            StringBuilder strSQL = <span style="color: #0000FF; ">new</span> StringBuilder();<br /><br />            <span style="color: #0000FF; ">foreach</span> (KeyValuePair<<span style="color: #0000FF; ">string</span>, <span style="color: #0000FF; ">string</span>> pair <span style="color: #0000FF; ">in</span> row)<br />            {<br />                <span style="color: #0000FF; ">string</span> value = pair.Value.ToString();<br />                <span style="color: #0000FF; ">this</span>.quote(<span style="color: #0000FF; ">ref</span> value);<br />                strSQL.AppendFormat("{0}='{1}',", pair.Key, value);<br />            }<br />            strSQL.Remove(strSQL.Length-1, 1);<br />            <span style="color: #0000FF; ">return</span> strSQL;<br />        }<br /><br /><br />        <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">bool</span> UpdateOne(<span style="color: #0000FF; ">string</span> table,Row row,<span style="color: #0000FF; ">string</span> format,<span style="color: #0000FF; ">params</span> <span style="color: #0000FF; ">object</span>[] args)<br />        {<br />            StringBuilder condition = <span style="color: #0000FF; ">new</span> StringBuilder();<br />            condition.AppendFormat(format, args);<br />            <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">this</span>.UpdateOne(table, row, condition.ToString());<br />        }<br /><br /><br />        <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">bool</span> UpdateOne(<span style="color: #0000FF; ">string</span> strTable, Row row, <span style="color: #0000FF; ">string</span> strQuery)<br />        {<br />            StringBuilder strSQL = <span style="color: #0000FF; ">new</span> StringBuilder();<br />            <span style="color: #0000FF; ">try</span><br />            {<br />                strSQL.AppendFormat("UPDATE {0} set {1} WHERE {2} LIMIT 1", strTable, GetPairSQLString(row), strQuery);<br />                <span style="color: #008000; ">//</span><span style="color: #008000; ">mysql.Open();</span><span style="color: #008000; "><br /></span>                MySqlCommand cmd = <span style="color: #0000FF; ">new</span> MySqlCommand(strSQL.ToString(), mysql);<br />                cmd.ExecuteNonQuery();<br />                cmd.Dispose();<br />                <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">true</span>;<br />            }<br />            <span style="color: #0000FF; ">catch</span> (System.Exception ex)<br />            {<br />                MessageBox.Show(ex.Message);<br />            }<br />            <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">false</span>;<br />        }<br />        <br /><br />        <span style="color: #0000FF; ">public</span> Row FetchOne(<span style="color: #0000FF; ">string</span> strSQL)<br />        {<br />            Row row = <span style="color: #0000FF; ">new</span> Row();<br />            <span style="color: #0000FF; ">try</span><br />            {<br />                <br />                <span style="color: #008000; ">//</span><span style="color: #008000; ">mysql.Open();</span><span style="color: #008000; "><br /></span>                MySqlCommand cmd = <span style="color: #0000FF; ">new</span> MySqlCommand(strSQL.ToString(),mysql);<br />                MySqlDataReader reader = cmd.ExecuteReader();<br />                reader.Read();<br />                <span style="color: #0000FF; ">for</span> (<span style="color: #0000FF; ">int</span> i = 0; i < reader.FieldCount; i++)<br />                {<br />                    <span style="color: #0000FF; ">if</span> (reader.HasRows)<br />                        row[reader.GetName(i)] = reader[i].ToString();<br />                }<br />                reader.Close();<br />                cmd.Dispose();<br />            }<br />            <span style="color: #0000FF; ">catch</span> (System.Exception ex)<br />            {<br />                MessageBox.Show(ex.Message);<br />            }<br />            <span style="color: #0000FF; ">return</span> row;<br />        }<br /><br /><br />        <span style="color: #0000FF; ">#region</span> 鑾峰彇鐧婚檰瀛楃<br />        <span style="color: #808080; ">///</span><span style="color: #008000; "> </span><span style="color: #808080; "><summary></span><span style="color: #008000; "><br />        </span><span style="color: #808080; ">///</span><span style="color: #008000; "> 鑾峰彇鐧婚檰瀛楃<br />        </span><span style="color: #808080; ">///</span><span style="color: #008000; "> </span><span style="color: #808080; "></summary></span><span style="color: #008000; "><br />        </span><span style="color: #808080; ">///</span><span style="color: #008000; "> </span><span style="color: #808080; "><returns></returns></span><span style="color: #808080; "><br /></span>        <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">static</span> <span style="color: #0000FF; ">string</span> GetConfigString()<br />        {<br />            <span style="color: #0000FF; ">string</span> spath = Application.StartupPath;<br />            spath += "\\config.xml";<br />            XmlDocument xml = <span style="color: #0000FF; ">new</span> XmlDocument();<br />            xml.Load(spath);<br />            XmlNode config = xml.SelectSingleNode("config");<br />            XmlNode dbname = config.SelectSingleNode("dbname");<br />            XmlNode ipaddr = config.SelectSingleNode("ipaddr");<br />            XmlNode username = config.SelectSingleNode("username");<br />            XmlNode password = config.SelectSingleNode("password");<br /><br />            <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">string</span>.Format("database={0};Password={1};User ID={2};server={3}", dbname.InnerText, password.InnerText, username.InnerText, ipaddr.InnerText);<br />            <br />        }<br />        <span style="color: #0000FF; ">#endregion</span><br /><br /><br /><br />        <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">bool</span> BindData(<span style="color: #0000FF; ">string</span> sql,<span style="color: #0000FF; ">ref</span> DataGridView dgv)<br />        {<br />            DataSet dataset = <span style="color: #0000FF; ">new</span> DataSet();<br />            DataTable datatable = <span style="color: #0000FF; ">new</span> DataTable();<br />            <span style="color: #0000FF; ">try</span><br />            {<br />                MySqlDataAdapter mdap = <span style="color: #0000FF; ">new</span> MySqlDataAdapter(sql, mysql);<br />                mdap.Fill(dataset);<br />                datatable = dataset.Tables[0];<br />                dgv.DataSource = datatable;<br />                <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">true</span>;<br />            }<br />            <span style="color: #0000FF; ">catch</span> (Exception ex)<br />            {<br />                MessageBox.Show(ex.Message);<br />            }<br />            <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">false</span>;<br />        }<br /><br /><br />        <span style="color: #0000FF; ">#region</span> 鐢ㄦ埛鐧誨綍<br />        <span style="color: #808080; ">///</span><span style="color: #008000; "> </span><span style="color: #808080; "><summary></span><span style="color: #008000; "><br />        </span><span style="color: #808080; ">///</span><span style="color: #008000; "> 緋葷粺鐧誨綍<br />        </span><span style="color: #808080; ">///</span><span style="color: #008000; "> </span><span style="color: #808080; "></summary></span><span style="color: #008000; "><br />        </span><span style="color: #808080; ">///</span><span style="color: #008000; "> </span><span style="color: #808080; "><returns></returns></span><span style="color: #808080; "><br /></span>        <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">bool</span> Login(cUserInfo userinfo)<br />        {<br />            DataSet dataset = <span style="color: #0000FF; ">new</span> DataSet();<br />            DataTable datatable = <span style="color: #0000FF; ">new</span> DataTable();<br />            <span style="color: #0000FF; ">try</span><br />            {<br />                <span style="color: #008000; ">//</span><span style="color: #008000; ">MySqlDataAdapter 鏁版嵁搴撴墽琛屽嚱鏁幫紝鏌ヨ錛屾彃鍏ワ紝鍒犻櫎閮藉彲浣跨敤</span><span style="color: #008000; "><br /></span>               MySqlDataAdapter mdap = <span style="color: #0000FF; ">new</span> MySqlDataAdapter("select * from nw_user where user_name = '" + userinfo.User_name + "' and user_pwd = '" + userinfo.User_password + "'", mysql);<br />               mdap.Fill(dataset);<br />               datatable = dataset.Tables[0];<br /><br />            }<br />            <span style="color: #0000FF; ">catch</span> (Exception ex)<br />            {<br />                MessageBox.Show(ex.Message);<br />            }<br /><br />            <span style="color: #0000FF; ">if</span> (datatable.Rows.Count == 1)<br />            {<br />                DataRow datarow = datatable.Rows[0];<br />                userinfo.User_power = datarow["user_power"].ToString();<br />                <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">true</span>;<br />            }<br />            <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">false</span>;<br /> <br />        }<br />        <span style="color: #0000FF; ">#endregion</span><br /><br />        <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">bool</span> SaveFix(Dictionary<<span style="color: #0000FF; ">string</span>,<span style="color: #0000FF; ">string</span>> row,<span style="color: #0000FF; ">bool</span> bNew)<br />        {<br />            StringBuilder strSQL = <span style="color: #0000FF; ">new</span> StringBuilder();<br />            <span style="color: #0000FF; ">try</span><br />            {<br />                <span style="color: #0000FF; ">if</span> (bNew)<br />                    strSQL.Append("INSERT INTO nw_fix_record set ");<br />                <span style="color: #0000FF; ">else</span><br />                    strSQL.Append("UPDATE nw_fix_record set ");<br />                strSQL.AppendFormat("{0}",GetPairSQLString(row));<br /><br />                <span style="color: #0000FF; ">if</span> (!bNew)<br />                {<br />                    strSQL.AppendFormat(" WHERE IMEI_MEID='{0}' limit 1", row["IMEI_MEID"]);<br />                }<br />                <span style="color: #008000; ">//</span><span style="color: #008000; ">mysql.Open();</span><span style="color: #008000; "><br /></span><br />                MySqlCommand cmd = <span style="color: #0000FF; ">new</span> MySqlCommand(strSQL.ToString(), mysql);<br />                cmd.ExecuteNonQuery();<br />            }<br />            <span style="color: #0000FF; ">catch</span> (Exception ex)<br />            {<br />                MessageBox.Show(ex.Message);<br />                <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">false</span>;<br />            }<br />            <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">true</span>;<br />        }<br /><br />        <span style="color: #0000FF; ">#region</span> 鑾峰彇鎵鏈変駭鍝佸瀷鍙?br />        <span style="color: #808080; ">///</span><span style="color: #008000; "> </span><span style="color: #808080; "><summary></span><span style="color: #008000; "><br />        </span><span style="color: #808080; ">///</span><span style="color: #008000; "> 鑾峰彇鎵鏈変駭鍝佸瀷鍙?br />        </span><span style="color: #808080; ">///</span><span style="color: #008000; "> </span><span style="color: #808080; "></summary></span><span style="color: #008000; "><br />        </span><span style="color: #808080; ">///</span><span style="color: #008000; "> </span><span style="color: #808080; "><returns></returns></span><span style="color: #808080; "><br /></span>        <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">string</span>[] GetProducts()<br />        {<br />            DataSet dataset = <span style="color: #0000FF; ">new</span> DataSet();<br />            DataTable datatable = <span style="color: #0000FF; ">new</span> DataTable();<br />            <span style="color: #0000FF; ">string</span>[] rows = <span style="color: #0000FF; ">null</span>;<br />            <span style="color: #0000FF; ">try</span><br />            {<br /><br />                MySqlDataAdapter mdap = <span style="color: #0000FF; ">new</span> MySqlDataAdapter("select * from nw_product where 1", mysql);<br />                mdap.Fill(dataset);<br />                datatable = dataset.Tables[0];<br /><br />            }<br />            <span style="color: #0000FF; ">catch</span> (Exception ex)<br />            {<br />                MessageBox.Show(ex.Message);<br />                <span style="color: #0000FF; ">return</span> rows;<br />            }<br /><br />            <span style="color: #0000FF; ">int</span> row_count = datatable.Rows.Count;<br />            <span style="color: #0000FF; ">if</span> (row_count>0)<br />            {<br />                rows = <span style="color: #0000FF; ">new</span> <span style="color: #0000FF; ">string</span>[row_count];<br />                <span style="color: #0000FF; ">for</span> (<span style="color: #0000FF; ">int</span> i = 0; i < row_count; i++ )<br />                {<br />                    rows[i] = datatable.Rows[i][0].ToString();<br />                }<br />            }<br />            <span style="color: #0000FF; ">return</span> rows;<br />        }<br />        <span style="color: #0000FF; ">#endregion</span><br /><br /><br />        <span style="color: #0000FF; ">#region</span> 鑾峰彇鎵鏈夊鎴峰悕縐?br />        <span style="color: #808080; ">///</span><span style="color: #008000; "> </span><span style="color: #808080; "><summary></span><span style="color: #008000; "><br />        </span><span style="color: #808080; ">///</span><span style="color: #008000; "> 鑾峰彇鎵鏈夊鎴峰悕縐?br />        </span><span style="color: #808080; ">///</span><span style="color: #008000; "> </span><span style="color: #808080; "></summary></span><span style="color: #008000; "><br />        </span><span style="color: #808080; ">///</span><span style="color: #008000; "> </span><span style="color: #808080; "><returns></returns></span><span style="color: #808080; "><br /></span>        <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">string</span>[] GetAllClientName()<br />        {<br />            DataSet dataset = <span style="color: #0000FF; ">new</span> DataSet();<br />            DataTable datatable = <span style="color: #0000FF; ">new</span> DataTable();<br />            <span style="color: #0000FF; ">string</span>[] rows = <span style="color: #0000FF; ">null</span>;<br />            <span style="color: #0000FF; ">try</span><br />            {<br /><br />                MySqlDataAdapter mdap = <span style="color: #0000FF; ">new</span> MySqlDataAdapter("select client_name from nw_client where 1", mysql);<br />                mdap.Fill(dataset);<br />                datatable = dataset.Tables[0];<br /><br />            }<br />            <span style="color: #0000FF; ">catch</span> (Exception ex)<br />            {<br />                MessageBox.Show(ex.Message);<br />                <span style="color: #0000FF; ">return</span> rows;<br />            }<br /><br />            <span style="color: #0000FF; ">int</span> row_count = datatable.Rows.Count;<br />            <span style="color: #0000FF; ">if</span> (row_count > 0)<br />            {<br />                rows = <span style="color: #0000FF; ">new</span> <span style="color: #0000FF; ">string</span>[row_count];<br />                <span style="color: #0000FF; ">for</span> (<span style="color: #0000FF; ">int</span> i = 0; i < row_count; i++)<br />                {<br />                    rows[i] = datatable.Rows[i][0].ToString();<br />                }<br />            }<br />            <span style="color: #0000FF; ">return</span> rows;<br />        }<br />        <span style="color: #0000FF; ">#endregion</span><br /><br /><br />        <span style="color: #0000FF; ">#region</span> 鑾峰彇鎵鏈夌淮淇漢鍛?br />        <span style="color: #808080; ">///</span><span style="color: #008000; "> </span><span style="color: #808080; "><summary></span><span style="color: #008000; "><br />        </span><span style="color: #808080; ">///</span><span style="color: #008000; "> 鑾峰彇鎵鏈夌淮淇漢鍛?br />        </span><span style="color: #808080; ">///</span><span style="color: #008000; "> </span><span style="color: #808080; "></summary></span><span style="color: #008000; "><br />        </span><span style="color: #808080; ">///</span><span style="color: #008000; "> </span><span style="color: #808080; "><returns></returns></span><span style="color: #808080; "><br /></span>        <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">string</span>[] GetAllRepairEr()<br />        {<br />            DataSet dataset = <span style="color: #0000FF; ">new</span> DataSet();<br />            DataTable datatable = <span style="color: #0000FF; ">new</span> DataTable();<br />            <span style="color: #0000FF; ">string</span>[] rows = <span style="color: #0000FF; ">null</span>;<br />            <span style="color: #0000FF; ">try</span><br />            {<br /><br />                MySqlDataAdapter mdap = <span style="color: #0000FF; ">new</span> MySqlDataAdapter("select user_name from nw_user where user_power='緇翠慨鍛? order by user_id", mysql);<br />                mdap.Fill(dataset);<br />                datatable = dataset.Tables[0];<br /><br />            }<br />            <span style="color: #0000FF; ">catch</span> (Exception ex)<br />            {<br />                MessageBox.Show(ex.Message);<br />                <span style="color: #0000FF; ">return</span> rows;<br />            }<br /><br />            <span style="color: #0000FF; ">int</span> row_count = datatable.Rows.Count;<br />            <span style="color: #0000FF; ">if</span> (row_count > 0)<br />            {<br />                rows = <span style="color: #0000FF; ">new</span> <span style="color: #0000FF; ">string</span>[row_count];<br />                <span style="color: #0000FF; ">for</span> (<span style="color: #0000FF; ">int</span> i = 0; i < row_count; i++)<br />                {<br />                    rows[i] = datatable.Rows[i][0].ToString();<br />                }<br />            }<br />            <span style="color: #0000FF; ">return</span> rows;<br />        }<br /><br />    }<br />    <span style="color: #0000FF; ">#endregion</span><br /><br />    <span style="color: #0000FF; ">#region</span> 瀹氫箟鐢ㄦ埛琛?br />    <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">class</span> cUserInfo<br />        {<br />            <span style="color: #0000FF; ">private</span> <span style="color: #0000FF; ">int</span> user_id;<br /><br />            <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">int</span> User_id<br />            {<br />                <span style="color: #0000FF; ">get</span> { <span style="color: #0000FF; ">return</span> user_id; }<br />                <span style="color: #0000FF; ">set</span> { user_id = value; }<br />            }<br /><br />            <span style="color: #0000FF; ">private</span> <span style="color: #0000FF; ">string</span> user_name;<br /><br />            <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">string</span> User_name<br />            {<br />                <span style="color: #0000FF; ">get</span> { <span style="color: #0000FF; ">return</span> user_name; }<br />                <span style="color: #0000FF; ">set</span> { user_name = value; }<br />            }<br />            <span style="color: #0000FF; ">private</span> <span style="color: #0000FF; ">string</span> user_password;<br /><br />            <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">string</span> User_password<br />            {<br />                <span style="color: #0000FF; ">get</span> { <span style="color: #0000FF; ">return</span> user_password; }<br />                <span style="color: #0000FF; ">set</span> { user_password = value; }<br />            }<br />            <span style="color: #0000FF; ">private</span> <span style="color: #0000FF; ">string</span> user_power;<br /><br />            <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">string</span> User_power<br />            {<br />                <span style="color: #0000FF; ">get</span> { <span style="color: #0000FF; ">return</span> user_power; }<br />                <span style="color: #0000FF; ">set</span> { user_power = value; }<br />            }<br />        }<br />   <span style="color: #0000FF; ">#endregion</span><br />   <br />}</div><img src ="http://www.shnenglu.com/aaxron/aggbug/211434.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/aaxron/" target="_blank">澶╀笅</a> 2015-07-30 19:59 <a href="http://www.shnenglu.com/aaxron/archive/2015/07/30/211434.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鏉傝Json,MySQL,C#http://www.shnenglu.com/aaxron/archive/2015/07/06/211165.html澶╀笅澶╀笅Mon, 06 Jul 2015 11:37:00 GMThttp://www.shnenglu.com/aaxron/archive/2015/07/06/211165.htmlhttp://www.shnenglu.com/aaxron/comments/211165.htmlhttp://www.shnenglu.com/aaxron/archive/2015/07/06/211165.html#Feedback0http://www.shnenglu.com/aaxron/comments/commentRss/211165.htmlhttp://www.shnenglu.com/aaxron/services/trackbacks/211165.html
MySQL 1045鏉冮檺閿欒 鐨勮В鍐?
GRANT ALL PRIVILEGES ON *.* TO test_user@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;


libJson(Jsoncpp),澶熺敤浜?
C++:
extern "C" LIB_MESCLIENT_API int nw_save_prodmade_data(const char* jo_in);

Json::Value jo;
jo["row"]["product_id"] = "21265"; 
jo["row"]["product_sn"] = 223456789012345678; 
int error_code = nw_save_prodmade_data(jo.toStyledString().c_str());


C#涓嬬敤Newtonsoft.Json涔熸尯濂界敤鐨?br />using Newtonsoft.Json.Linq;
JObject jo = new JObject();
jo["row"] = new JObject();
//姝ら儴鍒嗗湪dll鍐呴儴浼氭彃鍏ュ埌鍙拷婧姸鎬佽〃 nw_sn_status
jo["row"]["product_id"] = "12\r\n3\"12'\"65"; //浜у搧ID
StringBuilder row = new StringBuilder(jo.ToString());
int error_code = nw_save_prodmade_data(row);




澶╀笅 2015-07-06 19:37 鍙戣〃璇勮
]]>C#涓粨鏋勪綋涓庡瓧鑺傛祦浜掔浉杞崲http://www.shnenglu.com/aaxron/archive/2012/09/20/191369.html澶╀笅澶╀笅Thu, 20 Sep 2012 03:37:00 GMThttp://www.shnenglu.com/aaxron/archive/2012/09/20/191369.htmlhttp://www.shnenglu.com/aaxron/comments/191369.htmlhttp://www.shnenglu.com/aaxron/archive/2012/09/20/191369.html#Feedback0http://www.shnenglu.com/aaxron/comments/commentRss/191369.htmlhttp://www.shnenglu.com/aaxron/services/trackbacks/191369.html 

涓銆乧#緇撴瀯浣?br />
1銆佸畾涔変笌C++瀵瑰簲鐨凜#緇撴瀯浣?br />
鍦╟#涓殑緇撴瀯浣撲笉鑳藉畾涔夋寚閽堬紝涓嶈兘瀹氫箟瀛楃鏁扮粍錛屽彧鑳藉湪閲岄潰瀹氫箟瀛楃鏁扮粍鐨勫紩鐢ㄣ?br />C
++鐨勬秷鎭粨鏋勪綋濡備笅錛?br />//娑堟伅鏍煎紡 4+16+4+4= 28涓瓧鑺?/span>
struct cs_message{
         u32_t        cmd_type;
         
char username[16];
         u32_t        dstID;
         u32_t        srcID;
};
C#瀹氫箟鐨勭粨鏋勪綋濡備笅:
[StructLayout(LayoutKind.Sequential, Pack 
= 1)]
    
public struct my_message
    {
        
public UInt32  cmd_type;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst 
= 16)]
        
public string username;    
        
public UInt32  dstID;
        
public UInt32  srcID;
        
public my_message(string s)
        {
            cmd_type 
= 0;
            username 
= s;
            dstID 
= 0;
            srcID 
= 0;
        }
}
鍦–
++鐨勫ご鏂囦歡瀹氫箟涓紝浣跨敤浜?nbsp;#pragma pack 1 瀛楄妭鎸?瀵歸綈錛屾墍浠#鐨勭粨鏋勪綋涔熷繀欏昏鍔犱笂瀵瑰簲鐨勭壒鎬э紝LayoutKind.Sequential灞炴ц緇撴瀯浣撳湪瀵煎嚭鍒伴潪鎵樼鍐呭瓨鏃舵寜鍑虹幇鐨勯『搴忎緷嬈″竷灞,鑰屽浜嶤++鐨刢har鏁扮粍綾誨瀷錛孋#涓彲浠ョ洿鎺ヤ嬌鐢╯tring鏉ュ搴旓紝褰撶劧浜嗭紝涔熻鍔犱笂灝侀佺殑鐗規(guī)у拰闀垮害闄愬埗銆?br />2銆佺粨鏋勪綋涓巄yte[]鐨勪簰鐩歌漿鎹?br />
瀹氫箟涓涓被錛岄噷闈㈡湁2涓柟娉曞幓瀹炵幇浜掕漿錛?br />
public class Converter
{
        
public Byte[] StructToBytes(Object structure)
        {
            Int32 size 
= Marshal.SizeOf(structure);
            Console.WriteLine(size);
            IntPtr buffer 
= Marshal.AllocHGlobal(size);
            
try
            {
                Marshal.StructureToPtr(structure, buffer, 
false);
                Byte[] bytes 
= new Byte[size];
                Marshal.Copy(buffer, bytes, 
0, size);
                
return bytes;
            }
            
finally
            {
                Marshal.FreeHGlobal(buffer);
            }
        }
        
public Object BytesToStruct(Byte[] bytes, Type strcutType)
        {
            Int32 size 
= Marshal.SizeOf(strcutType);
            IntPtr buffer 
= Marshal.AllocHGlobal(size);
            
try
            {
                Marshal.Copy(bytes, 
0, buffer, size);
                
return Marshal.PtrToStructure(buffer, strcutType);
            }
            
finally
            {
                Marshal.FreeHGlobal(buffer);
            }
        }
}
3銆佹祴璇曠粨鏋滐細

static void Main(string[] args)
{
    
//瀹氫箟杞崲綾葷殑涓涓璞″茍鍒濆鍖?/span>
Converter Convert = new Converter();
//瀹氫箟娑堟伅緇撴瀯浣?/span>
    my_message m;
 
    
//鍒濆鍖栨秷鎭粨鏋勪綋
    m = new my_message("yanlina");
    m.cmd_type 
= 1633837924;
    m.srcID 
= 1633837924;
m.dstID 
= 1633837924;
 
//浣跨敤杞崲綾葷殑瀵硅薄鐨凷tructToBytes鏂規(guī)硶鎶妋緇撴瀯浣撹漿鎹㈡垚Byte
Byte[] message = Convert.StructToBytes(m);
//浣跨敤杞崲綾葷殑瀵硅薄鐨凚ytesToStruct鏂規(guī)硶鎶夿yte杞崲鎴恗緇撴瀯浣?/span>
my_message n = (my_message)Convert.BytesToStruct(message, m.GetType());
//杈撳嚭嫻嬭瘯
    Console.WriteLine(Encoding.ASCII.GetString(message));
    Console.WriteLine(n.username);
}
緇撴瀯浣撶殑size鏄?8涓瓧鑺傚拰c
++鐨勭粨鏋勪綋涓鏍鳳紝鍚屾椂鍙互灝嗙粨鏋勪綋鍜屽瓧鑺傛暟緇勪簰杞紝鏂逛究UDP鐨勫彂閫佸拰鎺ユ敹銆?/span>


杞嚜:http://blog.csdn.net/huxiangyang4/article/details/5853247



澶╀笅 2012-09-20 11:37 鍙戣〃璇勮
]]>
C#濮旀淳Delegate http://www.shnenglu.com/aaxron/archive/2012/06/07/177941.html澶╀笅澶╀笅Thu, 07 Jun 2012 08:41:00 GMThttp://www.shnenglu.com/aaxron/archive/2012/06/07/177941.htmlhttp://www.shnenglu.com/aaxron/comments/177941.htmlhttp://www.shnenglu.com/aaxron/archive/2012/06/07/177941.html#Feedback0http://www.shnenglu.com/aaxron/comments/commentRss/177941.htmlhttp://www.shnenglu.com/aaxron/services/trackbacks/177941.html1:
//鐩存帴涓奙SDN涓婄殑C#浠g爜:
using System;
public class SamplesDelegate
{

    
// Declares a delegate for a method that takes in an int and returns a String.
    public delegate String myMethodDelegate(int myInt);

    
// Defines some methods to which the delegate can point.
    public class mySampleClass
    {

        
// Defines an instance method.
        public String myStringMethod(int myInt)
        {
            
if (myInt > 0)
                
return ("positive");
            
if (myInt < 0)
                
return ("negative");
            
return ("zero");
        }

        
// Defines a static method.
        public static String mySignMethod(int myInt)
        {
            
if (myInt > 0)
                
return ("+");
            
if (myInt < 0)
                
return ("-");
            
return ("");
        }
    }

    
public static void Main()
    {

        
// Creates one delegate for each method. For the instance method, an
        
// instance (mySC) must be supplied. For the static method, use the
        
// class name.
        mySampleClass mySC = new mySampleClass();
        myMethodDelegate myD1 
= new myMethodDelegate(mySC.myStringMethod);
        myMethodDelegate myD2 
= new myMethodDelegate(mySampleClass.mySignMethod);

        
// Invokes the delegates.
        Console.WriteLine("{0} is {1}; use the sign \"{2}\"."5, myD1(5), myD2(5));
        Console.WriteLine(
"{0} is {1}; use the sign \"{2}\"."-3, myD1(-3), myD2(-3));
        Console.WriteLine(
"{0} is {1}; use the sign \"{2}\"."0, myD1(0), myD2(0));
    }

}


2:
// d11.cpp : Defines the entry point for the console application.
//C++浠g爜

#include 
"stdafx.h"
#include 
<iostream>
#include 
<string>

using namespace std;

typedef 
string myMethodDelegate(int myInt);

string myStringMethod ( int myInt )  {
    
if ( myInt > 0 )
        
return string"positive" );
    
if ( myInt < 0 )
        
return string"negative" );
    
return string"zero" );
}

string mySignMethod ( int myInt )  {
    
if ( myInt > 0 )
        
return string"+" );
    
if ( myInt < 0 )
        
return string"-" );
    
return  string"" );
}

int _tmain(int argc, _TCHAR* argv[])
{
    myMethodDelegate
* myD1 = myStringMethod;
    myMethodDelegate
* myD2 = mySignMethod;

    
// Invokes the delegates.
    printf( "{%d} is {%s}; use the sign \"{%s}\". \r\n"5, myD1( 5 ).c_str(), myD2( 5 ).c_str() );
    printf( 
"{%d} is {%s}; use the sign \"{%s}\". \r\n"-3, myD1( -3 ).c_str(), myD2( -3 ).c_str() );
    printf( 
"{%d} is {%s}; use the sign \"{%s}\".\r\n"0, myD1( 0 ).c_str(), myD2( 0 ).c_str() );
    
return 0;
}









澶╀笅 2012-06-07 16:41 鍙戣〃璇勮
]]> 亚洲欧美日韩中文久久| 国产欧美一区二区久久| 亚洲人成无码久久电影网站| 久久久久国色AV免费观看| 日日狠狠久久偷偷色综合免费| 久久精品无码一区二区WWW| 亚洲国产欧洲综合997久久| 2021久久精品国产99国产精品| 亚洲精品国产第一综合99久久 | 久久久免费观成人影院 | 国产精品视频久久| 91久久香蕉国产熟女线看| 亚洲国产精品成人AV无码久久综合影院 | 无码精品久久久天天影视| 久久婷婷五月综合成人D啪| 久久精品一区二区国产| 人妻丰满?V无码久久不卡| 中文字幕亚洲综合久久| 午夜精品久久久久| 久久精品国产影库免费看| 97久久超碰成人精品网站| 久久免费99精品国产自在现线 | 亚洲AV日韩AV永久无码久久| 一本久久a久久精品综合夜夜| AV色综合久久天堂AV色综合在| 一本色道久久HEZYO无码| 亚洲精品无码久久久久AV麻豆| 久久99精品国产99久久6| 亚洲国产精品成人久久| 日韩欧美亚洲综合久久影院Ds| 精品久久久久久无码人妻热 | 亚洲第一永久AV网站久久精品男人的天堂AV| 波多野结衣中文字幕久久 | 日本国产精品久久| 久久精品视频91| 97久久精品国产精品青草| 午夜精品久久久久成人| 久久97久久97精品免视看秋霞| 久久99精品九九九久久婷婷| 国产精品久久久久天天影视| 久久久精品人妻一区二区三区蜜桃|