WebViewProcessControl initialization crash - c++

The Problem
I'm trying to use the "modern" web view API in my Win32 program, but when I initialize WebViewControlProcess, the program hangs for a couple of seconds, and then suddenly exits.
Minimal Example
// cl minimal.cpp /EHsc /std:c++17 /await windowsapp.lib
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Web.UI.Interop.h>
using namespace winrt;
using namespace Windows::Foundation;
using namespace Windows::Web::UI::Interop;
int main(void) {
winrt::init_apartment();
printf("Hello\n");
WebViewControlProcess webviews = WebViewControlProcess();
printf(" world!\n");
}
Expected Output
Hello
world!
Actual Output
Hello
Environment
I'm using Windows 10.0.17134 (1803).

Turns out WebViewProcessControl needs you to winrt::init_apartment(apartment_type::single_threaded);. I don't know why it needs a single-threaded apartment, but it works.

Related

Using DLLs wrapping Windows PackageManager in MinGW

In an attempt to incorporate a windows platform feature into an otherwise crossplatform application, I've made a one-function VC++ DLL in visual studio that uses Windows.Management.Deployment.PackageManager to get some details on all installed windows store apps.
The function works fine as a standalone application, and I can successfully build the DLL with MSVC that links properly with my MinGW main application (I can happily return primitive data from the dll, etc) - but any attempt to execute a function from the dll containing code relating to PackageManager crashes my application in runtime with the unhelpful code -529697949.
Here's some minimal code blocks that replicate:
main.cpp in the main application:
#include <QCoreApplication>
#include "mylib/WindowsAppsLib.h"
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
auto hi = (Helpers::sayHi());
qDebug() << (hi);
return a.exec();
}
dll header:
#pragma once
#define WINDOWSAPPSLIB_API __declspec(dllexport)
namespace Helpers
{
extern "C" WINDOWSAPPSLIB_API const char* sayHi();
}
dll source:
#include "stdafx.h"
#include <sddl.h>
#include <collection.h>
#include "WindowsAppsLib.h"
#include <windows.h>
#using <Windows.winmd>
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace std;
const char* Helpers::sayHi()
{
auto packageManager = ref new Windows::Management::Deployment::PackageManager();
auto packages = packageManager->FindPackages();
return "Hi!";
}
Without the two lines relating to packagemanger, the program runs fine and prints "Hi!". When included, the program crashes with code -529697949 as soon as sayHi() is called. The two lines in themselves have their dependencies available and don't cause exceptions.
Any clues on how I might proceed to investigate this? Nothing I've been able to get out of this system is getting me closer to identifying the problem. Is this the sensible way to access Windows.Management.Deployment.PackageManager from within a plain C++ MinGW application to begin with?

Eclipse CDT using std libraries in external console

I created C++ console project in Eclipse on Windows 7. I wanted it to run in external terminal, so I configured External Tool as described here: LINK. The following code runs fine and shows "Hello" on the console:
#include <iostream>
#include <string>
#include <vector>
#include <queue>
using namespace std;
void foo() {
//queue<char> x;
}
int main() {
//vector<int> a;
//string t;
cout << "Hello World!" << endl;
cin.get();
return 0;
}
However, when I uncomment one of the lines above, external console refuses to work (program exits instantly). Program compiles successfully and runs in the internal console.
The variables do not have to be used, declaration is sufficient to stop excution. I assume, there is something wrong with the External Tool, as the internal console works normally (maybe I should add some libraries to working directory).
Any ideas?

how to resolve Error 193:%1 is not a win32 application in dev c++?

unable to compile even the hello world programe
#include <iostream>
using namespace std;
int main(){
cout <<"hello world";
system("pause");
return 0;
}
Dev ++ clearly compiles to 16 bit architectures and they are deprecated and unsupported since exactly Windows Vista. So you clearly have to use a different compiler.

g++ error 0xc000007b when compiling program with iostream

I have a C++ program which I am compiling on a x64 machine running Windows 10 with g++ x86_64-win32-seh-rev2 v7.1.0, using the command g++ -g main.cpp. When I run my program, I get the error 0xc000007b. This is my code
#include <iostream>
using namespace std;
int main() {
cout << "Hello World";
return 0;
}
When I compile with this code
#include <stdio.h>
using namespace std;
int main() {
printf("Hello World");
return 0;
}
It works fine. When I run it in gdb, it runs fine.
I have seen other posts where there are dlls being used that do not support the architecture, but I don't think I am using any dlls in this application, unless they are being added by g++

My running c++ background

I've re installed my dev c++ and now I have problem that when I run the application of this simple code:
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
cout<<"hi mateen";
return 0;
}
it shows me this:
How can I delete this? It wasn't showing before always used to use
getche()
but even when I use
return 0;
the problem is still the same.
thanks
Turn off "Pause console programs after return" option in "Tools > Environment Options..."