Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 179681

VDDK 5.1 and C#.Net

$
0
0

Hello,

I try to use the VDDK to access the VMDK of a virtual machine managed by vCenter. Here is the C#.Net code:

 

public enum VixDiskLibCredType: int
{
VIXDISKLIB_CRED_UID = 1,
VIXDISKLIB_CRED_SESSIONID = 2,
VIXDISKLIB_CRED_TICKETID = 3,
VIXDISKLIB_CRED_SSPI = 4,
VIXDISKLIB_CRED_UNKNOWN = 256,
}

 

[StructLayoutAttribute(LayoutKind.Explicit)]
public struct VixDiskLibConnectParams
{
[MarshalAsAttribute(UnmanagedType.LPStr)]
[FieldOffset(0)]
public string vmxSpec;
[MarshalAsAttribute(UnmanagedType.LPStr)]
[FieldOffset(4)]
public string serverName;
[MarshalAsAttribute(UnmanagedType.LPStr)]
[FieldOffset(8)]
public string thumbPrint;
[FieldOffset(12)]
public long privateUse;
[FieldOffset(20)]
public VixDiskLibCredType credType;
[FieldOffset(24)]
[MarshalAsAttribute(UnmanagedType.LPStr)]
public string userName;
[FieldOffset(28)]
[MarshalAsAttribute(UnmanagedType.LPStr)]
public string password;
[FieldOffset(36)]
public uint port;
}

 

[DllImport("vixDiskLib.dll", SetLastError = true)]
public static extern VixError VixDiskLib_Connect(ref VixDiskLibConnectParams connectParams, IntPtr connection);

 

 

Everytime I call VixDiskLib_Connect, I get a VIX_E_INVALID_ARG error. I've tried to connect to vCenter 4.1, vCenter 5.0, vCenter 5.1 and ESX 4.1.0. So I assume, that there may be a problem with the data structure. But in my opinion the offsets should be corrent and the length (40 bytes) should be correct too...

This is the code I use:

 

VixDiskLibConnectParams connectParams = new VixDiskLibConnectParams();
connectParams.serverName = ServiceInstance.ConnectedToHost;
connectParams.credType = VixDiskLibCredType.VIXDISKLIB_CRED_UID;
connectParams.userName = "user";
connectParams.password = "pass";
connectParams.port = 902;
connectParams.vmxSpec = @"moref=" + virtualMachine.ManagedObjectReference.Value;

 

VixError err = VddkWrapper_5_1.NativeMethods.VixDiskLib_InitEx(5, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, string.Empty, string.Empty);

 

if (err != VixError.VIX_OK) MessageBox.Show("VixDiskLib_Init:" + err.ToString());

 

IntPtr connectionHandle = Marshal.AllocHGlobal(4);

 

err = VddkWrapper_5_1.NativeMethods.VixDiskLib_Connect(ref connectParams, connectionHandle);
if (err != VixError.VIX_OK) MessageBox.Show("VixDiskLib_Connect:" + err.ToString()); //ERROR VIX_E_INVALID_ARG

 

These are the values in the connectParams structure, they seem ok to me:

 

 

credType VIXDISKLIB_CRED_UID VddkWrapper_5_1.VixDiskLibCredType
password "password" string
port 902 uint
privateUse 0 long
serverName "vcenter-5.domain.local" string
thumbPrint null string
userName "user" string
vmxSpec "moref=vm-321" string

 

can anybody help or give an advise?

 

Thanks in advance,

Eric


Viewing all articles
Browse latest Browse all 179681

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>