I want to use GetClusterInformation() function to get the version of MSCS .
below is the code snippet I am trying. Any help is much appreciated.
public static class Test_LoadLibrary
{
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Unicode)]
static extern IntPtr LoadLibrary(string lpFileName);
[DllImport("kernel32.dll")]
public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool FreeLibrary(IntPtr hModule);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate IntPtr TestOpenCluster(string computerName);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void MyFunctionDelegate(IntPtr frame, string ClusterName, ref uint dword, ref CLUSTERVERSIONINFO pclusterInfo);
[StructLayout(LayoutKind.Sequential)]
public class CLUSTERVERSIONINFO {
public uint dwVersionInfoSize;
public ushort MajorVersion;
public ushort MinorVersion;
public ushort BuildNumber;
public char[] szVendorId;
public char[] szCSDVersion;
public uint dwClusterHighestVersion;
public uint dwClusterLowestVersion;
public uint dwFlags;
public uint dwReserved;
CLUSTERVERSIONINFO()
{
szCSDVersion = new char[64];
szVendorId = new char[64];
}
}
public static void LosdLibraryTest()
{
try
{
IntPtr hExe = LoadLibrary("clusapi.dll");
if (hExe == IntPtr.Zero)
{
Console.WriteLine("Cannot open clusapi.dll ");
}
else
{
Console.WriteLine("open clusapi.dll " + hExe.ToString());
IntPtr pAddressOfFunctionToCall = GetProcAddress(hExe, "OpenCluster");
Console.WriteLine("open GetProcAddress " + pAddressOfFunctionToCall.ToString());
TestOpenCluster multiplyByTen = (TestOpenCluster)Marshal.GetDelegateForFunctionPointer(
pAddressOfFunctionToCall,
typeof(TestOpenCluster));
IntPtr resdult = multiplyByTen(null);
Console.WriteLine("OpenCluster" + resdult.ToString());
IntPtr ptrClusterInfo = GetProcAddress(hExe, "GetClusterInformation");
MyFunctionDelegate drs = (MyFunctionDelegate)Marshal.GetDelegateForFunctionPointer(ptrClusterInfo, typeof(MyFunctionDelegate));
uint value = 0;
CLUSTERVERSIONINFO info = new CLUSTERVERSIONINFO();
drs(pAddressOfFunctionToCall, "testServer", ref value, ref info);
Console.WriteLine(info.BuildNumber);
Console.WriteLine(info.MajorVersion);
bool freeresult = FreeLibrary(hExe);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message+ex.StackTrace);
}
Console.ReadLine();
}
}