我无法弄清楚这个异常以及如何解决这个问题
我正在为我的项目提供这个例外,但我无法弄清楚它是什么。它使用C ++/Winrt和XAML在Winui3项目中。这是一个项目中的一些代码,如果我隔离了例外。我还评论了一些以前解决该问题的尝试。
#include "pch.h"
#include "MainWindow.xaml.h"
#if __has_include("MainWindow.g.cpp")
#include "MainWindow.g.cpp"
#include <opencv2\opencv.hpp>
#include <shlobj.h>
#include <winrt/Microsoft.UI.Dispatching.h>
#include <winrt\Windows.UI.Core.h>
#include <winrt\Windows.System.h>
#include <winrt/Windows.Foundation.h>
#endif
using namespace winrt;
using namespace Microsoft::UI::Xaml;
using namespace Microsoft::UI::Xaml::Controls;
using namespace Windows::Storage;
using namespace cv;
using namespace std;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: ``http://aka.ms/winui-project-info``.
namespace winrt::OpenCVTestingSDK::implementation
{
MainWindow::MainWindow()
{
InitializeComponent();
}
int32_t MainWindow::MyProperty()
{
throw hresult_not_implemented();
}
void MainWindow::MyProperty(int32_t /* value */)
{
throw hresult_not_implemented();
}
void MainWindow::myButton_Click(IInspectable const&, RoutedEventArgs const&)
{
Mat picture_data = Mat(250, 100, CV_8UC3, Scalar(250, 0, 75));
TCHAR mypicturespath[MAX_PATH];
HRESULT result = SHGetFolderPath(NULL, CSIDL_MYPICTURES, NULL, SHGFP_TYPE_CURRENT, mypicturespath);
wstring imagePathW = mypicturespath;
string imagePath(imagePathW.begin(), imagePathW.end());
bool imageCreated = cv::imwrite(imagePath + "\\CrazyImageName.png", picture_data);
if (imageCreated) {
myButton().Content(box_value(L"True"));
}
else {
myButton().Content(box_value(L"False"));
}
//list<string> testListContents;
//testListContents.push_back("test1");
//testListContents.push_back("test2");
//testListContents.push_back("test3");
//testList().Items().Append(box_value(L"test1"));
//testList().Items().Append(box_value(L"test2"));
//testList().Items().Append(box_value(L"test2"));
//hstring message = L"Hello developers!";
//co_await winrt::resume_foreground(testList.Dispatcher());
//testList().Items().Append(box_value(message));
// Switch to the foreground thread associated with textblock.
//co_await winrt::resume_foreground(testList.Dispatcher());
//winrt::init_apartment();
//auto processOp{ DoWorkAsync() };
//winrt::Microsoft::UI::Xaml::Controls::ListView testList
testList().Items().Append(box_value(L"test1"));
}
//winrt::Windows::Foundation::IAsyncAction MainWindow::DoWorkAsync() {
//winrt::apartment_context ui_thread;
//co_await resume_background();
//co_await ui_thread;
//testList().Items().Append(box_value(L"test1"));
//}
void MainWindow::testList_SelectionChanged(Windows::Foundation::IInspectable const& sender, Microsoft::UI::Xaml::Controls::SelectionChangedEventArgs const& args)
{
}
}
XAML
<Window
x:Class="OpenCVTestingSDK.MainWindow"
xmlns="``http://schemas.microsoft.com/winfx/2006/xaml/presentation``"
xmlns:x="``http://schemas.microsoft.com/winfx/2006/xaml``"
xmlns:local="using:OpenCVTestingSDK"
xmlns:d="``http://schemas.microsoft.com/expression/blend/2008``"
xmlns:mc="``http://schemas.openxmlformats.org/markup-compatibility/2006``"
mc:Ignorable="d">
<Grid Grid.Column="1" Margin="40, 0, 40, 30">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
</StackPanel>
<Border Grid.RowSpan="2" Grid.Column="1" Margin="25, 0, 25, 0">
<StackPanel x:Name="subsystemPanel" Orientation="Vertical">
<TextBlock Style="{StaticResource Header}">Aircraft System</TextBlock>
<ListView x:Name="testList" SelectionMode="Single" SelectionChanged="testList_SelectionChanged" />
</StackPanel>
</Border>
</Grid>
</Window>
XAML.H
#pragma once
#include "MainWindow.g.h"
namespace winrt::OpenCVTestingSDK::implementation
{
struct MainWindow : MainWindowT<MainWindow>
{
MainWindow();
int32_t MyProperty();
void MyProperty(int32_t value);
void myButton_Click(Windows::Foundation::IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& args);
void testList_SelectionChanged(Windows::Foundation::IInspectable const& sender, Microsoft::UI::Xaml::Controls::SelectionChangedEventArgs const& args);
//winrt::Windows::Foundation::IAsyncAction DoWorkAsync();
};
}
namespace winrt::OpenCVTestingSDK::factory_implementation
{
struct MainWindow : MainWindowT<MainWindow, implementation::MainWindow>
{
};
}
例外:异常在OpenCvTestingsDk.exe中以0x00007FFCF3784F69抛出:Microsoft C ++例外:Winrt :: Hresult_Error在存储器位置0x0000000000000000000000B32B4FDE58。
结果值:0x802b000a
I am getting this exception for my project and I cannot figure out what it is. It is in winui3 project using c++/winrt and xaml. Here is some code from a project were I isolated the exception. I have also commented out some prior attempts at solving the problem.
#include "pch.h"
#include "MainWindow.xaml.h"
#if __has_include("MainWindow.g.cpp")
#include "MainWindow.g.cpp"
#include <opencv2\opencv.hpp>
#include <shlobj.h>
#include <winrt/Microsoft.UI.Dispatching.h>
#include <winrt\Windows.UI.Core.h>
#include <winrt\Windows.System.h>
#include <winrt/Windows.Foundation.h>
#endif
using namespace winrt;
using namespace Microsoft::UI::Xaml;
using namespace Microsoft::UI::Xaml::Controls;
using namespace Windows::Storage;
using namespace cv;
using namespace std;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: ``http://aka.ms/winui-project-info``.
namespace winrt::OpenCVTestingSDK::implementation
{
MainWindow::MainWindow()
{
InitializeComponent();
}
int32_t MainWindow::MyProperty()
{
throw hresult_not_implemented();
}
void MainWindow::MyProperty(int32_t /* value */)
{
throw hresult_not_implemented();
}
void MainWindow::myButton_Click(IInspectable const&, RoutedEventArgs const&)
{
Mat picture_data = Mat(250, 100, CV_8UC3, Scalar(250, 0, 75));
TCHAR mypicturespath[MAX_PATH];
HRESULT result = SHGetFolderPath(NULL, CSIDL_MYPICTURES, NULL, SHGFP_TYPE_CURRENT, mypicturespath);
wstring imagePathW = mypicturespath;
string imagePath(imagePathW.begin(), imagePathW.end());
bool imageCreated = cv::imwrite(imagePath + "\\CrazyImageName.png", picture_data);
if (imageCreated) {
myButton().Content(box_value(L"True"));
}
else {
myButton().Content(box_value(L"False"));
}
//list<string> testListContents;
//testListContents.push_back("test1");
//testListContents.push_back("test2");
//testListContents.push_back("test3");
//testList().Items().Append(box_value(L"test1"));
//testList().Items().Append(box_value(L"test2"));
//testList().Items().Append(box_value(L"test2"));
//hstring message = L"Hello developers!";
//co_await winrt::resume_foreground(testList.Dispatcher());
//testList().Items().Append(box_value(message));
// Switch to the foreground thread associated with textblock.
//co_await winrt::resume_foreground(testList.Dispatcher());
//winrt::init_apartment();
//auto processOp{ DoWorkAsync() };
//winrt::Microsoft::UI::Xaml::Controls::ListView testList
testList().Items().Append(box_value(L"test1"));
}
//winrt::Windows::Foundation::IAsyncAction MainWindow::DoWorkAsync() {
//winrt::apartment_context ui_thread;
//co_await resume_background();
//co_await ui_thread;
//testList().Items().Append(box_value(L"test1"));
//}
void MainWindow::testList_SelectionChanged(Windows::Foundation::IInspectable const& sender, Microsoft::UI::Xaml::Controls::SelectionChangedEventArgs const& args)
{
}
}
Xaml
<Window
x:Class="OpenCVTestingSDK.MainWindow"
xmlns="``http://schemas.microsoft.com/winfx/2006/xaml/presentation``"
xmlns:x="``http://schemas.microsoft.com/winfx/2006/xaml``"
xmlns:local="using:OpenCVTestingSDK"
xmlns:d="``http://schemas.microsoft.com/expression/blend/2008``"
xmlns:mc="``http://schemas.openxmlformats.org/markup-compatibility/2006``"
mc:Ignorable="d">
<Grid Grid.Column="1" Margin="40, 0, 40, 30">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
</StackPanel>
<Border Grid.RowSpan="2" Grid.Column="1" Margin="25, 0, 25, 0">
<StackPanel x:Name="subsystemPanel" Orientation="Vertical">
<TextBlock Style="{StaticResource Header}">Aircraft System</TextBlock>
<ListView x:Name="testList" SelectionMode="Single" SelectionChanged="testList_SelectionChanged" />
</StackPanel>
</Border>
</Grid>
</Window>
xaml.h
#pragma once
#include "MainWindow.g.h"
namespace winrt::OpenCVTestingSDK::implementation
{
struct MainWindow : MainWindowT<MainWindow>
{
MainWindow();
int32_t MyProperty();
void MyProperty(int32_t value);
void myButton_Click(Windows::Foundation::IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& args);
void testList_SelectionChanged(Windows::Foundation::IInspectable const& sender, Microsoft::UI::Xaml::Controls::SelectionChangedEventArgs const& args);
//winrt::Windows::Foundation::IAsyncAction DoWorkAsync();
};
}
namespace winrt::OpenCVTestingSDK::factory_implementation
{
struct MainWindow : MainWindowT<MainWindow, implementation::MainWindow>
{
};
}
the exception: Exception thrown at 0x00007FFCF3784F69 in OpenCVTestingSDK.exe: Microsoft C++ exception: winrt::hresult_error at memory location 0x000000B32B4FDE58.
result value: 0x802b000a
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论