i'll edit this post from time to time to update it untill it's finished.
Worker Thread and Service Agent execution.
If an exception is thrown from the SA, the exceeption is logged (using the Exception management mechanism). The default exception publisher logs to System Event log.
This is because the worker thread has a try-catch inside the thread proc. And this makes that the while loop inside the thread procedure to continue.
The Worker thread has a serviceAgentRequest memeber variable which is set \ cleared to null on SA creation execution \ SA execution returns.
Worker thred checks for this variable at the loop begin and resubmits the request (it wont look at the requests queue).
So, when an exception is thrown from a SA during execution, the SA will be resubmitted indefinetely until the SAMonitor aborts the worker thread.
Regarding the SAMonitor: Note that in the case of the exeception thrown from SA, the SAMonitor is called to add the worker thread at each resubmission. But SAMonitor checks if it has that worker thread already in its thread table and removes it and adds it again.
So this means that if a SA exception appears you can decide to either rethrow the exception so the request is resubmit or not rethrow it and maybe just return from execution (and the worker thread will mark the request as completed).
Wednesday, July 25, 2007
Sunday, July 15, 2007
Opening CHM Help files from Network or Internet
Due to a security patch Windows has restricted access to a CHM. More info here: http://support.microsoft.com/kb/896358.
The attached reg script fixes one of the 4 problems described in the KB. It works for most of the CHM files. Here is the file.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\HTMLHelp\1.x\ItssRestrictions]
"MaxAllowedZone"=dword:00000004
The attached reg script fixes one of the 4 problems described in the KB. It works for most of the CHM files. Here is the file.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\HTMLHelp\1.x\ItssRestrictions]
"MaxAllowedZone"=dword:00000004
Monday, July 09, 2007
Win32 HANDLEs
Each time when you use a win32 API which uses a HANDLE remember that the handle Must be valid (not closed).
It is important to understand the concepts of the handle being signaled and being closed.
Signaled state refers to the handle state. It can be signaled or unsignaled. Wait functions for example, like WaitForSingleObject, block current thread until the object gets signaled.
A handle is said to be closed when its reference count reaches zero value. When this happens the handle is closed and doing any waiting on it is error prone.
A handle is a pointer on an object. Wait functions check the state of the object, hence it is a must that the handler (the pointer) is valid. Otherwise, waiting functions wont work properly (while waiting on an invalid handle, you might wait indefinetly).
One example of bogus use is with MFC AfxBeginThread function. Its default behaviour is to auto 'delete' the thread, i.e to close its handle.
Its bad to use the returned handle after the thread is terminated and closed.
That its not a HANDLE. its a wild HANDLE.
This is described excellent in Chapter 12, Threads in the well known book by Jeff Prosise, Programming Windows with MFC, 2nd Edition.
Another missuse, without MFC, might be in an multithreaded application. One threads create a thread and share the handle others thread which use it.
It is important to understand the concepts of the handle being signaled and being closed.
Signaled state refers to the handle state. It can be signaled or unsignaled. Wait functions for example, like WaitForSingleObject, block current thread until the object gets signaled.
A handle is said to be closed when its reference count reaches zero value. When this happens the handle is closed and doing any waiting on it is error prone.
A handle is a pointer on an object. Wait functions check the state of the object, hence it is a must that the handler (the pointer) is valid. Otherwise, waiting functions wont work properly (while waiting on an invalid handle, you might wait indefinetly).
One example of bogus use is with MFC AfxBeginThread function. Its default behaviour is to auto 'delete' the thread, i.e to close its handle.
Its bad to use the returned handle after the thread is terminated and closed.
That its not a HANDLE. its a wild HANDLE.
This is described excellent in Chapter 12, Threads in the well known book by Jeff Prosise, Programming Windows with MFC, 2nd Edition.
Another missuse, without MFC, might be in an multithreaded application. One threads create a thread and share the handle others thread which use it.
Labels:
handle,
multithreading,
synchronization,
win32api
Thursday, June 21, 2007
Monstrous compilation error on any MFC application
Ok, I've just created a simple MFC DLL, hit the compile button and I got this monstrous error:
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\excpt.h(36): error C2144: syntax error : 'int' should be preceded by ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\excpt.h(36): error C2501: 'x' : missing storage-class or type specifiers
And i was like, "WTF !?".
When I see these kind of errors i instantly get several thoughts but in a 'chain of responsability' pattern way:
'i need to check the code again'
'ummm, lemme search google for the error'
'shit, i need to reinstall the vstudio'
'ok, i think i need 'a' beer'
Ive been lucky enough not to reach the last option in my programming problems ive had so far(though, i dont need programming problems to do that, really).
googling a bit i found somebody adviced for a VisualStudio reinstallation. hmmm. too lazy for doing that (and not necessary). but searchin in the microsoft.com for 'C2144' i got a post with a similar issue and an idea that some of the headears might got mistakenly changed by an accidentaly edit.
i said, Ok, no problem i will do a search on windows explorer to see what was changed today.
i did, and to my horrification i found no change.
luckily, i have another pc with a visual studio installation. i quickly opened windiff over the atlmfc folder. and there it was: 'afxv_w32.h'. a smiley 'x' was lying there.
i wasnt able to find the header simply because it was not changed today. it was changed 2 days ago :|
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\excpt.h(36): error C2144: syntax error : 'int' should be preceded by ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\excpt.h(36): error C2501: 'x' : missing storage-class or type specifiers
And i was like, "WTF !?".
When I see these kind of errors i instantly get several thoughts but in a 'chain of responsability' pattern way:
'i need to check the code again'
'ummm, lemme search google for the error'
'shit, i need to reinstall the vstudio'
'ok, i think i need 'a' beer'
Ive been lucky enough not to reach the last option in my programming problems ive had so far(though, i dont need programming problems to do that, really).
googling a bit i found somebody adviced for a VisualStudio reinstallation. hmmm. too lazy for doing that (and not necessary). but searchin in the microsoft.com for 'C2144' i got a post with a similar issue and an idea that some of the headears might got mistakenly changed by an accidentaly edit.
i said, Ok, no problem i will do a search on windows explorer to see what was changed today.
i did, and to my horrification i found no change.
luckily, i have another pc with a visual studio installation. i quickly opened windiff over the atlmfc folder. and there it was: 'afxv_w32.h'. a smiley 'x' was lying there.
i wasnt able to find the header simply because it was not changed today. it was changed 2 days ago :|
Wednesday, April 04, 2007
working with DirectShow
The project I am working on has some code already written using DirectShow and I am working with Visual Studio 2005.
DirectShow needs DirectX also.
So you need both of them installed.
It seems that DirectShow was moved from DirectX and was a separate package. Now it seems it is part of the Windows Platform SDK.
Latest "DirectX Software Development Kit" location here
Latest Platform SDK it is called "Microsoft Windows Server 2003 R2 Platform SDK" and get it from here
From the webpage select the type of target platform you want the SDK for.
It will download a small web installer from which you can select what SDK components you want to download an install. In this case choose DirectShow.
The project uses a DirectShow filter and this one needs Strmbase.lib which is the static library from BaseClasses (located under: (SDK root)\Samples\C++\DirectShow\BaseClasses)
The documentation says that there it should be an BaseClasses.dsw file but its not.
I did a search on google on this file and i found this as a response to someone with the same problem:
"There are no project files in the Platform SDK. You must build from command line using the appropriate build shortcut under the Platform SDK menu item.
Once launched, use the DOS CD command to change to the Baseclasses directory and type NMAKE.
You can also get just the project files from an older distribution here:
http://tmhare.mvps.org/downloads.htm"
So I downloaded "DirectShow SDK Project Files (version 0.2 for W2K3 R2 PSDK) 146 KB." from that location which has the sln and vcproj files to build BaseClasses.
Also, when building DirectShow applications make sure that:
in Visual Studio VC++ Directories Options you have at the top both in Include and Libs the path to the Include and Lib folders of DirectShow and DirectX.
if the application (for example a filter) uses environment variables to locate the DirectShow include \ library files (like $(DSHOWBASECLASSES)\.,$(DXSDK)\include) then make sure you have or define else these variables.
$(DSHOWBASECLASSES) must point to the (SDK root)\Samples\C++\DirectShow\BaseClasses
where (SDK Root) is the root folder installation of DirectShow (the application (filter) needs the path to locate strmbas.lib file (the BaseClasses lib))
$(DXSDK) is the root folder of the DirectX installation.
If while compiling you get this error:
error C1189: Need to include strsafe.h after tchar.h
A possible explanation is done here: http://harshdeep.wordpress.com/2006/05/30/directshow-with-visual-studio-8/
(he tried to compile by hand the BaseClasses and link to it in his application and he got different errors)
"The first step was to get the latest DirectShow SDK - as I mentioned in the last post, it’s a part of the Platform SDK and Direct X SDK is required to build the samples. The first sample, Baseclasses, is what I needed. I built the static libraries strmbasd.lib (debug) and strmbase.lib (release) through nmake, as DirectShow documentation suggested, and linked them to the corresponding builds of my dll that uses DirectShow. This opened up a Pandora’s box of compiler, linker and run-time errors.
tchar.h was throwing a compiler error - “error C1189: Need to include strsafe.h after tchar.h”. Lots of people have complained about this error in the forums. dshow.h includes strsafe.h, so in this case the error simply reads “include tchar.h before including dshow.h”.
I was getting some “undefined symbols” link errors for functions that I could clearly see in Baseclasses code. It was because I’d used nmake to build the libraries. The default settings that it used were not compatible with the project settings of my DirectShow code.
I created a VS8 project for Baseclasses. All I had to do to fix the link errors was to match the “Character Set” and “Treat wchar_t as a Built-in type” settings in the project properties of Baseclasses and my dll that links to it. But this code was still crashing. Reason - different “Structure alignment” in the two projects. Using the same value in both the projects fixed it.
Moral of the story: Don’t use nmake to build Baseclasses for you - write a VS project and use the right settings.
"
DirectShow needs DirectX also.
So you need both of them installed.
It seems that DirectShow was moved from DirectX and was a separate package. Now it seems it is part of the Windows Platform SDK.
Latest "DirectX Software Development Kit" location here
Latest Platform SDK it is called "Microsoft Windows Server 2003 R2 Platform SDK" and get it from here
From the webpage select the type of target platform you want the SDK for.
It will download a small web installer from which you can select what SDK components you want to download an install. In this case choose DirectShow.
The project uses a DirectShow filter and this one needs Strmbase.lib which is the static library from BaseClasses (located under: (SDK root)\Samples\C++\DirectShow\BaseClasses)
The documentation says that there it should be an BaseClasses.dsw file but its not.
I did a search on google on this file and i found this as a response to someone with the same problem:
"There are no project files in the Platform SDK. You must build from command line using the appropriate build shortcut under the Platform SDK menu item.
Once launched, use the DOS CD command to change to the Baseclasses directory and type NMAKE.
You can also get just the project files from an older distribution here:
http://tmhare.mvps.org/downloads.htm"
So I downloaded "DirectShow SDK Project Files (version 0.2 for W2K3 R2 PSDK) 146 KB." from that location which has the sln and vcproj files to build BaseClasses.
Also, when building DirectShow applications make sure that:
in Visual Studio VC++ Directories Options you have at the top both in Include and Libs the path to the Include and Lib folders of DirectShow and DirectX.
if the application (for example a filter) uses environment variables to locate the DirectShow include \ library files (like $(DSHOWBASECLASSES)\.,$(DXSDK)\include) then make sure you have or define else these variables.
$(DSHOWBASECLASSES) must point to the (SDK root)\Samples\C++\DirectShow\BaseClasses
where (SDK Root) is the root folder installation of DirectShow (the application (filter) needs the path to locate strmbas.lib file (the BaseClasses lib))
$(DXSDK) is the root folder of the DirectX installation.
If while compiling you get this error:
error C1189: Need to include strsafe.h after tchar.h
A possible explanation is done here: http://harshdeep.wordpress.com/2006/05/30/directshow-with-visual-studio-8/
(he tried to compile by hand the BaseClasses and link to it in his application and he got different errors)
"The first step was to get the latest DirectShow SDK - as I mentioned in the last post, it’s a part of the Platform SDK and Direct X SDK is required to build the samples. The first sample, Baseclasses, is what I needed. I built the static libraries strmbasd.lib (debug) and strmbase.lib (release) through nmake, as DirectShow documentation suggested, and linked them to the corresponding builds of my dll that uses DirectShow. This opened up a Pandora’s box of compiler, linker and run-time errors.
tchar.h was throwing a compiler error - “error C1189: Need to include strsafe.h after tchar.h”. Lots of people have complained about this error in the forums. dshow.h includes strsafe.h, so in this case the error simply reads “include tchar.h before including dshow.h”.
I was getting some “undefined symbols” link errors for functions that I could clearly see in Baseclasses code. It was because I’d used nmake to build the libraries. The default settings that it used were not compatible with the project settings of my DirectShow code.
I created a VS8 project for Baseclasses. All I had to do to fix the link errors was to match the “Character Set” and “Treat wchar_t as a Built-in type” settings in the project properties of Baseclasses and my dll that links to it. But this code was still crashing. Reason - different “Structure alignment” in the two projects. Using the same value in both the projects fixed it.
Moral of the story: Don’t use nmake to build Baseclasses for you - write a VS project and use the right settings.
"
Saturday, March 24, 2007
CreateDialog, CreateWindow or any other window\dialog creation function fails and GetLastError is 0
... then check if you have called InitCommonControls() at very start of your application if you use any common controls (list view, tree view ,etc)
Subscribe to:
Posts (Atom)