API in .NET

GetShortPathName

This is very helpful in getting files to work with mciSendString. Unless you installed your application in folders without spaces, they won't work with mciSendString, as any space that is passed in to the lpstrCommand will be interpreted as the separator between command words.
Of course, before we can use it, we must declare it properly, according to the main rule behind .NET API functions. GetShortPathName
The Long in VB6 code must be converted to an Integer.
Now, the VB6 declaration looks like this:
Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, _
ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Our VB.NET declaration should look like this:
Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, _
ByVal lpszShortPath As String, ByVal cchBuffer As Integer) As Integer
The usage is not simply passing a string to GetShortPathName and it spitting out a return value with the shortened path name. You have to actually make a string buffer that the result will be pasted onto. It is important to make your buffer long enough so that the file can actually fit in it. Typically, no filename should be longer than 256 characters, but 128 will work for most purposes. Now, first our buffer will be declared and filled with an appropriate number of strings. These can be any character really, but strings look nicer as a buffer.
        Dim SPN As String
        SPN = "".PadRight(256, " "c)

Now, we are ready to call GetShortPathName. The first argument to GetShortPathName is the filename that we wish to condense... typically Application.StartupPath, although if you need a distant folder's shortened name, then you'd put that instead. The second argument is the string-character-filled buffer that we just created. When the function returns, each character will be "replaced" by the correct character in the shortened path name, leaving the shortened path name in the (now modified) buffer. The third argument is the length of the buffer that the shortened path string will be copied to. This value should be one less, because GetShortPathName will tack on an extra null character at the end of the string (we'll get to that in a minute). The function can now be called (the return value is negligible).
	GetShortPathName(Application.StartupPath, SPN, 255)

Now, the shortened path name is in SPN. We're finished, right?
Of course not. As you probably could tell by my pretentious question, we are not finished. As mentioned above, GetShortPathName tacks on a null character at the end of the string that we receive from it. In a MessageBox.Show, you would actually see the shortened path name, but when you decide to concatenate something to the end of it, say:
        mciSendString("OPEN " & SPN.ToLower & "\FF2p.mid TYPE SEQUENCER ALIAS theworld", String.Empty, 0, 0)

Only the part of the string up to the null character will be interpreted, i.e. we'll only see "OPEN C:\DOCUME~1\OWNER\MYDOCU~1\SOMESU~1\FF2p.MID". We have to get that null character out of our string. This can be done by a simple .IndexOf and .Substring operation. First, we use .IndexOf to find the location of the null character in the shortened path name (.Length will not work as it includes the rest of the spaces that we used for padding).
        Dim StrEndLoc As Integer = SPN.IndexOf(Convert.ToChar(0))

Next, we use .SubString to get everything that came before it:
        SPN = SPN.Substring(0, StrEndLoc)

And now, our shortened path name does not contain a null character and can be concatenated with anything:
        mciSendString("OPEN " & SPN.ToLower & "\FF2p.mid TYPE SEQUENCER ALIAS theworld", String.Empty, 0, 0)