Windows: Compiling as a console-less windows application

110 views
Skip to first unread message

wtfux

unread,
Jun 20, 2012, 10:46:25 AM6/20/12
to nod...@googlegroups.com
I wrote a GUI for my application as a c++ addon. Now I want node to start without the console. To do this I changed the subsystem from console to windows and replaced the following in node_main.cc (latest stable):

int wmain(int argc, wchar_t *wargv[]) {
with
int wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) {
  int argc = __argc;
  wchar_t **wargv = __wargv;

It works, Node starts without console and you can run your script. Only you can't use console output unless you pipe it to some file or something else.
However after doing this my addon broke. Node will still load my addon and I can spawn a windows form and do stuff. However if I use uv or v8 stuff it'll crash because of an access violation at `mod->register_func(target);` in node.cc. Even a single `HandleScope scope` in the init function is enough to cause a crash.
The same addon works when I run it with node with console. Both node executables are built from the same source, just with/without the patch above.

I wonder how the access violation is related to changing node to a windows application? Any windows developer here who has a clue? Built-in stuff like a HTTP Server works without a crash. Loading modules works too, they just mustn't contain any v8/uv stuff. I can't figure this out...

Bert Belder

unread,
Jun 20, 2012, 10:54:18 AM6/20/12
to nodejs
Are you sure you are not creating an additional thread for your addon?

Bert Belder

unread,
Jun 20, 2012, 10:57:41 AM6/20/12
to nod...@googlegroups.com

You should also make sure that your addon links to the same version of the CRT as node. Node statically links the crt with /MT.

wtfux

unread,
Jun 20, 2012, 5:13:58 PM6/20/12
to nod...@googlegroups.com
Bert Belder:
Are you sure you are not creating an additional thread for your addon? 

Yes, no threading. Even the hello world example causes an access violation: http://nodejs.org/docs/latest/api/addons.html#addons_hello_world
When I however empty the init function it'll run. I can put any code there, just nothing from libuv and v8.
 
You should also make sure that your addon links to the same version of the CRT as node. Node statically links the crt with /MT. 
 
I had /MD and changed to /MT. No change. My addon works with an unmodified node version, even with /MD. The problem must have something to do with my wWinMain patch. When I change back to `wmain` and recompile, it works. But I need to get rid of the console, hiding is not an option since the console will still appear for some milliseconds.
Reply all
Reply to author
Forward
0 new messages