Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 20 Nov 2005
Offline Last Active Apr 28 2016 11:00 AM

Topics I've Started

Unable to debug CTRL_CLOSE_EVENT

05 March 2016 - 09:03 AM

Using SetConsoleCtrlHandler i set a handler that gets called when needed (CTRL_C_EVENT, CTRL_BREAK_EVENT, CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, CTRL_SHUTDOWN_EVENT) [either the RTL or the OS or whatever spawns a high priority worker thread to run it].


The handler signals the apps worker thread to to finish what it is doing and exit. Then it will wait till the main thread signals back that it is safe to exit the handler (which will terminate the process in case of CTRL_CLOSE_EVENT).


All of this works perfectly.


However, there is a long ignored slight problem in the main threads termination code (before signalling the CtrlHandler) which i opted to try to amend today ... and ran into problems.


VS2015 just does not let me debug any of it.


All i can see is the state at breakpoint (which is of limited use) - F11 etc will just instantly terminate the process (debug build of course). At breakpoint i can see that the CtrlHandler thread is waiting in my custom infinite spin-lock as it should ... so, who is killing my process? Can i stop it from doing that (it is not logoff/shutdown, so, what the hell)?


Currently trying to debug by just putting the breakpoint in different places and trying to guess by the visible state what is going on - needless to say, it would help immensely if i could just step through that code.


Any ideas?

VS2015 without internet explorer

17 February 2016 - 10:00 AM

Is it possible to use Visual Studio 2015 without having internet explorer (OS: Win7)?
It seems that registering needs "sign in" and that i suspect demands internet explorer - which i do not have. I can not find anything useful about this issue due to sheer amount of false positives for any search term i can come up with.
Error message for license / 'sing in':


We can't sign you in

Your browser is currently set to block JavaScript. You need to allow JavaScript to use this service.

To learn how to allow JavaScript or to find out whether your browser supports JavaScript, check the online help in your web browser.


My web browser is Firefox and has no Javascript blocking. I suspect that the error message is just a blatant lie in the usage of the term "web browser" as VS is just hardcoded to use some IE component directly. Either way - i can not find anything about it.

Are there any workarounds?
Suppose i get to register it somehow - will it keep working without internet explorer?

I'm sleepy and confused: __try, __except, /EHa, C2712 (unwinding)

02 October 2015 - 01:24 PM

I do not get it, why does code that needs unwinding inside __try block give me errors/warnings:

* warning C4509: nonstandard extension used: 'someFunctionScope' uses SEH and 'someVariable' has destructor

* error C2712: Cannot use __try in functions that require object unwinding

When /EHa (VC++ 2013) option is selected?


Isn't /EHa supposed to force the compiler to assume exceptions can occur anywhere (aka. asynchronous) and it hence must record all the destructors (ie. cannot optimize out the non-explicit ones like access violations etc).


What? I don't even ... what is my sleepy head missing? I could have sworn that i have done this before without problems.


PS. Since it is bound to come up: i really-really need to attempt (in my case, the chances are actually very good) surviving memory trashing / broken code (something that is normally undesirable), so SEH is a must as is unwinding.

"defer": is this silly / broken?

09 December 2014 - 10:10 AM

The geek in me smiles, yet i can't get rid of the feeling that i am doing something eerily wonky.

// clean is just a struct that plonks out all the unwanted default crap c++ attaches - not terribly important here.
struct Defer : Clean {
    template<typename FN> struct Obj : Clean {
        Obj(FN fn) : fn(fn) {}
        ~Obj() { fn(); }
        FN fn;
    template<typename FN> Obj<FN> operator=(FN fn) { return Obj<FN>(fn); }
#define defer auto JOIN(_defer, __COUNTER__) = Defer() = [&]
Now i can use "defer" (iirc, Go language has it) in C++:
__declspec(noinline) void test() {
    int i = 41;
    defer {
        // some code to defer
        msg(L"defer %d", i); // some typical logging function - note: "i" comes from outer scope.

    // perhaps some other code (with multiple exit points etc) here

    msg(L"----- %d", i++);
VS2013 optimizes all of the overhead completely out:
__declspec(noinline) void init() {
00FA1060  push        ecx  
00FA1061  push        29h  
00FA1063  push        0FB1514h  
00FA1068  mov         dword ptr [esp+8],2Ah  
00FA1070  call        msg (0FA1000h)  
00FA1075  push        dword ptr [esp+8]  
00FA1079  push        0FB1524h  
00FA107E  call        msg (0FA1000h)  
00FA1083  add         esp,14h  
00FA1086  ret  
Giving the expected output:
----- 41
defer 42
What could go wrong? Am i nuts thinking this is occasionally useful? Why have i not seen it used anywhere, i wonder :/. Looks solid to me.

Windows 7 - icons shown with wrong size (folder thumbnail alternative).

07 December 2014 - 04:56 PM

Since Windows 7 folder thumbnail feature was degraded to being completely unusable from XP days - i though of an alternative:

Windows Registry Editor Version 5.00


@="cmd.exe /d /c \"c:\\somewhere\\iconify.bat \"%1\"\""

Where "someDefaultJpgHandler" is from "HKEY_CLASSES_ROOT\.jpg" default value.

@echo off

:: imagemagick
convert "%~n1%~x1" -resize x128 -gravity center -crop 128x128+0+0 -alpha remove -colors 256 "folder.ico"

attrib -s -h desktop.ini
del desctop.ini

  echo [ViewState]
  echo Mode=
  echo Vid=
  echo FolderType=Generic
  echo Logo=
  echo [.ShellClassInfo]
  echo IconResource=.\folder.ico,0
) > desktop.ini

attrib -a +s +h desktop.ini
Works nicely - i can pick "Iconify" on any picture file and it will be shown as the folder icon.

... except - Windows ignores the icon size and persist on showing as 48x48. Even with "View -> extra large icons" option (48x48 seems to be the icon size my desktop uses).
Thought that perhaps it would help if i give multiple resolutions - nope.
convert "%~n1%~x1" -bordercolor white -border 0 ^
  ^( -clone 0 -resize x16 -gravity center -crop 16x16+0+0 ^) ^
  ^( -clone 0 -resize x32 -gravity center -crop 32x32+0+0 ^) ^
  ^( -clone 0 -resize x48 -gravity center -crop 48x48+0+0 ^) ^
  ^( -clone 0 -resize x64 -gravity center -crop 64x64+0+0 ^) ^
  ^( -clone 0 -resize x128 -gravity center -crop 128x128+0+0 ^) ^
  -delete 0 -alpha remove -colors 256 "folder.ico"
PS. afaik 128x128 are the dimensions for "Large icons" option - which i would prefer.
PS2. there is no problem when i use some random windows stock icon.

I'm stuck and Google gives me nothing. Help! WTF is going on?