Figures
© 2004 Microsoft Corporation. All rights reserved.
Figure 2 Overriding MSLU's LoadCursorW
HCURSOR __stdcall
MyLoadCursorW(HINSTANCE hInstance, LPCWSTR lpCursorName)
{

    // Make sure this lpCursorName is a valid string
    if((ULONG_PTR)lpCursorName > 0xffff)
    {
        size_t cchCursorName = wcslen(lpCursorName) + 1;
        LPSTR lpCursorNameAnsi = _alloca(cchCursorName*2);

        WideCharToMultiByte(CP_ACP,
                            0,
                            lpCursorName,
                            cchCursorName,
                            lpCursorNameAnsi,
                            cchCursorName*2,
                            NULL,
                            NULL);
        return(LoadCursorA(hInstance, lpCursorNameAnsi));
    }
    return(LoadCursorA(hInstance, (LPCSTR)lpCursorName));
}
Figure 3 Managed C++ Sample
#using <mscorlib.dll>
using namespace System;
using namespace System::Text;
using namespace System::Runtime::InteropServices;

typedef unsigned __int32 UINT;

public class SystemAPI 
{
    [DllImport("kernel32")]
    extern "C" UINT GetVersion();

    [DllImport("kernel32", EntryPoint="GetSystemDirectoryW", 
        CharSet=CharSet.Unicode)]
    extern "C" UINT OsGetSystemDirectoryW(StringBuilder *lpBuf, 
        UINT uSize);
    [DllImport(" unicows.dll", EntryPoint="GetSystemDirectoryW", 
        CharSet=CharSet.Unicode)]
    extern "C" UINT MsluGetSystemDirectoryW(StringBuilder *lpBuf, 
        UINT uSize);
	
    public static UINT GetSystemDirectory(StringBuilder *lpBuf, 
        UINT uSize)
    {
        if(GetVersion() < 0x80000000)
            return(OsGetSystemDirectoryW(lpBuf, uSize));
        else
            return(MsluGetSystemDirectoryW(lpBuf, uSize));
    }
}
Figure 4 C# Sample
using System;
using System.Text;
using System.Runtime.InteropServices;

public class SystemAPI 
{
    [DllImport("kernel32")]
    private static extern uint GetVersion();

    [DllImport("kernel32", EntryPoint="GetSystemDirectoryW", 
        CharSet=CharSet.Unicode)]
    private static extern uint OsGetSystemDirectoryW(StringBuilder lpBuf,
         uint uSize);
    [DllImport("unicows.dll", EntryPoint="GetSystemDirectoryW", 
        CharSet=CharSet.Unicode)]
    private static extern uint MsluGetSystemDirectoryW(StringBuilder 
        lpBuf, uint uSize);
	
    public static uint GetSystemDirectory(StringBuilder lpBuf, uint 
        uSize)
    {
        if(GetVersion() < 0x80000000)
            return(OsGetSystemDirectoryW(lpBuf, uSize));
        else
            return(MsluGetSystemDirectoryW(lpBuf, uSize));
    }
}
Figure 5 Visual Basic .NET Sample
Imports System
Imports System.Text
Imports System.Runtime.InteropServices

Public Class SystemAPI
    Declare Function GetVersion Lib "kernel32" () As Integer

    Declare Unicode Function OsGetSystemDirectoryW Lib "kernel32" _
     Alias "GetSystemDirectoryW" _
     (ByVal lpBuf As StringBuilder, ByVal uSize As Integer) As Integer
    Declare Unicode Function MsluGetSystemDirectoryW Lib "unicows.dll" _
     Alias "GetSystemDirectoryW" _
     (ByVal lpBuf As StringBuilder, ByVal uSize As Integer) As Integer

    Public Function GetSystemDirectory _
     (ByVal lpBuf As StringBuilder, ByVal uSize As Integer) As Integer
        If (GetVersion() > &H80000000) Then
            GetSystemDirectory = OsGetSystemDirectoryW(lpBuf, uSize)
        Else
            GetSystemDirectory = MsluGetSystemDirectoryW(lpBuf, uSize)
        End If
    End Function
End Class
Page view tracker