|
thank so much...very kind and clear!
|
|
|
|
|
I have a dll that implements a debug console (i.e. an application can send messages to it during run time) made of a window with a textbox on it. It's set up so that the first call to ConInit creates the window and displays it, but subsequent calls to ConInit simply return TRUE. In this way, the same console is used by several apps. My problem is that if I run 2 or more applications, when I shut down the first one, it kills my debug console. How can I lock the window so it's not destroyed until the last reference to it is gone (and yes, I'm using reference counting, so that's not it). Anyway, here's some of the pertininet code:
HINSTANCE g_hInstance= NULL;
HMENU g_hMenu= NULL;
HWND g_hOwner= NULL;
#pragma data_seg(".SHARED")
HWND g_hWnd= NULL;
HWND g_hTextBox= NULL;
WNDPROC g_hOldTextBoxProc= NULL;
COLORREF g_clrTextColor= RGB(192,192,192);
COLORREF g_clrBackColor= 0;
HBRUSH g_hBrush= NULL;
HFONT g_hFont= NULL;
BOOL g_bShowTime= FALSE;
BOOL g_bShowSourceHwnd= FALSE;
BOOL g_bShowSourceCaption= FALSE;
UINT g_uRefCount= 0;
#pragma data_seg()
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
switch(dwReason)
{
case DLL_PROCESS_ATTACH:
g_hInstance=hInstance;
g_uRefCount++;
break;
case DLL_PROCESS_DETACH:
g_uRefCount--;
if (g_uRefCount==0)
{
DeleteObject(g_hBrush);
DeleteObject(g_hFont);
SetWindowLong(g_hTextBox, GWL_WNDPROC, (LONG)g_hOldTextBoxProc);
DestroyWindow(g_hWnd);
}
break;
}
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
RECT rect;
LOGFONT lf;
switch(uMsg)
{
case WM_CREATE:
g_hTextBox=CreateWindowEx(WS_EX_CLIENTEDGE,
"EDIT",
NULL,
WS_VISIBLE|WS_CHILD|WS_BORDER|WS_HSCROLL|WS_VSCROLL|ES_MULTILINE|ES_NOHIDESEL,
1,
1,
1,
1,
hWnd,
NULL,
g_hInstance,
NULL);
if (!g_hTextBox)
return -1;
lf.lfCharSet=ANSI_CHARSET;
lf.lfClipPrecision=CLIP_DEFAULT_PRECIS;
lf.lfEscapement=0;
strcpy(lf.lfFaceName, "Courier");
lf.lfHeight=-10;
lf.lfItalic=0;
lf.lfOrientation=0;
lf.lfOutPrecision=OUT_DEFAULT_PRECIS;
lf.lfPitchAndFamily=FF_ROMAN|DEFAULT_PITCH;
lf.lfQuality=DRAFT_QUALITY;
lf.lfStrikeOut=0;
lf.lfUnderline=0;
lf.lfWeight=FW_NORMAL;
lf.lfWidth=0;
g_hFont=CreateFontIndirect(&lf);
SendMessage(g_hTextBox, WM_SETFONT, (WPARAM)g_hFont, 0);
g_hOldTextBoxProc=(WNDPROC)SetWindowLong(g_hTextBox, GWL_WNDPROC, (LONG)EditWndProc);
return 0;
break;
}
BOOL WINAPI ConInit(HWND hWndOwner)
{
WNDCLASS wc;
g_hOwner=hWndOwner;
if (!g_hWnd)
{
memset(&wc, 0, sizeof(WNDCLASS));
wc.hbrBackground=(HBRUSH)(COLOR_BTNFACE+1);
wc.hCursor=LoadCursor(NULL, IDC_ARROW);
wc.hInstance=g_hInstance;
wc.lpfnWndProc=WndProc;
wc.lpszClassName="DebugConsole";
if (!RegisterClass(&wc))
return FALSE;
g_hWnd=CreateWindow("DebugConsole",
"Debug Console",
WS_OVERLAPPEDWINDOW&~WS_MAXIMIZEBOX,
CW_USEDEFAULT,
CW_USEDEFAULT,
600,
300,
NULL,
NULL,
g_hInstance,
NULL);
if (!g_hWnd)
return FALSE;
g_hMenu=CreateMenu();
AppendMenu(g_hMenu, MF_STRING, IDM_CLOSE, "Close");
SetMenu(g_hWnd, g_hMenu);
g_hBrush=CreateSolidBrush(g_clrBackColor);
}
return TRUE;
}
Thanks for any advice.
Jamie Nordmeyer
Portland, Oregon, USA
|
|
|
|
|
A shot in the dark: maybe you should use CS_GLOBALCLASS as class style?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
just a quick simple question.
Do you have to use memfree after your finished with a block you created with memset?
|
|
|
|
|
memset() doesn't create (allocate) memory. Use malloc() instead.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I'm writing a app. that connects to a ftp server and downloads /uploads some files. I also need smb support and the app must also be able to mount a network share and do similar ftp stuff. My first instinct was to use communication pipes. howeevr I need the app to be Win9x compatible too. My next guess is using Winsock.
how do I mount a network share in WinNT?
Any comments/advise?
TIA.
I'm an alien, I'm an alien
it's a beautiful life....
Bush
|
|
|
|
|
Hi,
I want to show the vertical scroll bar always in the view (derived from CRichEditView) of my MDI application. The problem is, by default the scroll bar is shown only when it is required. But I want to show the scroll bar always, even if there is nothing to scroll in the view. How do I do that. I tried ShowScrollBar, ModifyStyle ...but no result. ( this is in Win 95 machine)
Shrinivas
|
|
|
|
|
Hi,
I create a thread that run's for quite a long time. I want a "nice" way of terminating the thread from outside it. The only way I know at the moment is by TerminateThread, but this is not recommended. Are there any better ways?
Thanks
Neil
|
|
|
|
|
The only 'clean' way to terminate the thread is from the thread itself. It should periodically check for a signal from main thread to end itself - you can implement this strategy using a volatile bool variable. The variable should be initially set to false; when other thread should exit, the variable is set to true.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
There is no nice way of terminating a thread outside of it without some collaboration inside the thread (by the way TerminateThread shoud be used only as a last resort when nothing else worked). It is the thread that has to return upon indication.
There are several methods to signal a thread to die:- Setting some variable that the thread polls periodically,
- if the thread is usually hanged on a
WaitForMultipleObjects() (which is a very usual configuration for dispatching of asynchronous events), have an additional event handle for signalling time to die,
- if the thread pumps messages with a
GetMessage loop, post a termination message with PostThreadMessage(idThread,WM_QUIT,0,0) , or signal its dependent window to die and have this windows do PostQuitMessage() on WM_DESTROY .
Once you've signaled the thread to die, you can sit down and wait fot it to pass away with WaitForSingleObject(hThread,INFINITE) . If however you're not 100% sure your thread is going to behave, you can add a little panic handler just in case:
if(WaitForSingleObject(hThread,10000)!=WAIT_OBJECT_0){
ASSERT(FALSE);
TerminateThread(hThread);
}
CloseHandle(hThread);
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi,
I am embedding MSWord In my application, using OLE automation.
But when I goto save i get the saveas method is not available as the
document is been editted in another application.
Code As Follows, from the CanCloseFrame(), i did something similar to insert word into the doc/view architecture
CEmbedWordCntrItem* ViewObj;
ViewObj = ((CEmbedWordView*)pFrame->GetActiveView())
- >m_pSelection;
LPDISPATCH lpDispatch = (ViewObj->GetIDispatch());
_Document doc;
doc.AttachDispatch(lpDispatch);
COleVariant covFalse((short)FALSE);
COleVariant vtOptional((long)DISP_E_PARAMNOTFOUND,VT_ERROR);
doc.SaveAs(COleVariant("C:\\DataDoc.doc",VT_BSTR), vtOptional.........)
Cheers
Richard
|
|
|
|
|
I'm using a function to set a file for saving data. The function requires an LPSTR typr
for the filename parameter. The filename will be retrieved from an edit box in the application
dialog and it is presently type CString. When I build the project I get an error in the setDisk
function that says. "cannot convert parameter 2 from 'class CString' to 'char *'".
How do I fix this?
|
|
|
|
|
if your CString variable is str, do something like this:
yourFunction (firstParametar, (const char*) str);
I vote pro drink
|
|
|
|
|
You have to cast:
void func(LPSTR s);
CString strx;
func((char *)(const char *)strx);
... or ...
func(const_cast<char *>(static_cast<const char *>(strx)));
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Help!
I've got a list box that that wont stop updating itself.
It displays correctly initially, but if it is refreshed(ON_UPDATE)
then it just goes beserk, repeatedly refreshing itself and keeping the rest of the dialog from refreshing.
Anybody had this happen before?
Know how to fix it?
Thanks
Josh
josh@that-guy.net
|
|
|
|
|
Are you handling any of the notifications from the list box? if you are make sure that they arent firing themselfs... like if you handle LBN_SELCHANGE, dont set the selection withing that handler.
It kind of sounds like something similar is happening to you, thought I'm not sure what ON_UPDATE referes to.
Ben Burnett
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
|
Hi,
I am embedding MSWord In my application, using OLE automation.
But when I goto save i get the saveas method is not available as the document is been editted in another application.
Code As Follows, from the CanCloseFrame()
CEmbedWordCntrItem* ViewObj;
ViewObj = ((CEmbedWordView*)pFrame->GetActiveView())
- >m_pSelection;
LPDISPATCH lpDispatch = (ViewObj->GetIDispatch());
_Document doc;
doc.AttachDispatch(lpDispatch);
COleVariant covFalse((short)FALSE);
COleVariant vtOptional((long)DISP_E_PARAMNOTFOUND,VT_ERROR);
doc.SaveAs(COleVariant("C:\\DataDoc.doc",VT_BSTR), vtOptional.........)
Cheers
Richard
|
|
|
|
|
Hi,
My objective is to simply copy a buffer to a file. However,
my program crashes when I attempt to do any CFile operations
(open/read/write/etc...) when I'm inside my ThreadFunction.
My calls work fine when I move it to the main application
thread, but I need to transfer it to a worker thread, and do
its processing in the background.
What am I neglecting to do? Any help is appreciated.
Best Regards,
Thuan
|
|
|
|
|
What kind of crash it is? Can you post some relevant code fragments?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Have you declared your CFile Object local to your thread or is it a static global object ?
|
|
|
|
|
I'm wrestling a problem that has me stumped.
In a nutshell, here's what happens: if I terminate my program in teh debugger - either becasue of a crash or because I manually stop debugging - it remains in memory. Its main window stays up; I can no longer do builds becasue Windows says the file is on use; and I can't even restart, because my app has code to only allow a single instance to run. Clever me!
When this happens, I have to reboot, and since I'm running Win2K, that's about a 5 minute process. I did learn last night, just through blind luck, that the app will eventually shut itself down on its own, like after about 15 minutes.
I can't terminate the app through Task Manager, either - the mesage I get back says "access denied".
My app is multi-threaded, in that I run a couple threads with to watch for file changes with FindFirstChangeNotification. However, this happens even when I disable those threads.
I've tried using AtExit() to set up a function to be called on shutdown, in an attempt to clean up some stuff of which I am suspicious (my MIDI ports, in particular). However, that does not get called when I shut down in the debugger. So much fdor advice from Usenet.
So the questions are:
1) Any idea what could be causing this sort of hangup?
2) Is there any function I can use that will really be called at shutdown, especially during crashes?
TIA x 10^6
|
|
|
|
|
1) Any idea what could be causing this sort of hangup?
Maybe an automation reference left dangling?
2) Is there any function I can use that will really be called at shutdown, especially during crashes?
I'll go out on a limb and say 'no'... - not for 'Stop Debugging'...
Well, gee that was helpful...
You might want to grep the MSDN for "W32Mar98.exe" - that should get you to a Q&A article by Jeffrey Richter where he discusses enabling the debug priviledge for task manager. The context here is a hung service, but might be worth a try...
|
|
|
|
|
Or, easier, get the PID and use kill.exe to terminate - kill should run with the debug privilege enabled, assuming you are an admin/user who has this privilege.
Check the Microsoft Platform SDK\Bin\Dbg dir if kill.exe is not in your path.
|
|
|
|
|
Thx for the tip - alas, kill doesn't even work!
C:\Microsoft Visual Studio\Platform SDK\Bin\Dbg>kill -f 1420
process PhantomExplorer (1420) - '' could not be killed
So I've got the right process, but it's still unkillable. Will have to look into this deeper. Thanks for the pointers -
|
|
|
|
|