如何在C++/CX中创建单例类?
我有一个Windows 8的WinRT应用程序,它包含几个C++静态库和一个WinRT本机静态C++库.它没有链接,因为它抱怨与线程模型库相关的多重定义符号:
vccorlibd.lib(tmmta.obj) : error LNK2005: "int __abi___threading_model" (?__abi___threading_model@@3HA) already defined in vccorlibd.lib(tmdefault.obj)
fatal error LNK1169: one or more multiply defined symbols found
Run Code Online (Sandbox Code Playgroud)
请注意,它正在尝试使用默认的踩踏模型lib(tmdefault)链接MTA线程模型lib(tmmta).
我无法在项目属性中找到任何设置来更改此设置.我发现最接近的是CLR线程属性,但更改此设置无效.我不知道我的解决方案中的哪个子项目正在使用哪个线程模型.
如何以及在何处可以查看和更改线程模型设置?
谢谢!
我在这里错过了什么?我认为^是一个智能指针,我可以通过ref将字符串传递给函数.其他帽子物品怎么样?
// calling code
MyClass::GetString(_str1, _str2);
// both strings are nullptr at this point
/* static */
MyClass::GetStrings(String^ str1, String^ str2)
{
// Read from Local Settings
auto value = localSettings->Values->Lookup(kKey);
String^ temp = ref new String(value->ToString()->Data());
str1 = temp;
// same for str2
}
Run Code Online (Sandbox Code Playgroud) 我是WPF世界的开发人员,但我决定用C++完成所有Winrt开发.
让我感到困惑的一件事是using在头文件中使用(或不使用)语句(而不是键入完全限定的类型名称).
using在头文件中使用语句要容易得多.很多Microsoft Winrt示例都包含using标题中的语句,这些语句使代码清晰易读.但是,我一直在阅读John Petzolds新书预览中的c ++示例,并要求标题不受所有using陈述的影响.
我不了解专业人士和骗子,当我谷歌时,我得到了很多反对意见.
任何人都可以给我一个关于这个问题的明确解释,因为它与Winrt世界有关(我对其他环境中的c ++不感兴趣)
谢谢
为什么在此页面的OnNavigatedTo事件中调用时,Navigate方法不起作用?
这种行为对你来说是否可以重现?
任何想法如何避免这个问题?
void LockScreenPage::OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e)
{
//if user has no PIN protection
this->Frame->Navigate(Windows::UI::Xaml::Interop::TypeName(AnotherPage::typeid));
//else verify PIN
}
Run Code Online (Sandbox Code Playgroud) 我正在努力在WinRT项目中创建一个新容器.此容器的行为类似于ListView,因此我决定在其属性中使用类似的名称.
我为ItemsSource创建了一个DependencyProperty来模仿内置的ItemsControl(其他列表的抽象父).ItemsControl将ItemsSource定义为a Platform::Object^,所以我做了同样的事情.这很好用.
稍后,是时候创建要进入列表的项目,使用指定的ItemsTemplate实例填充它们,并设置它们的数据上下文.这意味着我需要实际将ItemsSource Platform::Object^转换为可迭代的东西.不幸的是,要将其转换为可迭代的东西,我需要在强制转换中指定模板化类型(例如IIterable<UIElement^>^或IIterable<Object^>^).在这个阶段,我并不特别关心它是什么类型的对象,因为我只是将它用作新列表项的DataContext,所以转换为没问题IIterable<Object^>^.不幸的是,safe_cast不允许我这样做,除非最初设置为ItemsSource的东西也被模板化为某个IIterable<Object^>^或某个孩子,例如IVectorView<Object^>^.
使用ListView等现有容器,您可以将ItemsSource设置为a Vector<MyCustomViewModel^>^而不先将其转换为a Vector<Object^>^并且它可以正常工作.那他们怎么做呢?他们没有使用safe_cast吗?我很确定使用不太安全的演员阵容会产生不利影响.还有其他想法吗?
TL; DR:
我有一些Platform::Object^参考,我知道指向其他参考的IIterable.是否有可能以IIterable<Platform::Object^>^某种方式将其强制转换,即使迭代最初是使用其他模板创建的(例如IIterable<MyCustomViewModel^>^)?
我正在学习DirectX,但我不太了解C++所以我决定使用SharpDX.但我在C++中坚持使用TypedEventHandler中的函数地址,但是我不知道如何在C#中编写它?有人可以帮忙吗?
ref class App sealed : public IFrameworkView
{
public:
virtual void Initialize(CoreApplicationView^ AppView)
{
AppView->Activated += ref new TypedEventHandler
<CoreApplicationView^, IActivatedEventArgs^>(this, &App::OnActivated);
}
virtual void SetWindow(CoreWindow^ Window) {}
virtual void Load(String^ EntryPoint) {}
virtual void Run() {}
virtual void Uninitialize() {}
void OnActivated(CoreApplicationView^ CoreAppView, IActivatedEventArgs^ Args)
{
CoreWindow^ Window = CoreWindow::GetForCurrentThread();
Window->Activate();
}
};
Run Code Online (Sandbox Code Playgroud)
到目前为止我的转换
internal class App : IFrameworkView
{
public void Initialize(CoreApplicationView AppView)
{
// Call OnActivated() when the Activated event is triggered
AppView.Activated += new TypedEventHandler<CoreApplicationView, …Run Code Online (Sandbox Code Playgroud) 以下代码是非法的(Visual Studio 2012 Windows Phone(创建Windows Phone direct3d应用程序))
a non-value type cannot have any public data members 'posX'
Run Code Online (Sandbox Code Playgroud)
头
ref class Placement sealed
{
public:
Placement(
float rotX,
float rotY,
float rotZ,
float posX,
float posY,
float posZ
);
float rotX, rotY, rotZ, posX, posY, posZ;
};
Run Code Online (Sandbox Code Playgroud)
CPP
Placement::Placement(
float rotX,
float rotY,
float rotZ,
float posX,
float posY,
float posZ
)
: posX( posX ),
posY( posY ),
posZ( posZ )
{
this->rotX = static_cast<float>(rotX);
this->rotY = static_cast<float>(rotY);
this->rotZ = …Run Code Online (Sandbox Code Playgroud) 如何将焦点放在Windows 10 UWP应用程序中的网格上?好像它没有焦点成员.
我可以使用我在此处学习的图像编写视频文件.它使用IMFSample和IMFSinkWriter.现在我想为它添加音频.假设有Audio.wma文件,我希望将该音频写入该视频文件中.
但是在这个样本中无法弄清楚如何做到这一点.像输入和输出类型设置,IMFSample音频缓冲区的创建等等.如果有人能告诉我如何使用接收器编写器将音频添加到视频文件,那将是一件好事.