It will behave itself. It will behave itself. It will behave itself........

No, you're not boring me. I'm intrigued as to why the problem still persists when it's now OK with my test version.

OK. To get some diagnostics, change
Code:
if (inst == NULL)
            MessageBox(NULL, "instnull", "instnull", MB_OK);
to
Code:
if (inst == NULL) {
     char num[20];
     ltoa((long)msg, num, 10);
     MessageBox(NULL, num, "instnull", MB_OK);
}
and see what numbers the message box says.