Archive: PleaseWait plugin


PleaseWait plugin
  Hi.
I am creating new plug-in called PleaseWait which shows small modeless window (see attachment) with label and gif animation.

The goal is to create popup message for user that some action is being performed in background so he needs to wait.
It is suitable especially for long run tasks like downloading files, writing/reading, database operations and so on when nothing is happening/refreshing in GUI.

Plug-in runs in a separate thread, it is top most window [above all other windows - see attachment] so there is possible to show it over several pages even in .onGUIInit!

Showing window is simple, but I have problem with closing it.
This is my source:

  # Show dialog with gif file and caption, dimensions and label color

PleaseWait::ShowDialog /NOUNLOAD "D:\Projects\PleaseWait\loading.gif"
"Window title" 200 120 "Loading data..." "0x0000ff" 0

# This is important!
MessageBox MB_OK "After PleaseWait::ShowDialog"
And this is C++ code I use: [shortened]
__declspec(dllexport) void ShowDialog(HWND hwndParent, int string_size,

char *variables, stack_t **stacktop, extra_parameters *extra)
{
// get NSIS parameters
>.......
// Run main thread
unsigned uThreadID = 0;
HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, ThreadProc, &g_ThreadParam, 0, &uThreadID);
}

>// This is main Thread procedure
>unsigned __stdcall ThreadProc(void * param)
{
THREADPARAM * pThreadParam = (THREADPARAM *)param;

.......
RegisterClassEx(&wc) etc

// Create the Window
hwnd = CreateWindowEx(...)

// Show window and redraw it
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);

// Start animation
PlayAnimation(hwnd, pThreadParam->szFilename, ....);

// The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return0;
}
This is window procedure for window created above:
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)

{
switch(msg)
{
.......
caseWM_PAINT:
// Draw image
pe->OnPaint();
.......
default:
returnDefWindowProc(hwnd, msg, wParam, lParam);
}
return0;
}
I want anytime to close this window from NSIS script with PleaseWait::EndDialog which is:

__declspec(dllexport) void EndDialog(HWND hwndParent, int string_size,

char *variables, stack_t **stacktop, extra_parameters *extra)
{
g_bStopImmediately = true;
}
The problem is that immediately when I call PleaseWait::EndDialog I got Unhandled exception. I have breakpoint exactly on line EndDialog(...) also inside and this function is never called, the program crashes *before* entering into it.

I am not sure - what is wrong there? Why cannot I call EndDialog directly?
NSIS advanced to next line because I can see "After PleaseWait::ShowDialog" message box but calling EndDialog later causes the installer to crash.

ThreadProc is still running - separated thread but I need some way how to interrupt it from NSIS as I do not know how long the dialog will be shown.

Thanks for any ideas :)

I can't really say without having the full code. How about running the installer through the debugger? Rather than using a boolean flag you really aught to use an event (i.e. CreateEvent/SetEvent). Also as I said before (http://forums.winamp.com/showpost.ph...9&postcount=16), you should really avoid using CRT. However if you really must use CRT you should clearly state this on your plug-in page as your plug-in WILL crash the installer on machines without the necessary CRT.

Stu


Just a side note: If you want to use CRT functions, but do not want your DLL to depend on a separate CRT DLL, you can set "Ignore All Default Libraries" to Yes and then explicitly link against the VC 6.0 CRT import library. This way your DLL will use MSVCRT.DLL (note: no version number in the name!), which, in contrast to newer MSVCRT versions, is an integral part of the operating system (since Win2k, I think) and thus does not need a separate install. Many system components, like Explorer.exe and stuff, also use the "legacy" MSVCRT.DLL that ships with Windows. Only drawback: Some newer CRT functions, like the strcpy_s & friends, were not available in VC 6.0 yet...

(Side-side note: If you get linker errors regarding the "___CxxFrameHandler" symbol with VS2010 and the VC 6.0 CRT, then simply disable C++ exception handling. Of course, you better don't throw any exceptions in your code then - it still works but can have bad side effects)