473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

can u help me solving that error(Maneged.sizeof()

i got the current project that got the serial no.of a hard disk for
software protection but i got an error,if u solve it send me,thanx
alllllll.
1.file1
Option Strict On
Option Explicit On
Imports System.Runtime.InteropServices
Public Class DriveInfo

Public Enum DriveTypes
Fixed
Removable
Unknown
End Enum

Private _serialNumber As String
Private _model As String
Private _firmware As String

Private _driveType As DriveTypes = DriveTypes.Unknown
Private _numberCylinders As Integer
Private _numberHeads As Integer
Private _sectorsPerTrack As Integer
Private _bufferSize As Integer

#Region "Win32 Interop"

_
Private Class IDEREGS
Public Features As Byte
Public SectorCount As Byte
Public SectorNumber As Byte
Public CylinderLow As Byte
Public CylinderHigh As Byte
Public DriveHead As Byte
Public Command As Byte
Public Reserved As Byte
End Class

_
Private Class SENDCMDINPARAMS

Public BufferSize As Integer
Public DriveRegs As IDEREGS
Public DriveNumber As Byte
_
Public Reserved() As Byte
_
Public Reserved2() As Integer

Public Sub New()
DriveRegs = New IDEREGS
Reserved = New Byte(2) {}
Reserved2 = New Integer(3) {}
End Sub

End Class

_
Private Class DRIVERSTATUS

Public DriveError As Byte
Public IDEStatus As Byte
_
Public Reserved() As Byte
_
Public Reserved2() As Integer

Public Sub New()
Reserved = New Byte(1) {}
Reserved2 = New Integer(1) {}
End Sub

End Class

_
Private Class IDSECTOR

Public GenConfig As Short '0
Public NumberCylinders As Short '1
Public Reserved As Short '2
Public NumberHeads As Short '3
Public BytesPerTrack As Short '4
Public BytesPerSector As Short '5
Public SectorsPerTrack As Short '6
_
Public VendorUnique() As Short '7
_
Public SerialNumber() As Char '10
Public BufferClass As Short '20
Public BufferSize As Short '21
Public ECCSize As Short '22
_
Public FirmwareRevision() As Char '23
_
Public ModelNumber() As Char '27
Public MoreVendorUnique As Short '47
Public DoubleWordIO As Short '48
Public Capabilities As Short '49
Public Reserved1 As Short '50
Public PIOTiming As Short '51
Public DMATiming As Short '52
Public BS As Short '53
Public NumberCurrentCyls As Short '54
Public NumberCurrentHeads As Short '55
Public NumberCurrentSectorsPerTrack As Short '56
Public CurrentSectorCapacity As Integer '57
Public MultipleSectorCapacity As Short '59
Public MultipleSectorStuff As Short '60
Public TotalAddressableSectors As Integer '61
Public SingleWordDMA As Short '63
Public MultiWordDMA As Short '64
_
Public Reserved2() As Byte '65

Public Sub New()
VendorUnique = New Short(2) {}
Reserved2 = New Byte(381) {}
FirmwareRevision = New Char(7) {}
SerialNumber = New Char(19) {}
ModelNumber = New Char(39) {}
End Sub

End Class

_
Private Class SENDCMDOUTPARAMS

Public BufferSize As Integer
Public Status As DRIVERSTATUS
Public IDS As IDSECTOR
Public Sub New()
Status = New DRIVERSTATUS
IDS = New IDSECTOR
End Sub

End Class

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject
As Integer) As Integer
Private Declare Function CreateFile Lib "kernel32" Alias
"CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As
Integer, ByVal dwShareMode As Integer, ByVal lpSecurityAttributes As
Integer, ByVal dwCreationDisposition As Integer, ByVal
dwFlagsAndAttributes As Integer, ByVal hTemplateFile As Integer) As
Integer

Private Declare Function DeviceIoControl Lib "kernel32" (ByVal
hDevice As Integer, ByVal dwIoControlCode As Integer, <[In](), Out()>
ByVal lpInBuffer As SENDCMDINPARAMS, ByVal nInBufferSize As Integer,
<[In](), Out()> ByVal lpOutBuffer As SENDCMDOUTPARAMS, ByVal
nOutBufferSize As Integer, ByRef lpBytesReturned As Integer, ByVal
lpOverlapped As Integer) As Integer

Private Const CREATE_NEW As Integer = 1
Private Const OPEN_EXISTING As Integer = 3

Private Const GENERIC_READ As Integer = &H80000000
Private Const GENERIC_WRITE As Integer = &H40000000

Private Const FILE_SHARE_READ As Integer = &H1
Private Const FILE_SHARE_WRITE As Integer = &H2

Private Const VER_PLATFORM_WIN32_NT As Integer = 2

Private Const DFP_RECEIVE_DRIVE_DATA As Integer = &H7C088
'Private Const IOCTL_STORAGE_MEDIA_REMOVAL As Long = &H2D4804
Private Const INVALID_HANDLE_VALUE As Integer = -1

Private Shared Function SwapChars(ByVal chars() As Char) As String
For i As Integer = 0 To chars.Length - 2 Step 2
chars.Reverse(chars, i, 2)
Next
Return New String(chars).Trim
End Function

#End Region

Public Sub New(ByVal driveNumber As Integer)

Dim result As Boolean
Dim handle As Integer
Dim returnSize As Integer
Dim sci As New SENDCMDINPARAMS
Dim sco As New SENDCMDOUTPARAMS

If Environment.OSVersion.Platform = PlatformID.Win32NT Then
'handle = CreateFile("\\.\PhysicalDrive" &
CStr(driveNumber), GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ Or
FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0)
handle = CreateFile("\\.\PhysicalDrive" &
CStr(driveNumber), GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ Or
FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0)
' handle = CreateFile("\\.\PhysicalDrive", GENERIC_READ Or
GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, 0, OPEN_EXISTING,
0, 0)
Else ' 9X
handle = CreateFile("\\.\Smartvsd", 0, 0, 0, CREATE_NEW, 0,
0)
End If

If handle <> INVALID_HANDLE_VALUE Then

sci.DriveNumber = CType(driveNumber, Byte)
'error occure in the following line
sci.BufferSize = Marshal.SizeOf(sco)
sci.DriveRegs.DriveHead = CType(&HA0 Or (driveNumber << 5),
Byte)
sci.DriveRegs.Command = &HEC
sci.DriveRegs.SectorCount = 1
sci.DriveRegs.SectorNumber = 1

' If DeviceIoControl(handle, DFP_RECEIVE_DRIVE_DATA, sci,
Marshal.SizeOf(sci), sco, Marshal.SizeOf(sco), returnSize, 0) <> 0 Then
If DeviceIoControl(handle, DFP_RECEIVE_DRIVE_DATA, sci,
Marshal.SizeOf(sci), sco, Marshal.SizeOf(sco), returnSize, 0) <> 0 Then
_serialNumber = SwapChars(sco.IDS.SerialNumber)
_model = SwapChars(sco.IDS.ModelNumber)
_firmware = SwapChars(sco.IDS.FirmwareRevision)
_numberCylinders = sco.IDS.NumberCylinders
_numberHeads = sco.IDS.NumberHeads
_sectorsPerTrack = sco.IDS.SectorsPerTrack
_bufferSize = sco.IDS.BufferSize * 512
If (sco.IDS.GenConfig And &H80) = &H80 Then
_driveType = DriveTypes.Removable
ElseIf (sco.IDS.GenConfig And &H40) = &H40 Then
_driveType = DriveTypes.Fixed
Else
_driveType = DriveTypes.Unknown
End If
End If

CloseHandle(handle)

End If

End Sub

Public ReadOnly Property SerialNumber() As String
Get
Return _serialNumber
End Get
End Property

Public ReadOnly Property Model() As String
Get
Return _model
End Get
End Property

Public ReadOnly Property Firmware() As String
Get
Return _firmware
End Get
End Property

Public ReadOnly Property NumberCylinders() As Integer
Get
Return _numberCylinders
End Get
End Property

Public ReadOnly Property NumberHeads() As Integer
Get
Return _numberHeads
End Get
End Property

Public ReadOnly Property SectorsPerTrack() As Integer
Get
Return _sectorsPerTrack
End Get
End Property

Public ReadOnly Property BufferSize() As Integer
Get
Return _bufferSize
End Get
End Property

Public ReadOnly Property DriveType() As DriveTypes
Get
Return _driveType
End Get
End Property

End Class

2.file2
Option Strict On
Option Explicit On

Class DriveInfoApp

_
Shared Sub Main()

For drive As Integer = 0 To 4
Dim info As New DriveInfo(drive)
If Not info.SerialNumber Is Nothing Then
Select Case drive
Case 0 : Console.WriteLine("Primary Controller -
Master drive")
Case 1 : Console.WriteLine("Primary Controller -
Slave drive")
Case 2 : Console.WriteLine("Secondary Controller -
Master drive")
Case 3 : Console.WriteLine("Secondary Controller -
Slave drive")
End Select
Console.WriteLine()
Console.WriteLine("Drive Model Number________________:
" & info.Model)
Console.WriteLine("Drive Serial Number_______________:
" & info.SerialNumber)
Console.WriteLine("Drive Controller Revision Number__:
" & info.Firmware)
Console.WriteLine("Controller Buffer Size on Drive___:
" & info.BufferSize)
Console.WriteLine("Drive Type________________________:
" & info.DriveType.ToString)
Console.Write("Physical Geometry: ")
Console.Write(info.NumberCylinders & " Cylinders ")
Console.Write(info.NumberHeads & " Heads ")
Console.WriteLine(info.SectorsPerTrack & " Sectors per
track")
Console.WriteLine()
End If
Next

Console.WriteLine("Press [Enter] to exit...")
Console.ReadLine()

End Sub

End Class

Nov 22 '05 #1
0 1647

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sunil Menon | last post by:
Dear All, A class having no member variables and only a method sizeof(object) will return 1byte in ANSI and two bytes in Unicode. I have the answer for this of how in works in ANSI. But I don't...
0
by: besaar | last post by:
i got the current project that got the serial no.of a hard disk for software protection but i got an error,if u solve it send me,thanx alllllll. 1.file1 Option Strict On Option Explicit On...
12
by: nib | last post by:
What kind of problems is c best at solving?
5
by: sasiraj | last post by:
#include<stdio.h> #define TOTAL_ELEMENTS (sizeof(array) / sizeof(array)) int array = {23,34,12,17,204,99,16}; int main() { int d; for(d=-1;d <= (TOTAL_ELEMENTS-2);d++)
4
by: cs | last post by:
#include <stdio.h> #include <stdlib.h> typedef struct{ unsigned a; unsigned *b; unsigned k; }tp; tp e, *ee;
16
by: Martin Jørgensen | last post by:
Hi, I've made a program from numerical recipes. Looks like I'm not allowed to distribute the source code from numerical recipes but it shouldn't even be necessary to do that. My problem is...
1
by: bparanj | last post by:
Hello, I have been a software developer for the past 10 years now. I get job descriptions that requires problem-solving skills as one of the most desirable skills in a candidate. But there are...
1
by: bparanj | last post by:
Hello, I have been a software developer for the past 10 years now. I get job descriptions that requires problem-solving skills as one of the most desirable skills in a candidate. But there are...
12
by: Zilla | last post by:
I put everything in one file for ease of use; also I have #include <*.hfiles instead of the <*since my compiler is pre-ANSI C so it needs the .h #include <iostream.h> #include <iomanip.h>...
20
by: @$|-|. DUBEY | last post by:
i have a interger val = 99999; and i want to add the content of val i.e., 9+9+9+9+9 = 45; how to do that.... need urgent help
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.