The new
MSN Search (beta) was released today. I'll have to play with it for a few days before I'm convinced to give up
Google. It is exciting, though, to see some competition develop. We should start seeing some rapid improvements in both MSN Search and Google. Hooray for free enterprise!
I just got a new Suunto N3 SPOT Watch yesterday and I’m already in love with it. News, Weather, Sports (Go Red Sox!), and even my Outlook appointments all on my wrist. You can even IM my watch with MSN Messenger. These are the coolest things ever!
Mono Beta 1 is out. Is this the begining of true interoperability? I may have to actually install a Linux distro (gasp) and try!
A few weeks ago, Jon Box blogged on enabling Visual Styles in Windows XP. Like Jon, I think using a manifest file is the best approach, although not all that elegant. Your forced to distribute the manifest file with your assembly, and if it's ever deleted, you've lost your support for Visual Styles. A better approach would be to insert the manifest into the assembly as a resource. There are a couple of ways to accomplish this. You could use a utility like Resource Hacker, or even Visual Studio to manually insert the manifest. While this works like champ, I would really rather have Visual Studio do it for me at compile time. So, after a little Googling, I ran across this article. Very cool stuff. It's a Visual Studio add-in that creates a manifest file at compile time and places it in the same folder as the compiled assembly (bin\debug or bin\release). Now with a couple of little tweaks and a few API calls, I could create an add-in that does exactly what I want, insert the manifest directly into the assembly as a resource at compile time. Here are the API calls I used:
<DllImport(
"KERNEL32.DLL", EntryPoint:="BeginUpdateResourceW", SetLastError:=True, CharSet:=CharSet.Unicode)> _
Public Shared Function BeginUpdateResource( _
<MarshalAs(UnmanagedType.LPWStr)> ByVal pFileName As String, _
ByVal bDeleteExistingResources As Int32 _
) As IntPtr
End Function
<DllImport(
"KERNEL32.DLL", EntryPoint:="UpdateResourceW", SetLastError:=True, CharSet:=CharSet.Unicode)> _
Public Shared Function UpdateResource( _
ByVal hUpdate As IntPtr, _
ByVal lpType As Int32, _
ByVal lpName As Int32, _
ByVal wLanguage As Int32, _
<MarshalAs(UnmanagedType.LPStr)> ByVal lpData As String, _
ByVal cbData As Int32 _
) As Int32
End Function
<DllImport(
"KERNEL32.DLL", EntryPoint:="EndUpdateResourceW", SetLastError:=True, CharSet:=CharSet.Unicode)> _
Public Shared Function EndUpdateResource( _
ByVal hUpdate As IntPtr, _
ByVal fDiscard As Int32 _
) As Int32
End Function
Rather than show you the changes I made to the add-in code, I'll leave it up to you to implement it however you like, After all, I don't want to spoil your fun. I will say this:
First, call BeginUpdateResource to get a IntPtr to the Assembly.
Then pass that IntPtr and the contents of the manifest to UpdateResource. (lpType should equal 24 for a manifest, and lpName should be 1.)
Finally, call EndUpdateResource to close the Assembly and save the changes.
And there you have it. A Visual Studio add-in that creates a manifest and inserts it as a resource at compile time.
One of my coworkers was looking for a way to iterate MAC Addresses on the current machine. After a little research, here is what he came up with.
Dim mc As System.Management.ManagementClass
Dim mo As ManagementObject
mc = New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim moc As ManagementObjectCollection = mc.GetInstances()
For Each mo In moc
If mo.Item("IPEnabled") = True Then
ListBox1.Items.Add("MAC address " & mo.Item("MacAddress").ToString())
End If
Next
Personally, I haven’t found a need for this yet, but I figured I’d better write it down for future reference.
Registration
for DevDays 2004 is now open!
I
will be conducting some of the sessions in the Web Development Track in Memphis on March 9th.
Be sure to register. It should be very educational for all involved (myself included).
I've been using a great tool from SysInternals called DebugView. From their website:
DebugView is an application that lets you monitor debug output on your local system, or any computer on the network that you can reach via TCP/IP. It is capable of displaying both kernel-mode and Win32 debug output, so you don’t need a debugger to catch the debug output your applications or device drivers generate, nor do you need to modify your applications or drivers to use non-standard debug output APIs.
So what does this mean to .NET developers? I have a Web Service which is deployed on a remote machine and I've placed Trace.WriteLine() calls throughout the code. With DebugView, I can watch my traces fire, in real time, from any machine on the network. With the timestamp and log to file features, I can even use it to gather performance metrics. Very cool! And by using Trace methods instead of Debug, I don't loose any trace information if I compile for Release.
Needless to say, I've found it very useful, and can't recommend it highly enough.
Wow. Almost two months since I've posted! Sorry.
I ran into a very interesting problem with setting “Variant” properties via COM Interop. It turns out that if you do:
MyComObject.VariantProperty = “value”
you will get a Type Mismatch error. But if you say:
MyComObject.let_VariantProperty(“value”)
everything works just fine. Microsoft has verified this is a bug and published the details here. Be sure to notice the following note at the end of the article:
If a variant type variable is declared as Public in a class module, Visual Basic implicitly creates Let, Get, and Set accessor methods for this property.
Saw a very good presentation at this week's Memphis .NET Users' Group meeting. Jerry Dixon of Quilogy spoke about SQLXML, XSLT, and .NET. He tied them all together quite nicely. You can get the presentation and demos here. Sorry about the lack of a link for Jerry, we have to get this guy blogging!
There are times, I suppose, when you may not want some fields in a class to serialize. You may have data needed for internal processing which should not be passed via a Web Service. Using attributes, you can instruct the serializer to ignore this data. Take the following Customer class for example.
|
Imports System.Xml.Serialization
Public Class Customer
Public Name As String
Public Address As String
<XmlIgnore()> Public CustomerID As Integer
End Class |
When using this class internally, we may be using the Customer ID to reference Orders, etc. But we may not need, or even want, a business partner who is accessing our web service to know this information. When the above class serializes, the CustomerID field will be ignored and will not be included in the web service's XML response message.
Normally, enumerations serialize as their numeric values like this:
<EnumVal>0</EnumVal>
You can override this behavior in your code by adding XmlEnum Attributes to your enum definition.
|
Public Enum ApplicationStatus
<XmlEnum("OK")> OK = 0
<XmlEnum("CustomerPresent")> CustomerPresent = 1
<XmlEnum("OutOfService")> OutOfService = 2
End Enum |
Now when this value serializes, it will look like this:
<EnumVal>OK</EnumVal>
Here’s a mostly useless bit of code that someone may find a use for. It will generate VB.NET class code based on the results of a SQLDataReader call. I used it to generate custom classes in situations where I could not pass a DataReader.
|
Dim ClassText As String
Dim sqCon As New SqlConnection(“Your Connection String”)
sqCon.Open()
Dim cm As New SqlCommand(“Some SQL Command”, sqCon)
cm.CommandType = CommandType.Text
Dim rd As SqlDataReader = cm.ExecuteReader()
ClassText = "Public Class Test1" + vbCrLf
For i As Integer = 0 To rd.FieldCount - 1
ClassText += vbTab + "Public " + rd.GetName(i) + _
" As " + rd.GetFieldType(i).Name + vbCrLf
Next
ClassText += "End Class"
sqCon.Close() |
Now you’ll have ClassText equal to something like:
Public Class Test1
Public status As String
Public flr As Int16
Public bal As Decimal
Public gnr_num As Int32
Public departure_date As DateTime
Public guarantor_ind As Boolean
End Class
It's pretty much been beaten into our heads that caching external data in an ASP.NET app where you can provides a significant performance boost. But what do you do when that external data occasionally changes? Are you forced to make an expensive round trip to the database every time you need it? No, I say! Add it to the cache with an expiration time and a callback which refreshes itself.
Here is an example of a Utility Class which does just that. It can be added to any ASP.NET Application and will provide a Shared Property that is automatically refreshed every hour. Nifty.