Using DLLs wrapping Windows PackageManager in MinGW - c++

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?

Related

WebViewProcessControl initialization crash

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.

What's wrong with std::strings

Hi I am new to C++ and Code::Block
I am trying to make a simple code to test it, using strings.
when I compile the code there is no problem, but when I try to debug it, Code::Block gives me the following warning:
Cannot open file:
File:../../../../../src/gcc-4.9.2/libgcc/unwind-sjlj.c
Info: "Multiple information windows with the same message have been
supressed."
Image of the error FYI:
Part of the code that gives me an error.
inside main function
#include <iostream>
#include <string>
int main ()
{
std::mystring("What's wrong with strings");
return 0;
}
I realise that this error only occurs when I try to debug a string or a file containing a string.
Any help would be appreciated.
some other information that might help:
Code::Block 16.01
Compiler MinGW gcc4.9.2
Windows 7 Professional 32 bits SP1
First of all, to use strings you must include the file header string. And the name of the type string is..std::string, not std::mystring.
#include <string>
int main(int argc, char** argv)
{
std::string mystring("Nothing's wrong with strings");
return 0;
}
#include <iostream>
using namespace std;
int main ()
{
string mystring = "Whats wrong with my string";
return 0;
}
If you write it in the following way, it should work.
It's safer to define strings like I showed it. It will be also easier for you if you add using namespace std in the beginning of every program if you are new to C++.

Simple netbeans C++ project doesn't compile

I installed Netbeans and as C++ compiler I installed cygwin. I made a simple project to test out my installation, this is the code:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
cout << "test";
return 0;
}
This is the error message that it gives: http://pastebin.com/jRRh7MPi
I hope you guys can help me out.
You need to either explicitly link to C++ standard library, or compile using g++ instead of gcc.

MinGW portability

I'm completely new to C++, but I have created a minor program, looking to port the program to other computers, but when I "install" the program I get this error...-static-libgcc -static-libstdc++ missing, is there a file I should be including in the program itself, or is this a library I have to install on each computer? The computers that I expect to run the program will be windows xp. Source code of the file is as follows:
#include <stdlib.h>
#include <windows.h>
#include <direct.h>
#include <string.h>
#include <string>
#include <iostream>
using namespace std;
int main(int argc, const char *argv[])
{
_chdir("C:\\Program Files\\NCHSoftware\\Talk\\");
string number = "start talk.exe -dial " + std::string(argv[1]+4);
system(number.c_str());
exit;
return 0;
}
They are shared lib's that would need to be on the host computer.
To learn how to compile a static version;
See here: http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
Read the "-static-libgcc" & "-static-libstdc++" sections.

What kind of VS 2010 C++ Project I must choose to compile a simple Borland C++ 5 Console app?

I have a simple Win32 console (no vcl) app written in Borland C++ 5, now I want compile the same application in VS 2010. but I'm new using this IDE and I don't know how run the code in VS. I tried choosing Win32 Console Application. but even i very simple app like this
#include <iostream.h>
#pragma hdrstop
#pragma argsused
int main(int argc, char* argv[])
{
cout << "Hello" << endl;
getchar();
return 0;
}
does not compile in VS.
So, What kind of VS 2010 C++ Project I must choose to compile a simple Borland C++ 5 Console app? or I need modify my app in order to use VS C++?
<iostream.h> is deprecated, and VS10 does not support it, use <iostream> instead, and you'll also need std::cout, std::endl , etc.. i.e.
#include <iostream>
#pragma hdrstop
// #pragma argsused // I don't believe this is valid in VS10
int main(int argc, char* argv[])
{
std::cout << "Hello" << std::endl;
std::cin.get();
return 0;
}
Alternatively, if you don't want to prefix your library uses with std::, you can put a using declaration at the top, after the headers:
using namespace std;