Hi,
I'm so confused with this problem for a long time.
The program goes well on 32-bit system, such as: Windows server 2003, Windows server 2008, Windows XP and Windows 7.
Now I'd like to run the program on 64-bit system.
Each time the program interupt with the same exception:
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Here is the code.
const int HOSTPORT = 902;
const string diskPath = "[datastore1] UBUNTU/UBUNTU.vmdk";
// const string libdir = "C:\\Program Files\\VMware\\VMware Virtual Disk Development Kit";
VixDiskLibConnectParams cnxParams = new VixDiskLibConnectParams();
cnxParams.serverName = "10.10.0.227";
cnxParams.credType = VixDiskLibCredType.VIXDISKLIB_CRED_UID;
cnxParams.creds.uid.userName = "root";
cnxParams.creds.uid.password = "******";
cnxParams.port = HOSTPORT;
ulong vixError = vixDisk.Init(1,
0,
null, null, null,
null);
if (vixError != 0)
{
MessageBox.Show(vixDisk.GetErrorText(vixError, null));
return;
}
IntPtr pConnection = IntPtr.Zero;
GCHandle.Alloc(pConnection);
vixError = vixDisk.Connect(cnxParams, out pConnection); // Exception occures here.
if (vixError != 0 || pConnection.Equals(null))
{
MessageBox.Show(vixDisk.GetErrorText(vixError, null));
return;
}
IntPtr pDiskhandle = IntPtr.Zero;
pDiskhandle = Marshal.AllocHGlobal(8);
GCHandle.Alloc(pDiskhandle);
vixError = vixDisk.Open(pConnection, diskPath, VIXDISKLIB_FLAG_OPEN_READ_ONLY, out pDiskhandle);
if (vixError != 0 || pDiskhandle.Equals(null))
{
MessageBox.Show("ERROR: There was an error opening the disk using vixDisk API's");
MessageBox.Show(vixDisk.GetErrorText(vixError, null));
return;
}
vixError = vixDisk.Close(pDiskhandle);
if (vixError != 0)
{
MessageBox.Show("ERROR: There was an error closing the disk using vixDisk API's");
return;
}
// releases all resources held by VixDiskLib
vixDisk.Exit();
The wrapper is:
[DllImport("vixDiskLib.dll", ExactSpelling = true, EntryPoint = "VixDiskLib_Connect")]
public static extern System.UInt64
Connect(VixDiskLibConnectParams connectParams,
out IntPtr connection);
Please let me know if you need any more information.
Thanks in Advance,
Yangyang