Managed and unmanaged in C #

Source: Internet
Author: User

Attention! First look at the upper left corner of the declaration! I don't want to fraught! But I'm not afraid to think. Without thinking there is no mistake, learn from each other and make progress together!

Baidu in the "professional" answer appeared in this sentence (do not know is not professional ah Baidu said) "1, refers to the managed code, the managed code is actually the intermediate language (IL) code." Managed ”

If this sentence is right, it should be right, then the escrow is good to understand, (own search intermediate language to go), we write the language to be translated through the intermediate language is called the escrow to IL

Then the unmanaged is not the IL without the intermediate language translation, others (Microsoft put) has already translated this statement, the white is packaged well, you go directly to use on the line, nonsense less say directly above the sub-

Using system;using system.runtime.interopservices;class example{    //Use DllImport to import the Win32 MessageBox func tion.    [DllImport ("user32.dll", CharSet = CharSet.Unicode)]    public static extern int MessageBox (IntPtr hWnd, string text, string caption, uint type);    static void Main ()    {        //Call the MessageBox function using platform invoke.        MessageBox (new IntPtr (0), "Hello world!", "Hello Dialog", 0);}    }

  This is used on MSDN dllimportattribute attribute import Win32

Namespace cpower_csharp{public class CP5200 {Private Const string m_strpath = "CP5200.dll";        [DllImport (M_strpath, CharSet = CharSet.Auto)] public static extern string Cp5200_rs232_getfilename (); [DllImport (M_strpath, CharSet = CharSet.Auto)] public static extern int Cp5200_rs232_splitscreen (int ncardid, int n         scrwidth, int nscrheight, int nwndcnt, int[] pwndrects); [DllImport (M_strpath, CharSet = CharSet.Auto)] public static extern int Cp5200_net_splitscreen (int ncardid, int nSc        rwidth, int nscrheight, int nwndcnt, int[] pwndrects); [DllImport (M_strpath, CharSet = CharSet.Auto)] public static extern int Cp5200_rs232_initex (IntPtr fName, int Nbaud        rate, int dwtimeout); [DllImport (M_strpath, CharSet = CharSet.Auto)] public static extern int Cp5200_net_init (UINT dwip, int nipport, UIn        T dwidcode, int ntimeout); [DllImport (M_strpath, CharSet = CharSet.Auto)] public static extern int Cp5200_rs232_open (); [DllImport (M_strpath, CharSet = CharSet.Auto)] public static extern int Cp5200_rs232_sendtext (int ncardid, int nwnd        No, IntPtr ptext, int crcolor, int nfontsize, int nspeed, int neffect, int nstaytime, int nalignment); [DllImport (M_strpath, CharSet = CharSet.Auto)] public static extern int Cp5200_net_sendtext (int ncardid, int nwndno        , IntPtr ptext, int crcolor, int nfontsize, int nspeed, int neffect, int nstaytime, int nalignment); [DllImport (M_strpath, CharSet = CharSet.Auto)] public static extern int Cp5200_rs232_sendtagtext (int ncardid, int n        Wndno, IntPtr ptext, int crcolor, int nfontsize, int nspeed, int neffect, int nstaytime, int nalignment); [DllImport (M_strpath, CharSet = CharSet.Auto)] public static extern int Cp5200_net_sendtagtext (int ncardid, int nWn        DNo, IntPtr ptext, int crcolor, int nfontsize, int nspeed, int neffect, int nstaytime, int nalignment);       [DllImport (M_strpath, CharSet = CharSet.Auto)] public static extern int cp5200_rs232_sendpicture (int ncardid, int nwndno, int nposx, int nposy, int nCx, int nCy, INTPTR        ppicturefile, int nspeed, int neffect, int nstaytime, int npictref); [DllImport (M_strpath, CharSet = CharSet.Auto)] public static extern int cp5200_net_sendpicture (int ncardid, int nWn            dNo, int nposx, int nposy, int nCx, int nCy, IntPtr ppicturefile, int nspeed, int neffect, int nstaytime, int npictref); [DllImport (M_strpath, CharSet = CharSet.Auto)] public static extern int cp5200_rs232_sendstatic (int nCar        did, int nwndno, IntPtr ptext, int crcolor, int nfontsize, int nalignment, int x, int y, int cx, int cy); [DllImport (M_strpath, CharSet = CharSet.Auto)] public static extern int cp5200_net_sendstatic (int ncardid, int nwnd        No, IntPtr ptext, int crcolor, int nfontsize, int nalignment, int x, int y, int cx, int cy); [DllImport (M_strpath, CharSet = CharSet.Auto)] public static extern int Cp5200_rs232_sendclock(int ncardid, int nwinno, int nstaytime, int ncalendar, int nformat, int ncontent, int nfont, int nred, int ngreen, int NB        Lue, IntPtr pTxt); [DllImport (M_strpath, CharSet = CharSet.Auto)] public static extern int Cp5200_net_sendclock (int ncardid, int nwinn        o, int nstaytime, int ncalendar, int nformat, int ncontent, int nfont, int nred, int ngreen, int nblue, IntPtr pTxt); [DllImport (M_strpath, CharSet = CharSet.Auto)] public static extern int Cp5200_rs232_settime (byte ncardid, byte        [] pInfo); [DllImport (M_strpath, CharSet = CharSet.Auto)] public static extern int Cp5200_net_settime (byte ncardid, byte[] PIn        FO); [DllImport (M_strpath, CharSet = CharSet.Auto)] public static extern int CP5200_RS232_PLAYSELECTEDPRG (int ncardid, I        Nt[] pselected, int nselcnt, int noption); [DllImport (M_strpath, CharSet = CharSet.Auto)] public static extern int CP5200_NET_PLAYSELECTEDPRG (int ncardid, int [] pselected, int nselcnt, int noption);   }} 

 Private intInitcomm () {intNret =0; stringStrport; if(0==M_ncommtype) {Strport="COM"+m_nport.tostring (); Nret=CP5200.            Cp5200_rs232_initex (Marshal.stringtohglobalansi (Strport), m_nbaudrate, m_ntimeout); }            Else{m_dwipaddr=GetIP (Ipaddr.text); if(0!=m_dwipaddr) {M_dwidcode=GetIP (Idcode.text); if(0!=M_dwidcode) { CP5200.                        Cp5200_net_init (M_dwipaddr, M_nipport, M_dwidcode, m_ntimeout); Nret=1; }                }            }            returnNret; }


The red code directly refers to the amount, because it is a static method without an instance of the OK

Managed and unmanaged in C #

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.