0

I'm attempting to use the C++ REST SDK. I'm using this example as my starting point.

What has worked so far is creating a new Windows CLR application in VS2015, adding a new cpp file, installing cpprestsdk thru NuGet, pasting the tutorial code into the cpp, turning off management for that cpp file, and compiling. Works as expected.

What also works is creating a new Windows CLR application and making a blank form by adding a cpp file with:

#include "MainForm.h"
using namespace System;
using namespace System::Windows::Forms;

[STAThread]
void main(array<String^>^ args) {
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);
    MyProject::MainForm form;
    Application::Run(%form);
}

And adding a new UI Windows Form element "Main Form" and keeping the code managed. This compiles fine and displays a blank window which I can close.

The issue lies when I add a new .cpp file into the above and paste the example into it as I've done before. I set this new .cpp file as unmanaged and rename the function something arbitrary. I'm not calling this function in any way. It compiles fine, however when I try to launch the program, I have AccessViolationExceptions.

I've done plenty of looking into running mixed managed code and I don't see what error I'm making.

EDIT: For now, I've circumvented the problem by avoiding Windows Forms and using Qt GUI instead.

Apneal
  • 483
  • 4
  • 6
  • 1
    It is a VS2015 specific problem without a known workaround. The Winforms project templates were removed in VS2012, with the somewhat inevitable side-effect that this isn't tested by Microsoft anymore. And almost instantly everybody getting their Main() function wrong because of a crummy web site that is the first Google hit. Not otherwise the issue, it is initialization order problem. You'll have to use VS2013 or less. Or call Microsoft Support to get this problem fixed, nobody has volunteered yet. – Hans Passant Oct 07 '16 at 21:53
  • The newest C++ Rest SDK is made specifically for VS2015. It seems silly that no one would use a windows form in a Visual Studio project? – Apneal Oct 07 '16 at 23:20
  • I've circumvented the problem by simply using Qt GUI – Apneal Oct 09 '16 at 20:13

0 Answers0