Windows phone 8 file storage C++ - xaml

i'm beginning in C++ Windows phone.
Currently i'm doing a windows phone app with many pages and i don't know how to save and load my data. I tried global variables and SQLite database but i always meet errors so i tried " Windows::Storage::ApplicationDataContainer " but i can't pass the variable between all pages.
is there someone who have a template that use ApplicationDataContainer or someone who could explain me how to use it?
here is my code
MainPage.xaml.cpp
#include "pch.h"
#include "MainPage.xaml.h"
#include "menu.xaml.h"
using namespace japanEasy;
using namespace Windows::Storage;
using namespace Platform;
using namespace std;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Interop;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Popups;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings;
// Pour en savoir plus sur le modèle d'élément Page vierge, consultez la page http://go.microsoft.com/fwlink/?LinkId=234238
MainPage::MainPage()
{
InitializeComponent();
}
/// <summary>
/// Invoqué lorsque cette page est sur le point d'être affichée dans un frame.
/// </summary>
/// <param name="e">Données d'événement décrivant la manière dont l'utilisateur a accédé à cette page. La propriété Parameter
/// est généralement utilisée pour configurer la page.</param>
void MainPage::OnNavigatedTo(NavigationEventArgs^ e)
{
(void) e; // Paramètre non utilisé
}
void japanEasy::MainPage::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
if (this->theName->Text == "" || this->theName->Text == nullptr)
{
auto msgDlg = ref new MessageDialog("Vous devez d'abord saisir votre nom", "Attention");
msgDlg->ShowAsync();
}
else
{
auto values = localSettings->Values;
values->Insert("playerName", dynamic_cast<PropertyValue^>(PropertyValue::CreateString(this->theName->Text)));
String^ value = safe_cast<String^>(localSettings->Values->Lookup("playerName"));
this->Frame->Navigate(TypeName(japanEasy::menu::typeid), localSettings);
}
}
menu.xaml.cpp
#include "pch.h"
#include "menu.xaml.h"
#include "learn.xaml.h"
#include "level.xaml.h"
#include "records.xaml.h"
#include "easyGame.xaml.h"
using namespace japanEasy;
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Interop;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
using namespace Windows::Storage;
ApplicationDataContainer^ localSettings ;
menu::menu()
{
InitializeComponent();
this->myName->Text = safe_cast<String^>(localSettings->Values->Lookup("playerName"));
}
/// <summary>
/// Invoqué lorsque cette page est sur le point d'être affichée dans un frame.
/// </summary>
/// <param name="e">Données d'événement décrivant la manière dont l'utilisateur a accédé à cette page.
/// Ce paramètre est généralement utilisé pour configurer la page.</param>
void menu::OnNavigatedTo(NavigationEventArgs^ e)
{
(void) e; // Paramètre non utilisé
auto localSettings = (ApplicationDataContainer^)e->Parameter;
::Windows::UI::Xaml::Controls::Page::OnNavigatedTo(e);
}
void japanEasy::menu::goToLearn_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
this->Frame->Navigate(TypeName(japanEasy::learn::typeid));
}
void japanEasy::menu::goTo_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
}
void japanEasy::menu::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
this->Frame->Navigate(TypeName(japanEasy::level::typeid));
}
void japanEasy::menu::goToRecords_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
this->Frame->Navigate(TypeName(japanEasy::records::typeid));
}
when i launch my application on my windows phone i seize my username and i click on my button to show the "menu.xaml" page, and i'm supposed to have get the name in this page thanks to the "localSettings" i've passed on my MainPage.xaml.cpp with the naavigate function.

To pass data from a page to another i used "Page::OnNavigatedTo" method.
So on my menuPage I created a global variable and i added a menu::OnNavigatedTo()
where i get data from previous pages.
here is my menuPage.xaml.cpp
#include "pch.h"
#include "menu.xaml.h"
#include "learn.xaml.h"
#include "level.xaml.h"
#include "records.xaml.h"
#include "easyGame.xaml.h"
#include "mediumGame.xaml.h"
#include "hardGame.xaml.h"
#include "Constants.h"
using namespace japanEasy;
using namespace Platform;
using namespace std;
using namespace Windows::UI::Popups;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Interop;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
using namespace Windows::Phone::UI::Input;
using namespace Windows::Storage;
ApplicationDataContainer^ menuLocalSetting;
String^ lv = "Facile";
// Create a composite setting
ApplicationDataCompositeValue^ recordList = ref new ApplicationDataCompositeValue();
menu::menu()
{
InitializeComponent();
HardwareButtons::BackPressed += ref new EventHandler<BackPressedEventArgs ^>(this, &menu::HardwareButtons_BackPressed);
}
/// <summary>
/// Invoqué lorsque cette page est sur le point d'être affichée dans un frame.
/// </summary>
/// <param name="e">Données d'événement décrivant la manière dont l'utilisateur a accédé à cette page.
/// Ce paramètre est généralement utilisé pour configurer la page.</param>
void menu::OnNavigatedTo(NavigationEventArgs^ e)
{
//(void) e; // Paramètre non utilisé
if (e->Parameter) {
menuLocalSetting = safe_cast<ApplicationDataContainer^>(e->Parameter);
this->myName->Text = safe_cast<String^>(menuLocalSetting->Values->Lookup("userName"));
auto values = menuLocalSetting->Values;
if (safe_cast<String^>(menuLocalSetting->Values->Lookup("level"))) {
String^ value = safe_cast<String^>(menuLocalSetting->Values->Lookup("level"));
lv = value;
}
else {
auto vvv = menuLocalSetting->Values;
vvv->Remove("level");
vvv->Insert("level", dynamic_cast<PropertyValue^>(PropertyValue::CreateString("Facile")));
String^ test3 = safe_cast<String^>(menuLocalSetting->Values->Lookup("level"));
}
}
}
void japanEasy::menu::goToLearn_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
this->Frame->Navigate(TypeName(japanEasy::learn::typeid), menuLocalSetting);
}
void japanEasy::menu::goTo_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
if(lv == "Facile")
this->Frame->Navigate(TypeName(japanEasy::easyGame::typeid), menuLocalSetting);
else if(lv =="Moyen")
this->Frame->Navigate(TypeName(japanEasy::mediumGame::typeid), menuLocalSetting);
else if(lv == "Difficile")
this->Frame->Navigate(TypeName(japanEasy::hardGame::typeid), menuLocalSetting);
}
void japanEasy::menu::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
this->Frame->Navigate(TypeName(japanEasy::level::typeid), menuLocalSetting);
}
void japanEasy::menu::goToRecords_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
this->Frame->Navigate(TypeName(japanEasy::records::typeid), menuLocalSetting);
}
//on ajoute une fonction qui gère la back navigation
void menu::HardwareButtons_BackPressed(Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ e)
{
if (this->Frame->CanGoBack)
{
//On ferme l'application si l'utilisateur clique sur le bouton back du menu
Application::Current->Exit();
e->Handled = true;
}
}

Related

How to access form elements from another classes?

This my first time trying to create windows application using vs clr and i'm trying to implement it on my existing cpp project which i almost finished but the main problem that i'm facing is the i can't access the functions of myForm.h (buttons , text box , etc..) from my main source.cpp , any help would be appreciated and thanks
MyForm.h
#pragma once
namespace Project2 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::RichTextBox^ richTextBox1;
protected:
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(104, 177);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 0;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
//
// richTextBox1
//
this->richTextBox1->Location = System::Drawing::Point(47, 36);
this->richTextBox1->Name = L"richTextBox1";
this->richTextBox1->Size = System::Drawing::Size(208, 135);
this->richTextBox1->TabIndex = 1;
this->richTextBox1->Text = L"";
this->richTextBox1->TextChanged += gcnew System::EventHandler(this, &MyForm::richTextBox1_TextChanged);
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(282, 253);
this->Controls->Add(this->richTextBox1);
this->Controls->Add(this->button1);
this->Name = L"MyForm";
this->Text = L"MyForm";
this->ResumeLayout(false);
}
#pragma endregion
public: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {};
public: System::Void richTextBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {}
};
}
Main.c
#include <iostream>
#include <fstream>
#include <sstream>
#include <locale>
#include <string>
#include<vector>
#include <time.h>
#include "MyForm.h"
using namespace std;
using namespace System;
[STAThread]
int main()
{
System::Windows::Forms::Application::Run(gcnew Project2::MyForm());
MyForm F; \\ can't create an object of MyForm class
F.richtextbox->AppendText("Hello world"); \\ here is the confusing part
System::Windows::Forms::Application::Run(gcnew Project2::MyForm());
return 0;
}

NHibernate.HibernateException: No session bound to the current context

i'm working in a new project and i'm trying to implement nhibernate with ninject in asp.net mvc. I'm having the error:
NHibernate.HibernateException: No session bound to the current context
Below is the code i'm using:
using FluentNHibernate.Automapping;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using FluentNHibernate.Conventions.Helpers;
using NHibernate;
using NHibernate.Context;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace TestNhibernateSessions
{
public class SessionFactory : IHttpModule
{
private static readonly ISessionFactory _SessionFactory;
static SessionFactory()
{
_SessionFactory = CreateSessionFactory();
}
public void Init(HttpApplication context)
{
context.BeginRequest += BeginRequest;
context.EndRequest += EndRequest;
}
public void Dispose()
{
}
public static ISession GetCurrentSession()
{
return _SessionFactory.GetCurrentSession();
}
private static void BeginRequest(object sender, EventArgs e)
{
ISession session = _SessionFactory.OpenSession();
session.BeginTransaction();
CurrentSessionContext.Bind(session);
}
private static void EndRequest(object sender, EventArgs e)
{
ISession session = CurrentSessionContext.Unbind(_SessionFactory);
if (session == null) return;
try
{
session.Transaction.Commit();
}
catch (Exception)
{
session.Transaction.Rollback();
}
finally
{
session.Close();
session.Dispose();
}
}
private static ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("DefaultConnection")))
.Mappings(m => m.AutoMappings.Add(CreateMappings()))
.CurrentSessionContext<WebSessionContext>()
.BuildSessionFactory();
}
private static AutoPersistenceModel CreateMappings()
{
return AutoMap
.Assembly(System.Reflection.Assembly.GetCallingAssembly())
.Where(t => t.Namespace != null && t.Namespace.EndsWith("Domain"))
.Conventions.Setup(c => c.Add(DefaultCascade.SaveUpdate()));
}
}
}
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(TestNhibernateSessions.App_Start.NinjectWebCommon), "Start")]
[assembly: WebActivatorEx.ApplicationShutdownMethodAttribute(typeof(TestNhibernateSessions.App_Start.NinjectWebCommon), "Stop")]
namespace TestNhibernateSessions.App_Start
{
using System;
using System.Web;
using Microsoft.Web.Infrastructure.DynamicModuleHelper;
using Ninject;
using Ninject.Web.Common;
using TestNhibernateSessions.Repository;
using TestNhibernateSessions.Service;
using NHibernate;
public static class NinjectWebCommon
{
private static readonly Bootstrapper bootstrapper = new Bootstrapper();
/// <summary>
/// Starts the application
/// </summary>
public static void Start()
{
DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
bootstrapper.Initialize(CreateKernel);
}
/// <summary>
/// Stops the application.
/// </summary>
public static void Stop()
{
bootstrapper.ShutDown();
}
/// <summary>
/// Creates the kernel that will manage your application.
/// </summary>
/// <returns>The created kernel.</returns>
private static IKernel CreateKernel()
{
var kernel = new StandardKernel();
try
{
kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
RegisterServices(kernel);
return kernel;
}
catch
{
kernel.Dispose();
throw;
}
}
/// <summary>
/// Load your modules or register your services here!
/// </summary>
/// <param name="kernel">The kernel.</param>
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<IProductRepository>().To<ProductRepository>();
kernel.Bind<IProductService>().To<ProductService>();
}
}
}
Since you're using Ninject, my recommendation is to use it to inject the session factory rather than an IHttpModule. To do so, create Ninject Provider classes as shown below. Note that this requires transaction management in code, I dislike the idea of blindly holding a transaction open during a request.
public class SessionFactoryProvider : Provider<ISessionFactory>
{
protected override ISessionFactory CreateInstance(IContext context)
{
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("DefaultConnection")))
.Mappings(m => m.AutoMappings.Add(CreateMappings()))
.CurrentSessionContext<WebSessionContext>()
.BuildSessionFactory();
}
}
public class SessionProvider : Provider<ISession>
{
protected override ISession CreateInstance(IContext context)
{
var sessionFactory = context.Kernel.Get<ISessionFactory>();
var session = sessionFactory.OpenSession();
session.FlushMode = FlushMode.Commit;
return session;
}
}
Then in NinjectWebCommon:
private static void RegisterServices(IKernel kernel)
{
// session factory instances are singletons
kernel.Bind<ISessionFactory>().ToProvider<SessionFactoryProvider>().InSingletonScope();
// session-per-request
kernel.Bind<ISession>().ToProvider<SessionProvider>().InRequestScope();
}

Qt inherit QSpinBox and QPushButton

I would like create my CustomQSpinBox .
This CustomQSpinBox must inherit of QPushButton and QSpinBox
but when I compile this code :
#include <QSpinBox>
#include <QPushButton>
class CustomQSpinBox : public QSpinBox, public QPushButton
{
Q_OBJECT
public:
CustomQSpinBox (QWidget *parent = 0);
~CustomQSpinBox ();
void initMinMax(int min, int max);
void init();
signals:
void needNumpad();
public slots:
void clicked();
};
I get an error :
erreur : C2594: 'static_cast'ÿ: conversions ambigu‰s de 'QObject *' en
'CustomQSpinBox *'
How I must do my inheritance ?
Yes, when the numPad is closed, the value is set in the QSpinBox. The problem is so to open the numPad when I click on the QSpinBox.
For the moment I manage with this code :
#include <QSpinBox>
#include <QPushButton>
#include <QMoveEvent>
#include <QResizeEvent>
class CustomQSpinBox: public QSpinBox
{
Q_OBJECT
public:
CustomQSpinBox(QWidget *parent = 0);
~CustomQSpinBox();
void resizeEvent(QResizeEvent *event);
void moveEvent(QMoveEvent * event);
signals:
void needNumpad();
public slots:
void clicked();
private:
QPushButton * button;
};

Form.cpp(16): error C2061: syntax error : identifier 'Form1'

Im trying to start working with Windows Forms... And I tryed to make programm by lesson... But it doesnt work and I dont understand why. If someone can help me it would be great.
My error:
1>ClCompile:
1> stdafx.cpp
1> AssemblyInfo.cpp
1> Form.cpp
1>Form.cpp(16): error C2872: 'Form1' : ambiguous symbol
1> could be 'Form1'
1> or 'c:\users\mizuru\documents\visual studio 2010\projects\form\form\Form1.h(15) : Form1::Form1'
1>Form.cpp(16): error C2061: syntax error : identifier 'Form1'
1> Generating Code...
1>
1>Build FAILED.
Form.cpp
// Form.cpp : main project file.
#include "stdafx.h"
#include "Form1.h"
using namespace Form1;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}
Form1.h
#pragma once
namespace Form1 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
protected:
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::TextBox^ textBox1;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->label1 = (gcnew System::Windows::Forms::Label());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(113, 181);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 0;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(104, 13);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(35, 13);
this->label1->TabIndex = 1;
this->label1->Text = L"label1";
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(113, 110);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(100, 20);
this->textBox1->TabIndex = 2;
this->textBox1->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 262);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->label1);
this->Controls->Add(this->button1);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {
label1->Text="";
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
label1->Text=textBox1->Text;
}
};
}
The problem at hand is that your namespace and your form class both share the name Form1. You have to disambiguate the symbol by specifying that it's the class within the namespace.
Application::Run(gcnew ::Form1::Form1());

UnauthorizedAccessException in Webcam app

I'm trying to make a simple webcam app:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Media.MediaProperties;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;
namespace App1
{
public sealed partial class MainPage : Page
{
private Windows.Media.Capture.MediaCapture m_mediaCaptureMgr;
private Windows.Storage.StorageFile m_photoStorageFile;
private readonly String PHOTO_FILE_NAME = "photo.jpg";
public MainPage()
{
this.InitializeComponent();
}
internal async void initializeCamera()
{
m_mediaCaptureMgr = new Windows.Media.Capture.MediaCapture();
await m_mediaCaptureMgr.InitializeAsync();
statusBox.Text = "initialized";
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
internal async void takePicture(object sender, RoutedEventArgs e)
{
m_photoStorageFile = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync(PHOTO_FILE_NAME, Windows.Storage.CreationCollisionOption.GenerateUniqueName);
ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
await m_mediaCaptureMgr.CapturePhotoToStorageFileAsync(imageProperties, m_photoStorageFile);
}
private void initializeButton(object sender, RoutedEventArgs e)
{
initializeCamera();
}
}
}
However, when I click on the initializeButton, I got an exception:
UnauthorizedAccessException (Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)))
What could be the problem here?
EDIT: I found the bug. Basically, if the webcam is already initialized, trying to initialize it again will trigger an exception. So I had to put in a flag, and some try/catch
Have you set the capabilities for Microphone and Webcam in the manifest file?
Seect the Microphone and Webcam capability in Package.Appmnifest file