Advertisement

03.25.2008 at 11:09AM PDT, ID: 23267982
[x]
Attachment Details

MicroSoft, .Net, 2005, J#  GetDiskGeometry

Asked by dcrackel in Visual Studio .NET 2005, .NET, Microsoft Visual C++.Net

Tags: MicroSoft, .Net, 2005, J#

How do you get the DISK_GEOMETRY in J#

Below is my Example, but I get:
java.lang.IllegalArgumentException: No PInvoke conversion exists for value passed to Object-typed parameter.
   at com.ms.win32.Kernel32.DeviceIoControl<PInvokeHelper>kernel32(Int32 hDevice, Int32 dwIoControlCode, Object lpInBuffer, Int32 nInBufferSize, Object lpOutBuffer, Int32 nOutBufferSize, Int32[] lpBytesReturned, OVERLAPPEDHelper lpOverlapped)
   at com.ms.win32.Kernel32.DeviceIoControl(Int32 hDevice, Int32 dwIoControlCode, Object lpInBuffer, Int32 Object lpOutBuffer, Int32 nOutBufferSize, Int32[] lpBytesReturned, OVERLAPPED lpOverlapped)

My guess is it doesn't like the DISK_GEOMETRY Class I made since I can't make a struct in J#?

Thank you for your helpStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
import System.*;
import System.Runtime.InteropServices.*;
 
public class Test
{
 	private static final int IOCTL_DISK_GET_DRIVE_GEOMETRY = 0x0070000;
	private static final int INVALID_HANDLE_VALUE = -1;
 
 
	private class DISK_GEOMETRY
	{
		public long Cylinders;
		public int MediaType;
		public int TracksPerCylinder;
		public int SectorsPerTrack;
		public int BytesPerSector;
	}
 
	public Test()
	{
 
	}
 
	public DISK_GEOMETRY getDriveGeometry(DISK_GEOMETRY pdg)
	{
		int hDevice;
		boolean bResult;
		int[] junk = new int[0];
		com.ms.win32.OVERLAPPED lpOverlapped = null;
		com.ms.win32.SECURITY_ATTRIBUTES lpSecurity = null;
 
		hDevice = com.ms.win32.Kernel32.CreateFile("\\\\.\\PhysicalDrive0", com.ms.win32.wing.GENERIC_READ, com.ms.win32.winf.FILE_SHARE_READ, lpSecurity, com.ms.win32.wino.OPEN_EXISTING, 0, 0);
 
 
		if (hDevice == INVALID_HANDLE_VALUE) 
		{
			return null;
		}
 
		bResult = com.ms.win32.Kernel32.DeviceIoControl(hDevice, IOCTL_DISK_GET_DRIVE_GEOMETRY, null, 0, pdg, 192, junk, lpOverlapped);
 
		com.ms.win32.Kernel32.CloseHandle(hDevice);
 
		return pdg;
	}
 
	public void getDriveGeometryStart()
	{
		DISK_GEOMETRY pdg = new DISK_GEOMETRY();
		boolean bResult;
		long DiskSize;
 
		pdg = getDriveGeometry(pdg);
 
		if (pdg != null) {
			System.out.println("Cylinders = " + pdg.Cylinders);
			System.out.println("Tracks per cylinder = " + (long)pdg.TracksPerCylinder);
			System.out.println("Sectors per track = "+ (long)pdg.SectorsPerTrack);
			System.out.println("Bytes per sector = " + (long)pdg.BytesPerSector);
 
			DiskSize = pdg.Cylinders * (long)pdg.TracksPerCylinder * (long)pdg.SectorsPerTrack * (long)pdg.BytesPerSector;
 
			System.out.println("Disk size = %I64d (Bytes) = " + DiskSize + " " + DiskSize / (1024 * 1024));
		} else {
			System.out.println("Attempt to get drive geometry failed.");
		} 
 
 
	}
 
}
 
	public static void main(String[] args)
	{
                System.out.println("Starting...");
		try{
 
			Test test = new Test();
			test.getDriveGeometryStart();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
 
		System.out.println("Complete!");
	}
}
 
 
[+][-]03.25.2008 at 11:35AM PDT, ID: 21204676

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Visual Studio .NET 2005, .NET, Microsoft Visual C++.Net
Tags: MicroSoft, .Net, 2005, J#
Sign Up Now!
Solution Provided By: TheLearnedOne
Participating Experts: 1
Solution Grade: A
 
 
[+][-]06.26.2008 at 07:29PM PDT, ID: 21880619

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]06.30.2008 at 06:33PM PDT, ID: 21904414

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628