这两天学习了一下C++/CLI,将C#几个控件和例子翻写C++下,感觉确实还是属于Beta的语言,Bug是在不少,而且很多你就根本没有办法去调试。
列举如下,当然也有可能使我栽赃,水平不行,导致出现的错误。
1、首先是托管DirectX。
代码如下:
Texture
^
CreateTextureFromFileEx(Device
^
device, String
^
filename,
int
w,
int
h,
int
mip, Usage usage, Format fmt, Pool pool, Filter filter, Filter mipfilter,
int
colorkey)

{
// Search the cache first
for each(CachedTexture^ ct in safe_cast<array<CachedTexture^>^>(textureCache->Keys))

{
if ( (String::Compare(ct->Source, filename, true) == 0) &&
ct->Width == w &&
ct->Height == h &&
ct->MipLevels == mip &&
ct->Usage == usage &&
ct->Format == fmt &&
ct->Pool == pool &&
ct->Type == ResourceType::Textures)

{
// A match was found, return that
// 错误代码 return (safe_cast<Texture^>(textureCache[ct]));
}
}
出现错误error C2535: 'Microsoft::DirectX::Direct3D::Texture::~Texture(void)' : member function already defined or declared c:\xhluo\程序开发
\My codes\CustomUIMC++\CustomUI\DXMUTMisc.h 644。到网上一找,有这个错误的还不少,给的建议,暂时放弃,等待成熟。
二、RssBandit下的一个封装IE的Control,也翻写了一下,发现也有问题。
HtmlControl::HtmlControl() : AxHost(
"
8856f961-340a-11d0-a96b-00c04fd705a2
"
)

{
this->cbFlags = ControlBehaviorFlags::scrollBarsEnabled |
ControlBehaviorFlags::imagesDownloadEnabled |
ControlBehaviorFlags::scriptEnabled |
ControlBehaviorFlags::javaEnabled |
ControlBehaviorFlags::flatScrollBars |
ControlBehaviorFlags::imagesDownloadEnabled |
ControlBehaviorFlags::behaviorsExecuteEnabled |
ControlBehaviorFlags::frameDownloadEnabled |
ControlBehaviorFlags::clientPullEnabled;

HandleCreated += gcnew EventHandler(this, &HtmlControl::SelfHandleCreated);
HandleDestroyed += gcnew EventHandler(this, &HtmlControl::SelfHandleDestroyed);
NavigateComplete += gcnew BrowserNavigateComplete2EventHandler(this, &HtmlControl::SelfNavigateComplete);
}
代码看着和C#的差不多,运行也没问题,可是就是不停的发生ProgressChange事件,却始终没有NavigateComplete2事件。
后来跟踪才发现,SHDocVw::IWebBrowser2^ ocx这个对象看是初始化正常,但是里面的Application和Container对象均为<undefine value>,
而C#里面这两个对象都初始化了,而且显然还是两个大对象。
这个错误,从语法上代码与C#的差别很小,但是结果去不正确,感觉也和托管DirectX一样,是一些实在的Bug。
三、NJF的Collapsible Splitter Control for .Net,翻写道C++/CLI后,也有问题。
this
->
splitterListView
->
AnimationDelay
=
20
;
this
->
splitterListView
->
AnimationStep
=
20
;
this
->
splitterListView
->
BorderStyle3D
=
System::Windows::Forms::Border3DStyle::Flat;
this
->
splitterListView
->
ControlToHide
=
nullptr;
this
->
splitterListView
->
Dock
=
System::Windows::Forms::DockStyle::Top;
this
->
splitterListView
->
ExpandParentForm
=
false
;
this
->
splitterListView
->
Location
=
System::Drawing::Point(
0
,
200
);
this
->
splitterListView
->
Name
=
"
SplitterListView
"
;
this
->
splitterListView
->
TabIndex
=
4
;
this
->
splitterListView
->
TabStop
=
false
;
this
->
splitterListView
->
UseAnimations
=
true
;
this
->
splitterListView
->
VisualStyle
=
Luo::CollapsibleSplitter::VisualStyles::XP;
默认情况下,this->splitterListView->ControlToHide = nullptr,但是在设计界面却提示不知道nullptr是啥。
而且在C#下能用的SandBar和SandDock在设计界面都不能显示,提示有问题,编译后运行可以。
看来想提前用用C++/CLI是不现实的了,起码在Beta1,它还不是一个完整可用的语言,
但是它的介绍确实很诱人,既可以用一些现代语言的先进特性,接口、事件、属性等,而且还能结合native C++的性能。
期待Beta2以及后续的。
希望大家多发表评论!!!!!
郁闷,系统分析师考试没过,51/35/35,连个省线也不够,唉。
还努力
