Damir Arh's Corner
Search
Categories
  Development
 .NET
 Batch
 C++
 SQL
 VB6
 Vista
 Web
 Win32
  Downloads
 Amiga
 Articles
 Presentations
 Sources
 Windows
  Personal
 Education
 Software
 Website
Archives
June, 2008 (1)
April, 2008 (2)
December, 2007 (1)
November, 2007 (3)
July, 2007 (4)
June, 2007 (1)
May, 2007 (2)
March, 2007 (3)
January, 2007 (1)
December, 2006 (4)
October, 2006 (5)
September, 2006 (3)
August, 2006 (2)
June, 2006 (8)
May, 2006 (5)
April, 2006 (1)
March, 2006 (4)
February, 2006 (3)
January, 2006 (3)
March, 2003 (1)
February, 2002 (1)
January, 2002 (2)
August, 2001 (1)
July, 2001 (1)
February, 2001 (1)
December, 2000 (1)
September, 2000 (1)
July, 2000 (1)
Other Sites
Potepanja v naravi (sl)
Picasa Web Albums (sl)
moj-album.com Gallery (sl)
Bolha.com Auctions (sl)
My Game Space
LinkedIn Public Profile
My GamerTag
Sponsored Links
Administration
Sign In
Sunday, June 15, 2008

Microsoft Pro Photo Tools decimal separator problem (Personal | Software)

Today I've taken my new handeld GPS device for a test run. It did its job pretty well but the real challenge started afterwards when I tried geotagging the photos I've taken. I decided to use Microsoft Pro Photo Tools which have just been released with geotagging as its main feature. Downloading the track data from the GPS device with Garmin MapSource software was quick and simple. But the problems started soon afterwards. MapSource can only export track data in its proprietary format GDB which can't be used in Microsoft Pro Photo Tools.

GPSBabel came to the rescue. This free tool can probably convert files between any two existing GPS formats, at least judging from its list of supported formats. I used it to convert my data to the GPX XML format only to find out that Microsoft Pro Photo Tools have problems with it. Converting to NMEA or KML instead didn't help either. Fortunately the latter returned a strange error (Degrees must be between 0 and 90, found degree 46298501) which put me on the right track. Of course there was no such value in the KML file so I correctly deduced that the decimal separator was to blame.

The value in the file was 46.298501 but the Slovenian regional settings have comma as the decimal separator therefore the value was misinterpreted. Temporarily changing the decimal separator to dot solved the problem - the track was successfully imported immediately afterwards. This issue won't keep me from using this otherwise very useful tool with a really nice feature set. It could even fix the mismatching time settings between my GPS unit and the camera with a single setting. I just hope they address this bug soon so that I won't have to change my regional settings every time I use the program.

The only thing I still have to figure out is why the geotags somehow lost resolution when I uploaded the photos from Picasa to Picasa Web Albums. I just fixed them manually and decided to address the issue next time. Any tips are welcome.

6/15/2008 9:03:01 PM (Central Europe Standard Time, UTC+01:00)  #  Comments [0]

Tuesday, April 29, 2008

Old ActiveX controls under .NET 2.0 SP1 (Development | .NET | Vista)

A .NET application in the company I work for recently started crashing under Windows Vista when trying to open a window implemented in an ActiveX DLL. Investigations showed that they were caused by an AccessViolationException "Attempted to read or write protected memory. This is often an indication that other memory is corrupt.". The cause was one of the ActiveX controls in the window. When instantited directly in a .NET Form the exception above was contained in a TargetInvocationException "Unable to get the window handle for the '<control name>' control. Windowless ActiveX controls are not supported.". Knowing that the control didn't suddenly turn windowless we dug deeper.

It turned out that the problem appeared with .NET Framework 2.0 Service Pack 1. Apparently it caused the C# compiler in Visual Studio 2005 and later to set the NXCOMPAT bit for all build targets without an option to turn this new behavior off. For those who don't know, this means that DEP (data execution prevention) will kick in unless it is turned off completely in the operating system. This wouldn't be a big deal unless ATL before Visual Studio 2005 didn't have a bug which caused the heap allocated memory not to be flagged as executable, which under the new circumstances results as the already mentioned exception. Windows XP has DEP turned off by default therefore everything still works but in Windows Vista it is turned on and prevents such application from functioning properly.

The best solution would of course be to recompile the ActiveX controls in Visual Studio 2005 or later but this might not be possible if they are supplied by a third party. In this case the most obvious approach to dealing with the situation is to disable DEP in Vista. There is a Data Execution Prevention tab in the Performance Options which open when you click the Settings button in the Performance frame of the Advanced tab in the System Properties dialog but it only allows switching between DEP for all processes with defined exceptions and DEP for essential Windows programs and services, i.e. executables flagged with the NXCOMPAT bit. The only way to turn DEP completely off is executing the following command with administrative privileges:

bcdedit.exe /set {current} nx AlwaysOff

After restart DEP will be turned off and problematic binaries will work once again. To restore the previous (default) state replace AlwaysOff with OptIn. The AlwaysOn option enables DEP for all processes and might cause additional problems (e.g. Google Calendar Sync in its current version 0.9.3.2 doesn't work in this mode).

Unfortunately, this solution would require all your Vista using customers to disable DEP as well which really isn't an option for commercial software. Fortunately, there is another solution. Although there is no compiler option to turn keep the NXCOMPAT bit unset, you can still do this after compilation using the editbin.exe which comes with C++ compiler for Visual Studio 2005 and later:

editbin.exe /NXCOMPAT:NO <filename.exe>

This command removes the NXCOMPAT bit and restores the behavior before .NET 2.0 SP1. If your assembly was signed it also invalidates the signature so you'll have to resign it:

sn.exe -R <filename.exe> <keyfile.snk>

You can automate this by putting the two commands in the Post-build event command line for the project:

editbin.exe /NXCOMPAT:NO "$(TargetPath)"
sn.exe -R "$(TargetPath)" "$(ProjectDir)<keyfile.snk>"

You might need to call vcvars32.bat before that to put the required executables in path and enable editbin.exe dependencies to be resolved. Note that in a completely automated build scenario using MSBuild you'll have to specify full path for the vcvars32.bat because $(DevEnvDir) resolves to *Undefined* outside Visual Studio 2005. Also your strong name key should be in a snk file instead of a password protected pfx file because sn.exe doesn't allow the password to be read from a redirected standard input.

4/29/2008 2:29:08 PM (Central Europe Standard Time, UTC+01:00)  #  Comments [0]

Monday, April 14, 2008

MonthCalendar BoldedDates in Windows Vista (Development | .NET | Vista)

The MonthCalendar control's BoldedDates functionality doesn't appear to work properly on Windows Vista. The dates added to any of the BoldedDates, MonthlyBoldedDates and AnnuallyBoldedDates collections are rendered just the same as those not added to any of the collections. The same code works just fine on Windows XP and causes those dates to be rendered bold. The only workaround i've managed to find is disabling visual styles in the application, i.e. commenting out the first line in the Program.Main() method of a new Windows Application:

Application.EnableVisualStyles();

4/14/2008 8:54:58 PM (Central Europe Standard Time, UTC+01:00)  #  Comments [0]

Monday, December 31, 2007

Playing DivX and XviD videos natively on Xbox 360 (Personal | Software)

The Xbox 360 Dashboard update released on 4th December 2007 added support for playing DivX and XviD videos natively, i.e. without installing Transcode 360 for Windows Media Center. Unfortunatelly this only works for media played directly from the dashboard and not within Media Center Extender. Since I didn't want to copy my videos to CDs, DVDs or other external devices, the only thing left to do was to setup Windows Media Player media sharing which I never had to use before.

This turned out to be more difficult than I expected - the reason being that the media I wanted to share wasn't stored locally but on a separate file server. By default such media is not shared and there are few steps one has to follow to make this work, as thoroughly explained here:

  • Enable remote content sharing by adding the following entry into the registry:
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MediaPlayer\Preferences\HME]
    "EnableRemoteContentSharing"=dword:00000001
  • Grant anonymous users access to the shared folders on the file server by adding the read permission on the folder and on the share to the ANONYMOUS LOGON user
  • Modify the file server's group policy to allow anonymous access to the selected shares by listing them in the Network access: Shares that can be accessed anonymously policy in the Computer Configuration, Windows Settings, Security Settings, Local Policies, Security Options branch of the group policy tree (just run gpedit.msc to start the Group Policy Object Editor)

12/31/2007 12:34:14 PM (Central Europe Standard Time, UTC+01:00)  #  Comments [0]

Saturday, November 24, 2007

Notes about RSACryptoServiceProvider (Development | .NET)

In my opinion RSACryptoServiceProvider class is seriously under-documented in MSDN. Since there is also no abundance of examples on the web, I spent more time than I should figuring out how to use it correctly. For future reference I'm listing below the solution to two problems I had.

The maximum byte array length for encrypting without OAEP padding is Modulus size - 11 which is written somewhere in the Encrypt() method documentation. If you pass it a larger array it will return a not so informative Unspecified error. To encrypt a larger chunk of data you have to split it in smaller parts, encrypt them individually and concatenate them back together. You have to do the same when decrypting the data, with the only difference that each part has the size of Modulus in stead of Modulus - 11. To get the modulus size you can use the following piece of code (rsa is an instance of RSACryptoServiceProvider):

RSAParameters rsaParams = rsa.ExportParameters(false);
int modulusSize = rsaParams.Modulus.Length;

Each time you instantiate RSACryptoServiceProvider it generates a new pair of keys. If you want to use existing ones, you can import them by calling:

rsa.FromXmlString(key);

The key parameter is a string with the XML representation of the keys. You can get it by calling the ToXmlString() method once and storing its results. It's only parameter specifies whether to also export the private key. I guess I don't have to remind you that you need the private key only for decryption and that you should always keep it private for the encryption to make any sense at all.

11/24/2007 5:31:53 PM (Central Europe Standard Time, UTC+01:00)  #  Comments [0]

Always close DeflateStream before reading results (Development | .NET)

Is the code below correct? Will inputString and outputString be equal?

string inputString = "The text to compress and decompress";
byte[] inputArray = Encoding.UTF8.GetBytes(inputString);

MemoryStream stream = new MemoryStream();
DeflateStream compressionStream =
    new DeflateStream(stream, CompressionMode.Compress);
compressionStream.Write(inputArray, 0, inputArray.Length);
compressionStream.Flush();

stream.Position = 0;

DeflateStream decompressionStream =
    new DeflateStream(stream, CompressionMode.Decompress);
byte[] outputArray = new byte[inputArray.Length];
decompressionStream.Read(outputArray, 0, outputArray.Length);
string outputString = Encoding.UTF8.GetString(outputArray);

Console.WriteLine(outputString == inputString);
Console.ReadLine();

As it turns out, they won't. The reason for it being that compressionStream.Close() was not called before reading from stream started. Calling compressionStream.Flush() is not enough in this case. I haven't managed to find this documented anywhere but the example in the DeflateStream documentation does it correctly. You can find the fixed code below. Notice the additional last parameter in the first call to the DeflateStream constructor. Without it stream will also be closed when compressionStream gets closed.

string inputString = "The text to compress and decompress";
byte[] inputArray = Encoding.UTF8.GetBytes(inputString);

MemoryStream stream = new MemoryStream();
DeflateStream compressionStream =
    new DeflateStream(stream, CompressionMode.Compress, true);
compressionStream.Write(inputArray, 0, inputArray.Length);
compressionStream.Close();

stream.Position = 0;

DeflateStream decompressionStream =
    new DeflateStream(stream, CompressionMode.Decompress);
byte[] outputArray = new byte[inputArray.Length];
decompressionStream.Read(outputArray, 0, outputArray.Length);
string outputString = Encoding.UTF8.GetString(outputArray);

Console.WriteLine(outputString == inputString);
Console.ReadLine();

Thanks once again to my coworker for suggesting this when I was already running out of ideas.

11/24/2007 4:44:37 PM (Central Europe Standard Time, UTC+01:00)  #  Comments [0]

Location of PowerPoint AutoRecover files (Personal | Software)

Not so long ago I've been called to my boss's office to prevent him losing unsaved work in a PowerPoint presentation. It turned out that when he tried to save the file to a new location the message box with the overwrite warning for some reason didn't render completely and it was impossible to close it. As it turned out at the end I could have just killed the application and restart it, since the AutoRecover feature kicked in and offered a version of the file with all changes applied.

But just to be on the save side I wanted to copy the AutoRecover files to a save location before actually killing the application. But unlike Word or Excel where the location of these files is set in the options, PowerPoint does not have such an option. After some googling I finally stumbled across a page, correctly stating that the files are stored in the %temp% folder and named ppt*.tmp. I decided to publish this info here just in case I need it again.

11/24/2007 3:11:03 PM (Central Europe Standard Time, UTC+01:00)  #  Comments [0]

Tuesday, July 24, 2007

Loop over files in directory from a batch file (Development | Batch)

Figuring this out took me much longer than it should. The following line in a batch file will execute a command for each file in a directory:

for %%I in (C:\*.*) do echo %%~nxI

I had to overcome two obstacles to make this work:

  • When including the command in a batch file the % characters must be duplicated in comparison to the syntax for executing the command directly from the command line.
  • The ~nx prefix to the variable name causes only the filename with extension to be used instead of the complete path.

7/24/2007 3:19:03 PM (Central Europe Standard Time, UTC+01:00)  #  Comments [0]

Creating custom tasks for CruiseControl.NET (Development | .NET)

Once you start putting CruiseControl.NET to production use you'll sooner or later encounter the need for custom build tasks. There's only a limited set of them in the package and Executable Task can only do so much. Unfortunately there is not much information available on development of custom tasks. Your best sources will be:

  • Online documentation contains an article on the subject describing the first steps to get you going. It should be your first stop.
  • There's a high level architectural overview of a simple task available at Josh's Blog.
  • Lutz Roeder's Reflector for .NET will be your best friend. The source of the tasks in ThoughtWorks.CruiseControl.Core will soon become your best resource.

Apart from that I feel obliged to mention a few of the most important points I've come across during the development of a few custom tasks:

  • ThoughtWorks.CruiseControl.Core.Util.ProcessExecutor is a nice little wrapper around System.Diagnostics.Process class you'll end up using quite a lot.
  • You can add your own information to the build log by calling AddTaskResult on the IIntegrationResult instance passed to your ITask.Run method. There are two overloads available: one accepting a System.String and another one accepting ITaskResult to which you can pass a new FileTaskResult instance to quickly include a complete file.
  • If you're doing any checkins to your source control system as a part of the build you should call the MarkStartTime method of your IIntegrationResult instance afterwards to prevent triggering another build of the same project by setting the last build start time after the last checkin time.
  • Make sure you use a unique ReflectorType name for your task. The service will just silently fail to start in case of a duplicate value.

This information should make your first attempts at making your own custom task a little easier.

7/24/2007 12:57:26 PM (Central Europe Standard Time, UTC+01:00)  #  Comments [0]

Sunday, July 22, 2007

MSBuild.xsl problem in CruiseControl.NET 1.3 (Development | .NET | Downloads | Sources) msbuild.zip (1.33 KB)

The 1.3.0.2918 build of CruiseControl.NET has an error in msbuild.xsl file which causes an XslLoadException to be thrown when trying to view the MSBuild output in the web dashboard. One of the users was nice enough to describe the changes to the file necessary to fix the problem. Unfortunately even the latest version of the file on the CruiseControl.NET Live site doesn't include the changes therefore I'm attaching the file to this post as convenience.

7/22/2007 12:24:07 PM (Central Europe Standard Time, UTC+01:00)  #  Comments [0]

Installing MSI packages from command line (Personal | Software)

Although a MSI file can bi installed by double clicking on it in Explorer or by selecting install from the context menu, you might want to start from command line to include it in a script. This can be done by using the msiexec.exe utility. Although it's parameters are well documented I had to do some searching to find a way for setting a different installation directory than the default one in case the configuration forms are skipped with the /qb option. It can be done by setting the INSTALLDIR property to the desired value.

As a future reference the following command line triggers the setup package to install into the specified directory without opening any additional configuration windows:

msiexec /i MyMSI.msi /qb INSTALLDIR="C:\Program Files\My Install Dir"

7/22/2007 11:24:14 AM (Central Europe Standard Time, UTC+01:00)  #  Comments [0]

Saturday, June 02, 2007

OCR with Microsoft Office Document Imaging (Development | .NET)

If you need cheap and simple OCR functionality Microsoft Office Document Imaging Type Library (MODI) is a nice option if its requirements (Microsoft Office 2003 or later) and limitations (limited language support) don't bother you. Here is a simple C# function that does OCR on the image with the specified path:

static string OCR(string path)
{
    MODI.Document doc = new MODI.Document();
    doc.Create(path);
    doc.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, false, false);
    string result = ((MODI.Image)doc.Images[0]).Layout.Text;
    System.Runtime.InteropServices.Marshal.ReleaseComObject(doc);
    return result;
}

However, there is another Microsoft Office object model related problem. For Office 2003 users to be able to use your application, the MODI 11.0 (2003 version) must be referenced in the project and the release version of the application must be compiled on a machine with Office 2003 installed. In such a case VB6 still managed to compile the project on a machine with a newer version of Office installed, since the newer version of the type library was automatically used (MODI 12.0 for Office 2007 in this case). On the other hand strong type checking at compile time prevents that in C#.

If you want to keep using Office 2007 and be able to compile such a project, the only solution is to install Microsoft Office Document Imaging as the only component of Office 2003 along the existing Office 2007 installation. Unfortunately this overwrites the Microsoft Office Document Image Writer printer driver from 2007 with the older version, therefore you'll have to start a lengthy process of repairing the Office 2007 installation afterwards. And don't forget to apply all the service packs and updates for Office 2003 before that since this will also overwrite the printer driver and you'll have to repair Office 2007 once again. I learned that the hard way.

6/2/2007 9:39:34 AM (Central Europe Standard Time, UTC+01:00)  #  Comments [0]

Blog Feeds
RSS 2.0 RSS 2.0
Atom 1.0 ATOM 1.0
Fellow Bloggers
 Andrej Tozon
 Dejan Sarka
 Dusan Zupancic
 Matevz Gacnik
 Miha Markic
Disclaimer
The content of this site are my own personal opinions and do not represent my employer's view in anyway. In addition, my thoughts and opinions often change, and as a weblog is intended to provide a semi-permanent point in time snapshot you should not consider out of date posts to reflect my current thoughts and opinions.

Powered by:
newtelligence dasBlog 1.8.5223.2

© 2008 Damir Arh, M. Sc. Send mail to the author(s)

Microsoft Certified Professional
Currently Reading
Currently Playing
Currently Watching