mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Mar 2008
Posts: 93
B
BhaaL Offline OP
Babel fish
OP Offline
Babel fish
B
Joined: Mar 2008
Posts: 93
It seems my DLL is causing problems when mIRC is shutting down - until 7.14 simply closing mIRC was not a big deal, now with 7.15 it crashes.

The DLL internally creates a few HICONs that are cleaned on quit, aswell as a WndProc redirect to get certain stuff, other than the memory-mapped file to communicate with mIRC:
Code:
__declspec(dllexport) int __stdcall DllMain(HINSTANCE hInstance, unsigned int reason, LPVOID lpvReserved) {
  if (reason == DLL_PROCESS_ATTACH) {
    //TODO: check GetLastError and use mIRC{number} in case
    ghFileMap = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, 4096, L"mIRC");
    ghFileView = MapViewOfFile(ghFileMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
   
    //ChangeWindowMessageFilter(WM_COMMAND, MSGFLT_ADD);
  }
  else if (reason == DLL_PROCESS_DETACH) {
    if (ghFileView)
      UnmapViewOfFile(ghFileView);
    if (ghFileMap)
      CloseHandle(ghFileMap);

    SetWindowLong(mircHwnd, GWL_WNDPROC, (LONG)mircWndProc);

    for (std::vector<THUMBBUTTON>::iterator it = _buttons.begin(); it != _buttons.end(); it++)
      if (it->hIcon)
        DestroyIcon(it->hIcon);
  }
  return 1;
}

__declspec(dllexport) int __stdcall UnloadDll(int mTimeout) {
  if (mTimeout == 1)
    return 0;
  return 1;
}


That code hasn't changed since 7.14, and it also happens on a clean install.
I don't have any other DLLs loaded, so I'm not sure whether my DLL, my DLL_PROCESS_DETACH code or something else is at fault.

Any ideas on that?

Joined: Dec 2002
Posts: 5,412
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,412
The way mIRC closes down was changed in v7.15 to resolve this issue. A number of shutdown routines, including the unloading of DLLs, are now called immediately when mIRC detects that it is being closed. Previously there was a small delay for some shutdown routines that may have resulted in them not being called during a WM_ENDSESSION event. The order of shutdown calls is still the same as v6.35 and v7.14 however. Can you track down the cause of this issue to a specific call in your code?

Joined: Mar 2008
Posts: 93
B
BhaaL Offline OP
Babel fish
OP Offline
Babel fish
B
Joined: Mar 2008
Posts: 93
I did some tests in the meantime, it seems that my redirection of the mIRC WndProc causes the crash...

Code:
__declspec(dllexport) void __stdcall LoadDll(LOADINFO* info) {
  mircHwnd = info->mHwnd;
  info->mKeep = true;
  info->mUnicode = true;

  //redirect mIRC WndProc to ours. 
  //SetWindowsHookEx does not seem to catch the WM_COMMAND messages with THBN_CLICKED
  mircWndProc = (WNDPROC)SetWindowLong(mircHwnd, GWL_WNDPROC, (LONG)WndProc);
}


That part is needed because I add Thumbbar-Buttons on Win7 and need to get the WM_COMMAND message telling me when one of them was clicked.

It works when I call the unregister part by hand before mIRC quits, but it will crash the same way when using on EXIT.
The SetWindowLong call succeeds, but apparently something still wants to call my redirected WndProc after the DLL was unloaded.

Unregistering inside UnloadDll for mTimeout == 2 (shutdown) and returning 0 (do not unload) doesn't help, I guess thats due to the return value only being honored for mTimeout == 1 (10min timeout).

I guess I'll just have to live with it, I'm quitting mIRC anyways, so it shouldnt be a big deal if it crashes by then...unless it forgets my settings, which doesnt seem to be the case.

Joined: Dec 2002
Posts: 5,412
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,412
Thanks, I have changed the way DLLs are unloaded to cater for windows hooking, so this should be fixed in the next version.

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
NB: Unrelated to subject posting.
Quote:
I'm quitting mIRC anyways

I'm always sorry to hear that someone is quitting mIRC.
Guess I can hope that you won't really quit, but, maybe, take a break while doing other things.

Joined: Dec 2002
Posts: 344
D
Pan-dimensional mouse
Offline
Pan-dimensional mouse
D
Joined: Dec 2002
Posts: 344
Originally Posted By: RusselB
NB: Unrelated to subject posting.
Quote:
I'm quitting mIRC anyways

I'm always sorry to hear that someone is quitting mIRC.
Guess I can hope that you won't really quit, but, maybe, take a break while doing other things.


Haha, what he meant was that it's not a big deal that mIRC is crashing because it is only occurring when attempting to exit the program anyway.

Joined: Mar 2008
Posts: 93
B
BhaaL Offline OP
Babel fish
OP Offline
Babel fish
B
Joined: Mar 2008
Posts: 93
Duh, lets call it quits, I meant "I am closing the mIRC application" smile

Khaled: thanks for the quick response!

Joined: Mar 2008
Posts: 93
B
BhaaL Offline OP
Babel fish
OP Offline
Babel fish
B
Joined: Mar 2008
Posts: 93
Just reporting back, 7.16 beta fixed this. Thanks Khaled!

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Glad to hear it. Sorry about the misunderstanding earlier. It was, partially, due to a co-worker of mine having told me earlier that he was quitting, in spite of the fact that he's good at his job.

Joined: Mar 2008
Posts: 93
B
BhaaL Offline OP
Babel fish
OP Offline
Babel fish
B
Joined: Mar 2008
Posts: 93
Heh, guess I misunderstood aswell, thinking it was some kind of joke. Infact, mIRC (and probably Visual Studio) are the only things that keep me on Windows besides a bunch of games; I'd be on OSX or Linux otherwise wink


Link Copied to Clipboard