How does the “Using” statement translate from C# to VB?

Using has virtually the same syntax in VB as C#, assuming you’re using .NET 2.0 or later (which implies the VB.NET v8 compiler or later). Basically, just remove the braces and add a “End Using” Dim bitmap as New BitmapImage() Dim buffer As Byte() = GetHugeByteArrayFromExternalSource() Using stream As New MemoryStream(buffer, false) bitmap.BeginInit() bitmap.CacheOption = … Read more

Setting up a build dependency without using a reference?

Right click the root node in Solution Explorer -> Properties -> Project Dependencies. (VS 2008 users: this feature gets its own dialog box that’s directly accessible from the context menu.) The dependency graph is represented as an adjacency list of checkboxes. Each project you select will have its direct references checked & disabled [assuming you … Read more

How do I print to the debug output window in a Win32 app?

You can use OutputDebugString. OutputDebugString is a macro that depending on your build options either maps to OutputDebugStringA(char const*) or OutputDebugStringW(wchar_t const*). In the later case you will have to supply a wide character string to the function. To create a wide character literal you can use the L prefix: OutputDebugStringW(L”My output string.”); Normally you … Read more

ERROR : [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

If you’re working with an x64 server, keep in mind that there are different ODBC settings for x86 and x64 applications. The “Data Sources (ODBC)” tool in the Administrative Tools list takes you to the x64 version. To view/edit the x86 ODBC settings, you’ll need to run that version of the tool manually: %windir%\SysWOW64\odbcad32.exe (%windir% … Read more

Using HashSet in C# 2.0, compatible with 3.5

Here’s one I wrote for 2.0 that uses a Dictionary<T, object> internally. It’s not an exact match of the 3.5 HashSet<T>, but it does the job for me. using System; using System.Collections; using System.Collections.Generic; using System.Runtime.Serialization; public class HashSet<T> : ICollection<T>, ISerializable, IDeserializationCallback { private readonly Dictionary<T, object> dict; public HashSet() { dict = new … Read more