Resource Tools: Custom Resource Types

This update for Resource Tools adds an option to access custom resource types, such as FILE, TYPELIB, REGISTRY etc. It lets enumerate the resource, and load/save them. The COM interafce adds new Items property; the code snippet below accesses type library of image2.dll and saves it into external tyle library file image2.tlb:

image = new ActiveXObject("AlaxInfo.ResourceTools.Image");
image.Initialize("C:\\Windows\\syswow64\\imapi2.dll");
image.Items("TYPELIB").Item(1).SaveToFile(null, "imapi2.tlb");

Additionally, image.EndUpdate(false) call makes the object close all references to the underlying file so that it can be available for other operations (e.g. overwrite), and the COM object might be further re-initialized and reused.

Download links:

LogProcessExceptions: Log Service Process Exceptions

One of the nasty issues with LogProcessExceptions utility was that it was unable to attach to service processes and track them to catch their exceptions.

The actual problem was that the processes were not listed in first place, so there was nothing to attach to. Access and security requirements necessary for a process to debug another process are listed in MSDN DebugActiveProcess article:

The debugger must have appropriate access to the target process, and it must be able to open the process for PROCESS_ALL_ACCESS. DebugActiveProcess can fail if the target process is created with a security descriptor that grants the debugger anything less than full access. If the debugging process has the SE_DEBUG_NAME privilege granted and enabled, it can debug any process.

The utility did enable the SE_DEBUG_NAME privilege, however it was doing it prior to starting debugging session and after the process of interest was already pointed to by user.

This was insufficient because EnumProcesses only lists service processes (not actually exactly services, but processes running in different security context) in case debug privilege is already enable by the time of the API call. The utility now enabled the privilege well in advance and list the services, so can be effectively applied to those.

Download links:

COM Class to Send SMTP Email: x64, Attachments, HTML Content-Type

Here go the updates on the COM library which offers easy to use COM interface to send emails, including over secure TLS and SSL channels:

  • x64 build
  • Attachments property to enable attchments to the message being sent
  • ContentType property to enable text/html bodies
  • subject non-English characters are correctly UTF-8 encoded
  • empty To, CC, BCC fields are discarded
  • recent properties are put onto persistence map: SecureSocketsLayer, TransportLayerSecurity, ContentType
message = new ActiveXObject("AlaxInfo.EmailTools.Message");
message.ServerHost = "smtp.gmail.com";

// ...
message.Body = "See attached."

attachment = message.Attachments.Add();
attachment.Type = "text/html";
attachment.Disposition = "attachment";
attachment.Name = "AutoBuildResults.html";
attachment.LoadFromFile("C:\\AutoBuildResults.html");

attachment = message.Attachments.Add();
attachment.Type = "image/jpeg";
//attachment.Disposition = "inline";
attachment.Name = "picture.jpg";
attachment.LoadFromFile("C:\\me.jpg");

// ...
message.Send();

Download Information

American Kestrel Partnership — The Peregrine Fund

As a part of American Kestrel Partnership project, Peregrine Fund put live cameras online to broadcast interior and exterior views of American Kestrel nest boxes in their campus in Boise, Idaho.

One of the nestboxes is not only populated, four eggs have been laid recently and hatching is expected soon. The live picture is made possible by putting IP cameras and connecting them with to Ustream.tv broadcasting service through Adobe FMLE software through my IP Video Source DirectShow driver for IP cameras (the IP camera video feed is streamed 24/7 through a virtual video device picked up by FMLE and re-encoded into uploadable stream forwarded to Ustream online service for further distribution).

For more information, see:

Watch the pet on live cameras below:

North Nestbox – Outside

http://ustre.am/Evbs


Live stream videos at Ustream

North Nestbox – Inside

http://ustre.am/J6jD


Live broadcasting by Ustream

Continue reading →

Enabling ATLTRACE output in Release configuration builds

The original intent is pretty clear, as MSDN states:

In release builds, ATLTRACE2 compiles to (void) 0.

As simple as this, but once in a while you are in a situation where release build fails to work for unknown reason and you need additional information for troubleshooting, and then you remember that you had debug tracing code still nicely available in the source, it is just being stripped out by definition of ATLTRACE/ATLTRACE2 macros for release builds.

To avoid reinvention of the wheel and putting new tracing, it might make sense to just re-enable existing tracing (certainly, if putting debug build binary is out of question, which might be the case in production environment and/or to avoid the hassle of installing additional runtime).

The macros need to be #undef’ined and redefined appropriately with or without limiting scope by push_macro/pop_macro #pragma’s. The trick with macro has to reach two goals, to pick file name, line and current symbol name using __FILE__ and friend macros, and also accept variable number of arguments.

The trick ATL does and we can use too is to define a helper class, with constructor taking file name, line and symbol name values, and cast operator () taking actual tracing parameters and arguments. Internally the output can be mapped to OutputDebugString API so that output could be seen using external tool such as DebugView.

When everything is well set, new the macros in question can be defined as follows:

#pragma push_macro("ATLTRACE")
#pragma push_macro("ATLTRACE2")

#undef ATLTRACE
#undef ATLTRACE2

#define ATLTRACE2 CAtlTrace(__FILE__, __LINE__, __FUNCTION__)
#define ATLTRACE ATLTRACE2

int _tmain(int argc, _TCHAR* argv[])
{
    ATLTRACE("First: %d\n", __LINE__);
    ATLTRACE(L"Second: %d\n", __LINE__);
    ATLTRACE2(atlTraceGeneral, 2, "Third: %d\n", __LINE__);
    ATLTRACE2(atlTraceGeneral, 2, L"Fourth: %d\n", __LINE__);
    return 0;
}

#pragma pop_macro("ATLTRACE2")
#pragma pop_macro("ATLTRACE")

And the Release configuration output will be:

Visual C++ .NET 2010 source code is available from SVN; in particular CAtlTrace class is here.

Bonus reading:

StressEvr: So, how many EVRs you can do?

Direct3D based DirectShow video renderers – Video Mixing Renderer 9 and Enhanced Video Renderer – have been notoriously known for consuming resources in a way that you can run at most X simultaneously. There has been no comment published on the topic and questions (e.g. like this: How many VMR 9 can a PC support concurrently) remain unanswered for a long time. Video Mixing Renderer 7 was a good alternative for some time in past until it was cut down to be unable to support hardware scaling (thanks Microsoft!). The trendy way to render video nowadays is using Enhanced Video Renderer, a Media Foundation subsystem with an interface into DirectShow to take over state of the art video rendering capabilities. So, how many EVRs one can run simultaneously? Chances are that it is less than one could suppose. The interesting part is that there is no obvious evidence on type of resource running out, which causing next EVR instance to fail to run. And not even run, the failure seem to be coming up at an earlier stage of just connecting pins in stopped state. The failure might be accompanied with errors like E_INVALIDARG, ERROR_FILE_NOT_FOUND, E_UNEXPECTED. The actual limit appear to be loosely correlating to parameters of video output, such as resolution and bitness. Desperately waiting for clarification, I am sharing the tool to estimate the limit:
* multiple EVR instances at once, hosted by multiple windows, which can be distributed across multiple monitors
* choices of resolutions and formats
* a double click on an individual renderer pops up property page set displaying effective frame rate
* 32- and 64-bit versions

Download links

Arithmetics Problem Generator

Having no creativity to build problems myself yet trying to train 9 yo buddy in arithmetics, a small application is here to help generate problem to solve to get familiar with operator priorities and basic math.

Tweaking code back and forth can make it more or less complex. Regular expression replace by pattern erases all answers from end of lines and the text is ready to be printed for the one being trained.

180 - 70 - (6460 + 91 - 6) : 77 + (152 - 74 + 2733 - 67) : (4606 : 47) = ?
(1747 - (153 - 66)) : (43 + 125 - (117 - 32)) - 13 * 1 = 7
21 + 145 - (155 - 79) - 120 : 10 - (99 + 560 : 56 - 96) = 65
2 * (270 + 40) : 62 + (139 - 60 + 8753) : (40 + 29) - (180 - (149 - 36 - (91 - 63))) = 43
(4071 - 12 + 2640 : 80) : (98 - (46 + 35 + 7) + 34) = 93
151 + 39 - 45 - (59 + 62 - 33 - (61 - (70 - 46))) = 94
1 * 11 * 4 - (185 - 73 - (118 + 54 + 14 - 89)) = 29
122 - 83 + 81 - (1 + 8) - (101 - 42 - 5 * 2) = 62
254 - 82 - 65 - ((3342 + 13) : 55 + 118 - 96) + (41 * 2 - 38) * 0 * 95 = 24
(1 * 35 + 204 - 87 - 79 + 4 + 5 - (16 + 2758) : (81 - 43)) * 2133 : 79 : 27 = 9

A binary [Win32] and partial Visual C++ .NET 2010 source code are available from SVN.

If you just need an infinite source of things to crack, it’s here also: 01.txt.