simonkrauter / NiGui

Cross-platform desktop GUI toolkit written in Nim
MIT License
718 stars 50 forks source link

MSYS2/MinGW 64-bit: "attempt to set the process default activation context failed" #75

Closed exelotl closed 4 years ago

exelotl commented 4 years ago

This is a continuation of issue #29

I encountered this problem when running a simple Hello World on Windows 10 with msys2/mingw64. The program compiles, but fails to run, giving the following error message:

"An attempt to set the process default activation context failed because the process default activation context was already set."

Some info about my machine:

OS Name:  Microsoft Windows 10 Home
Version:  10.0.18362 Build 18362
System Manufacturer:  Dell Inc.
System Model:  XPS 13 9350
System Type:  x64-based PC
System SKU:  0704
Processor:  Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz, 2400 Mhz, 2 Core(s), 4 Logical Processor(s)

I walked a friend through the following process with fresh copies of MSYS2 and Nim, and the error occurred for him too:

Steps to reproduce

Install MSYS2 for x86_64 from https://www.msys2.org . Follow the instructions on the page to complete the installation

For this, we'll be using the mingw64 terminal.

Install git and gcc:

$ pacman -S git mingw-w64-x86_64-gcc 

Now you can open your msys2 home directory in Windows explorer:

$ explorer .

Download the latest Nim version for x86_64 from https://nim-lang.org/install_windows.html

Extract the contents to your MSYS2 home directory. So you should have a folder like this: "C:\msys32\home\exelotl\nim-1.0.2"

Edit your ~/.bashrc to add nimble and nim's bin folders to your path

export PATH=$PATH:/c/Users/exelotl/.nimble/bin
export PATH=$PATH:~/nim-1.0.2/bin

Apply the changes in your current terminal:

$ source ~/.bashrc

Install nigui

$ nimble install nigui

Create a minimal app:

$ touch hello.nim
import nigui

app.init()

var window = newWindow("Hello world")
window.width = 600.scaleToDpi
window.height = 400.scaleToDpi
window.show()

app.run()

Build and run:

$ nim c --app:gui hello.nim
$ ./hello.exe

You should see the following error:

nigui-error

Possible solutions

As previously mentioned, this issue occurs due to a hacky approach for enabling the visual styles module. The proper way to do this is to create an appropriate resource file and link it into your final executable. The Winim library uses this approach, and provides a very solid set of bindings for the Win32 API. I think we should strongly consider using it.

simonkrauter commented 4 years ago

@exelotl Thank you very much for your detailed explanation. I was able to reproduce the issue and fixed it by using the same way as Winim. Thanks for the hint! I want to keep NiGui as simple as possible, that's why it uses an own minimal Win32 binding and does not depend on other libraries.