I don't know if this is a generic situation or not, but it has been frustrating to resolve. The scenario is that I'm building some C/C++ FLEXnet components and was having no fun on getting the Release build to compile and link. After much fiddling, I was able to resolve everything down to one link error:
Error LNK2001: unresolved external symbol __imp__time
After comparing the differences between Debug and Release settings, I ended up stumbling upon the "Whole Program Optimization" setting (Project, Properties, Configuration Properties, General).
In my case, the default for the Release build was set to: Use Link Time Code Generation -- seems reasonable. What isn't reasonable is how it leads to the above linker error. I still have no idea why it causes it, but changing it to No Whole Program Optimization solved the issue.
Note: using Visual Studio 2008, SP1
Monday, December 22, 2008
Tuesday, December 16, 2008
Get Method or Property Name as String in .Net
There are a few occasions where it is helpful to have the string name of the executing method or property.
The cleanest way that I've been able to devise is to use the query the current stack frame using System.Diagnostics.StackFrame.
string methodName = new StackFrame().GetMethod().Name;
When called from within a property, the name includes the getter/setter prefix: get_ or set_. Therefore, if you want the actual property name, use the following:
string propertyName = new StackFrame().GetMethod().Name.Split('_')[1];
The cleanest way that I've been able to devise is to use the query the current stack frame using System.Diagnostics.StackFrame.
string methodName = new StackFrame().GetMethod().Name;
When called from within a property, the name includes the getter/setter prefix: get_ or set_. Therefore, if you want the actual property name, use the following:
string propertyName = new StackFrame().GetMethod().Name.Split('_')[1];
Monday, November 24, 2008
Directory.Delete and Read-only Files
The System.IO.Directory.Delete() method will fail (exception) when it encounters a read-only file, regardless of the recursive flag. Unfortunately, the designers of this method did not have the foresight to provide a means around this limitation.
First off, the exception (UnauthorizedAccessException) only contains the file name; no path information is given. So, if you are in the middle of a recursive delete, the file name is largely irrelevant and there isn't much (programatically) that can be done to manage the situation. The appropriate implementation would have been to include the full path & file name information in the exception, and let the implementor decide on how to represent the file to the UI, as needed.
Second, there is no provision to handle read-only or similar situations w/ the method. At a minimum, there should be the capability to specify whether or not a read-only file should be deleted or not.
Because of this, the recursive implementation of Directory.Delete() is largely useless as it doesn't do what it has been designed to do: delete a directory (and containing files). The consequence of this is that we must write our own method to perform what is actually wanted -- hardly efficient. Anyway, to that end, here is a small function that implements more complete and usable delete functionality:
public void DirectoryDelete(string path, bool recursive)
{
if (recursive)
foreach (string directory in Directory.GetDirectories(path))
DirectoryDelete(directory, true);
foreach (string file in Directory.GetFiles(path))
File.SetAttributes(file, FileAttributes.Normal);
Directory.Delete(path, true);
}
First off, the exception (UnauthorizedAccessException) only contains the file name; no path information is given. So, if you are in the middle of a recursive delete, the file name is largely irrelevant and there isn't much (programatically) that can be done to manage the situation. The appropriate implementation would have been to include the full path & file name information in the exception, and let the implementor decide on how to represent the file to the UI, as needed.
Second, there is no provision to handle read-only or similar situations w/ the method. At a minimum, there should be the capability to specify whether or not a read-only file should be deleted or not.
Because of this, the recursive implementation of Directory.Delete() is largely useless as it doesn't do what it has been designed to do: delete a directory (and containing files). The consequence of this is that we must write our own method to perform what is actually wanted -- hardly efficient. Anyway, to that end, here is a small function that implements more complete and usable delete functionality:
public void DirectoryDelete(string path, bool recursive)
{
if (recursive)
foreach (string directory in Directory.GetDirectories(path))
DirectoryDelete(directory, true);
foreach (string file in Directory.GetFiles(path))
File.SetAttributes(file, FileAttributes.Normal);
Directory.Delete(path, true);
}
Thursday, November 20, 2008
Mapping Alpha to Numeric

For example, entering in numeric values on a desktop computer with a keyboard is a non-issue (for the most part). If you intend "6", you type "6". However, if you are on a pen input device, if you intend "6", the recognizer may interpret "b".
Most of my requirements for pen input has focused around fields that should be constrained to numeric values. Simply using a 'numeric input only' text box often doesn't work. This is because if the recognizer interprets "b", the numeric text box discards that value. For the end user, this can be quite frustrating and counter-productive.
Presuming numeric-entry text, I've resolved to create an alphanumeric text box and simulate numeric-only by performing the necessary mapping from recognizer value to expected. Empirically, I've found the following table mapping suits most cases of misrecognition:
lowercase letter O (o) -> zero
uppercase letter O (O) -> zero
uppercase letter D (D) -> zero
lowercase letter I (i) -> one
uppercase letter I (I) -> one
lowercase letter L (l) -> one
slash (/) -> one
backslash (\) -> one
vertical bar (|) -> one
exclamation point (!) -> one
lowercase letter Z (z) -> two
uppercase letter Z (Z) -> two
lowercase letter S (s) -> five
uppercase letter S (S) -> five
lowercase letter B (b) -> six uppercase letter G (G) -> six
right angle bracket (>) -> seven
lowercase letter Q (q) -> nine
lowercase letter G (g) -> nine
single quote (') -> decimal point
comma (,) -> decimal point
In practice, I've found that the above mapping/conversion works pretty well and reduces the frustration and increases the validity of captured input.
Thursday, November 13, 2008
Changing e-mail Address Name Resolution Order in Outlook

The e-mail address name resolution order can be changed in Outlook. From Outlook, navigate to Tools, Address Book..., and then from the Address Book, navigate to Tools, Options.
From this dialog you can change the resolution order in the "When sending mail, check names using these address lists in the following order" list.
Subscribe to:
Posts (Atom)