青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

posts - 17,  comments - 2,  trackbacks - 0


一 混合類

所謂混合類是指CLI/C++中native的Class中可以包含CLR對象,CLR的class也可以包含Naitve的對象。

1)native的class中包含CLR對象,必須通過gcroot<>或auto_gcroot<>。
2)CLR中的class中包含native的對象,必須是指針,也可以使用高手寫的CAutoNativePtr智能指針。


注意:C#中不能調用CLI/C++中的Native的class。同樣Native C++中也不能調用CLI/C++中的Ref的class。

二 實例

 高手的CAutoNativePtr類:

/***
    CAutoNativePtr - A smart pointer for using native objects in managed code.

    Author    :    Nishant Sivakumar
    Email    :    voidnish@gmail.com    
    Blog    :    
http://blog.voidnish.com
    Web        :    
http://www.voidnish.com     

    You may freely use this class as long as you include
    this copyright. 
    
    You may freely modify and use this class as long
    as you include this copyright in your modified version. 

    This code is provided "as is" without express or implied warranty. 
    
    Copyright ?Nishant Sivakumar, 2006.
    All Rights Reserved.
**
*/


#pragma once

template
<typename T> ref class CAutoNativePtr
{
private:
    T
* _ptr;

public:
    CAutoNativePtr() : _ptr(nullptr)
    
{
    }


    CAutoNativePtr(T
* t) : _ptr(t)
    
{
    }


    CAutoNativePtr(CAutoNativePtr
<T>% an) : _ptr(an.Detach())
    
{
    }


    template
<typename TDERIVED> 
        CAutoNativePtr(CAutoNativePtr
<TDERIVED>% an) : _ptr(an.Detach())
    
{
    }


    
!CAutoNativePtr()
    
{    
        delete _ptr;
    }


    
~CAutoNativePtr()
    
{
        
this->!CAutoNativePtr();
    }


    CAutoNativePtr
<T>% operator=(T* t)
    
{
        Attach(t);
        
return *this;
    }


    CAutoNativePtr
<T>% operator=(CAutoNativePtr<T>% an)
    
{
        
if(this != %an)
            Attach(an.Detach());
        
return *this;
    }


    template
<typename TDERIVED> 
        CAutoNativePtr
<T>% operator=(CAutoNativePtr<TDERIVED>% an)
    
{
        Attach(an.Detach());
        
return *this;
    }


    
static T* operator->(CAutoNativePtr<T>% an)
    
{
        
return an._ptr;
    }


    
static operator T*(CAutoNativePtr<T>% an)
    
{
        
return an._ptr;
    }


    T
* Detach()
    
{
        T
* t = _ptr;
        _ptr 
= nullptr;
        
return t;
    }


    
void Attach(T* t)
    
{
        
if(t)
        
{    
            
if(_ptr != t)
            
{
                delete _ptr;
                _ptr 
= t;
            }

        }

        
else
        
{
#ifdef _DEBUG
            
throw gcnew Exception(
                
"Attempting to Attach() a nullptr!");
#endif
        }
        
    }


    
void Destroy()
    
{
        delete _ptr;
        _ptr 
= nullptr;
    }

}
;

測試實例之CLI/C++文件:
// MixedNativeAndCLIDLL.h

#pragma once
#include 
<string>
#include 
<iostream>
#include 
<gcroot.h>
#include 
<msclr/auto_gcroot.h>

#include 
"AutoNative.h"

using namespace System;

namespace MixedNativeAndCLIDLL {

    
public class NativeClass
    
{
    
public:
        
int *pX;    
        NativeClass()
{pX = new int(10);}
        
~NativeClass()
        
{
            
if(pX != NULL)
            
{
                delete pX;
                pX 
= NULL;
            }

        }
        
    }
;

    
public ref class RefClass
    
{
    
public:
        
int x;    
        RefClass()
{x = 20;}
    }
;

    
public class MixedClass0
    
{
        
public:
            NativeClass nativeClass;
            
//RefClass refClass; // error c3265 and error c3149
            gcroot<RefClass^> refClass1;

            std::
string nativeStr;
            
//System::String refStr; // error c3265 and error c3149
            gcroot<System::String^> refStr1;

            MixedClass0()
            
{
                refClass1 
= gcnew RefClass();
                refStr1 
= gcnew System::String("i am a native class mixed some clr members.\n");
            }

            
~MixedClass0()
            
{            
                delete refClass1;
                delete refStr1;
            }


            
void PrintSelf()
            
{
                System::Console::WriteLine(
"my name is MixedClass0");
                System::Console::WriteLine(refClass1
->x);
                System::Console::WriteLine(refStr1);
            }

    }
;

    
public class MixedClass1
    
{
        
public:
            NativeClass nativeClass;
            
//RefClass refClass; // error c3265 and error c3149
            msclr::auto_gcroot<RefClass^> refClass1;

            std::
string nativeStr;
            
//System::String refStr; // error c3265 and error c3149
            msclr::auto_gcroot<System::String^> refStr1;

            MixedClass1()
            
{
                refClass1 
= gcnew RefClass();
                refStr1 
= gcnew System::String("i am a native class with some clr members.\n");
            }

            
~MixedClass1()
            
{
                
// no need to delete.
            }
        

            
void PrintSelf()
            
{
                System::Console::WriteLine(
"my name is MixedClass1");
                System::Console::WriteLine(refClass1
->x);
                System::Console::WriteLine(refStr1);
            }

    }
;

    
public ref class MixedClass2
    
{
        
public:
            
//NativeClass nativeClass; // error c4368
            NativeClass * nativeClass1;
            RefClass
^ refClass; 
            
            
//std::string nativeStr; // error c4368
            std::string *nativeStr1;
            System::String
^ refStr; //     

            MixedClass2()
            
{
                nativeClass1 
= new NativeClass();
                nativeStr1 
= new std::string("i am a clr class with some native members.\n");
            }

            
~MixedClass2()
            
{
                delete nativeClass1;
                delete nativeStr1;
            }

            
!MixedClass2(){}

            
void PrintSelf()
            
{
                System::Console::WriteLine(
"my name is MixedClass2");
                std::cout
<<*(nativeClass1->pX)<<std::endl;
                std::cout
<<*nativeStr1<<std::endl;                
            }

    }
;
    
    
public ref class MixedClass3
    
{
        
public:
            
//NativeClass nativeClass; // error c4368
            CAutoNativePtr<NativeClass> nativeClass1;
            RefClass
^ refClass; 
            
            
//std::string nativeStr; // error c4368
            CAutoNativePtr<std::string> nativeStr1;
            System::String
^ refStr; //     

            MixedClass3()
            
{
                nativeClass1 
= new NativeClass();
                nativeStr1 
= new std::string("i am a clr class with some native members.\n");
            }

            
~MixedClass3(){}
            
!MixedClass3(){}

            
void PrintSelf()
            
{
                System::Console::WriteLine(
"my name is MixedClass3");
                std::cout
<<*(nativeClass1->pX)<<std::endl;
                std::cout
<<*nativeStr1<<std::endl;                
            }

    }
;
}


測試實例之C#調用文件:
using System;
using System.Collections.Generic;
using System.Text;

namespace CsharpTest
{
    
class Program
    
{
        
static void Main(string[] args)
        
{
            MixedNativeAndCLIDLL.MixedClass0 mixedClass0 
= new MixedNativeAndCLIDLL.MixedClass0();
            
//mixedClass0.PrintSelf();
            MixedNativeAndCLIDLL.MixedClass1 mixedClass1 = new MixedNativeAndCLIDLL.MixedClass1();
            
//mixedClass1.PrintSelf();
            MixedNativeAndCLIDLL.MixedClass2 mixedClass2 = new MixedNativeAndCLIDLL.MixedClass2();
            mixedClass2.PrintSelf();
            MixedNativeAndCLIDLL.MixedClass3 mixedClass3 
= new MixedNativeAndCLIDLL.MixedClass3();
            mixedClass3.PrintSelf();
        }

    }

}


三 代碼下載

http://m.shnenglu.com/Files/mzty/MixedNativeAndCLITest.rar
posted on 2008-11-08 13:26 BeyondCN 閱讀(885) 評論(0)  編輯 收藏 引用 所屬分類: .NET
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲国产cao| 欧美系列电影免费观看| 亚洲成色www8888| 免费h精品视频在线播放| 久久久久国产精品一区二区| 久久久久国产一区二区三区| 羞羞视频在线观看欧美| 久久精品国产99| 欧美国产一区在线| 亚洲人被黑人高潮完整版| 一本久久a久久精品亚洲| 亚洲主播在线| 久久亚洲精品一区二区| 欧美精品91| 国产一区二区黄| 亚洲日本中文字幕区| 亚洲小说欧美另类社区| 久久亚洲一区二区| 99re6这里只有精品视频在线观看| 亚洲先锋成人| 欧美88av| 激情六月婷婷综合| 亚洲午夜电影在线观看| 美女被久久久| 亚洲一区二区在线看| 久久综合狠狠综合久久激情| 欧美日韩黄视频| 1024欧美极品| 欧美xx69| 男人的天堂亚洲| 日韩网站在线观看| 久久久午夜视频| 欧美性一二三区| 欧美精品麻豆| 亚洲破处大片| 羞羞视频在线观看欧美| 欧美成人精品福利| 亚洲一区二区视频在线| 欧美精品福利| 海角社区69精品视频| 亚洲一区二区3| 亚洲国产精品久久91精品| 亚洲欧美网站| 欧美性生交xxxxx久久久| 亚洲日本成人| 女同性一区二区三区人了人一| 中文有码久久| 欧美天天在线| 久久免费一区| 午夜精品视频在线观看一区二区| 免费在线观看成人av| 黄色成人av网| 久久精品91久久久久久再现| 亚洲视频在线一区| 欧美日韩一级视频| 一区二区欧美国产| 亚洲精品在线观| 久久视频一区| 曰本成人黄色| 欧美777四色影视在线| 久久黄金**| 有坂深雪在线一区| 欧美黄色影院| 欧美日韩国产123区| 亚洲桃花岛网站| 亚洲欧美久久久久一区二区三区| 国产精品一区二区久久久久| 午夜亚洲一区| 亚洲欧美综合一区| 国模吧视频一区| 欧美成人午夜剧场免费观看| 另类图片国产| 亚洲美女av在线播放| 日韩一级精品| 国产视频亚洲| 欧美电影美腿模特1979在线看| 久久精品一区蜜桃臀影院| 亚洲大片av| 亚洲黄色在线| 国产精品国色综合久久| 欧美在线观看视频在线| 久久动漫亚洲| 91久久国产综合久久| 夜夜嗨av一区二区三区四区 | 午夜精品久久久久久99热软件| 日韩一二在线观看| 日韩亚洲欧美一区| 国产一区二区三区久久精品| 欧美大片在线看免费观看| 欧美激情精品久久久久久| 亚洲一区二区精品在线| 欧美一区不卡| 日韩亚洲欧美一区二区三区| 亚洲图片在线| 在线观看中文字幕亚洲| aa级大片欧美| 亚洲国产精品va| 亚洲一区二区免费| 亚洲精品日韩综合观看成人91| 亚洲男人的天堂在线| 最新精品在线| 欧美一区二区视频免费观看| 亚洲无玛一区| 欧美激情久久久| 另类人畜视频在线| 国产精品久久久久久久久久久久久久 | 亚洲理伦电影| 欧美一区二区三区精品| 正在播放欧美视频| 久久一本综合频道| 欧美在线视频不卡| 欧美三日本三级少妇三2023 | 一区二区毛片| 麻豆精品网站| 久久久天天操| 国产精品手机在线| av成人福利| 亚洲另类黄色| 久久综合狠狠综合久久综合88| 欧美一区在线直播| 欧美午夜剧场| 一本色道久久综合| 日韩一级片网址| 欧美电影免费观看高清| 欧美第一黄色网| 亚洲成人在线免费| 久久精品视频va| 久久婷婷色综合| 黄色精品免费| 久久久久国产精品人| 女人色偷偷aa久久天堂| 在线观看一区| 欧美大成色www永久网站婷| 欧美www视频| 亚洲福利一区| 欧美激情久久久久| 亚洲欧洲一区| 一本大道久久精品懂色aⅴ| 欧美日韩1080p| aa级大片欧美三级| 午夜精品三级视频福利| 国产麻豆精品theporn| 欧美亚洲综合另类| 国产精品视频网站| 欧美jizzhd精品欧美喷水 | 国产尤物精品| 久久婷婷久久一区二区三区| 久久蜜桃资源一区二区老牛| 精品999在线观看| 欧美成人免费在线视频| 亚洲精品乱码久久久久久黑人| 一本一本久久a久久精品综合妖精| 欧美美女日韩| 亚洲欧美一区二区激情| 久久综合网络一区二区| 亚洲激情二区| 国产精品久久久999| 久久久九九九九| 亚洲精品自在久久| 久久国产66| 最新国产拍偷乱拍精品| 国产精品swag| 久久精品最新地址| 亚洲免费av片| 久久久久国产免费免费| 99国产一区二区三精品乱码| 国产精品久久久久久久久搜平片| 香蕉成人伊视频在线观看| 欧美黄色成人网| 欧美一区二区三区四区在线| 精品91久久久久| 国产精品卡一卡二| 欧美成人午夜激情| 欧美亚洲三级| 一区二区三区四区国产精品| 久久综合电影一区| 亚洲一区www| 在线精品亚洲一区二区| 国产精品久久毛片a| 美日韩精品免费观看视频| 亚洲少妇中出一区| 亚洲欧洲一区二区三区在线观看| 亚洲欧美日本国产有色| 欧美色视频一区| 国产亚洲精品aa| 精品成人在线视频| 欧美激情一二三区| 99视频日韩| 免费看亚洲片| 亚洲欧美日韩国产一区二区三区 | 欧美亚洲在线| 亚洲精品少妇| 亚洲电影毛片| 国产无一区二区| 国产精品久久99| 欧美精品福利在线| 母乳一区在线观看| 久久午夜av| 久久精品国产91精品亚洲| 亚洲一二三四区|