Jump to content

SUBIECTE NOI
« 1 / 5 »
RSS
Incalzire casa fara gaz/lemne

Incalzire in pardoseala etapizata

Suprataxa card energie?!

Cum era nivelul de trai cam din a...
 probleme cu ochelarii

Impozite pe proprietati de anul v...

teava rezistenta panou apa calda

Acces in Curte din Drum National
 Sub mobila de bucatarie si sub fr...

Rezultat RMN

Numar circuite IPAT si prindere t...

Pareri brgimportchina.ro - teapa ...
 Lucruri inaintea vremurilor lor

Discuții despre TVR Sport HD.

Cost abonament clinica privata

Tremura toata, dar nu de la ro...
 

DeviceIOControl

- - - - -
  • Please log in to reply
3 replies to this topic

#1
bogdandaniel

bogdandaniel

    Junior Member

  • Grup: Members
  • Posts: 66
  • Înscris: 02.08.2002
Ma poate ajuta sa trec codul de mai jos din C in C# sau cel mai bine VB.Net


/* The code of interest is in the subroutine GetDriveGeometry. The
   code in main shows how to interpret the results of the IOCTL call. */

#include
#include

BOOL
GetDriveGeometry(DISK_GEOMETRY *pdg)
{
  HANDLE hDevice;               // handle to the drive to be examined
  BOOL bResult;                 // results flag
  DWORD junk;                   // discard results

  hDevice = CreateFile(".PhysicalDrive0", // drive to open
                       0,       // don't need any access to the drive
                       FILE_SHARE_READ | FILE_SHARE_WRITE,  // share mode
                       NULL,    // default security attributes
                       OPEN_EXISTING,  // disposition
                       0,       // file attributes
                       NULL);   // don't copy any file's attributes

  if (hDevice == INVALID_HANDLE_VALUE) // we can't open the drive
  {
    return (FALSE);
  }

  bResult = DeviceIoControl(hDevice,  // device we are querying
      IOCTL_DISK_GET_DRIVE_GEOMETRY,  // operation to perform
                             NULL, 0, // no input buffer, so pass zero
                            pdg, sizeof(*pdg),  // output buffer
                            &junk, // discard count of bytes returned
                            (LPOVERLAPPED) NULL);  // synchronous I/O

  CloseHandle(hDevice);         // we're done with the handle

  return (bResult);
}

int
main(int argc, char *argv[])
{
  DISK_GEOMETRY pdg;            // disk drive geometry structure
  BOOL bResult;                 // generic results flag
  ULONGLONG DiskSize;           // size of the drive, in bytes

  bResult = GetDriveGeometry (&pdg);

  if (bResult)
  {
    printf("Cylinders = %I64dn", pdg.Cylinders);
    printf("Tracks per cylinder = %ldn", (ULONG) pdg.TracksPerCylinder);
    printf("Sectors per track = %ldn", (ULONG) pdg.SectorsPerTrack);
    printf("Bytes per sector = %ldn", (ULONG) pdg.BytesPerSector);

    DiskSize = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *
      (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;
    printf("Disk size = %I64d (Bytes) = %I64d (Mb)n", DiskSize,
           DiskSize / (1024 * 1024));
  } else {
    printf ("Attempt to get drive geometry failed. Error %ld.n",
            GetLastError ());
  }

  return

#2
KLAMATH

KLAMATH

    Moderator

  • Grup: Members
  • Posts: 479
  • Înscris: 17.04.2002
N-am cscul la mine asa ca nu garantez  :D  ;)


public unsafe bool GetDriveGeometry(ref DISK_GEOMETRY pdg)
{
   IntPtr hDevice;
   bool bResult;
   int junk;


hDevice = CreateFile(".PhysicalDrive0", 0, FILE_SHARE_READ | FILE_SHARE_WRITE, null, OPEN_EXISTING, 0, null);
  
if (hDevice == INVALID_HANDLE_VALUE) // we can't open the drive
{
return (false);
}

bResult = DeviceIoControl(hDevice, IOCTL_DISK_GET_DRIVE_GEOMETRY, null, 0, pdg, System.Runtime.InteropServices.SizeOf(pdg), &junk, ref OVERLAPPED rf);

CloseHandle(hDevice);

}

public static void Main(string[] args)
{
DISK_GEOMETRY pdg = new DISK_GEOMETRY();
bool bResult;
ulong DiskSize;

bResult = GetDriveGeometry (ref pdg);

if (bResult)
{
Console.WriteLine("Cylinders = %I64dn", pdg.Cylinders);
Console.WriteLine("Tracks per cylinder = %ldn", (ulong) pdg.TracksPerCylinder);
Console.WriteLine("Sectors per track = %ldn", (ulong) pdg.SectorsPerTrack);
Console.WriteLine("Bytes per sector = %ldn", (ulong) pdg.BytesPerSector);

        DiskSize = pdg.Cylinders.QuadPart * (ulong)pdg.TracksPerCylinder * (ulong)pdg.SectorsPerTrack *

(ulong)pdg.BytesPerSector;
        Console.WriteLine("Disk size = %I64d (Bytes) = %I64d (Mb)n", DiskSize,DiskSize / (1024 * 1024));
}
else
{
  Console.WriteLine ("Attempt to get drive geometry failed. Error %ld.n", GetLastError ());

}

Declarerurile iti ramin tie ...tema pt acasa  :D  :cya:

#3
bogdandaniel

bogdandaniel

    Junior Member

  • Grup: Members
  • Posts: 66
  • Înscris: 02.08.2002
Imports System.Runtime.InteropServices

Imports System.Text



Public Class Form1

    Inherits System.Windows.Forms.Form



#Region " Windows Form Designer generated code "



    Public Sub New()

        MyBase.New()



        'This call is required by the Windows Form Designer.

        InitializeComponent()



        'Add any initialization after the InitializeComponent() call



    End Sub



    'Form overrides dispose to clean up the component list.

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

        If disposing Then

            If Not (components Is Nothing) Then

                components.Dispose()

            End If

        End If

        MyBase.Dispose(disposing)

    End Sub



    'Required by the Windows Form Designer

    Private components As System.ComponentModel.IContainer



    'NOTE: The following procedure is required by the Windows Form Designer

    'It can be modified using the Windows Form Designer.  

    'Do not modify it using the code editor.

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

        '

        'Form1

        '

        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

        Me.ClientSize = New System.Drawing.Size(740, 273)

        Me.Name = "Form1"

        Me.Text = "Form1"



    End Sub



#End Region



    Private Const DFP_GET_VERSION As Integer = &H74080

    Private Const DFP_SEND_DRIVE_COMMAND As Integer = &H7C084

    Private Const DFP_RECEIVE_DRIVE_DATA As Integer = &H7C088

    Private Const GENERIC_READ As Integer = &H80000000

    Private Const GENERIC_WRITE As Integer = &H40000000

    Private Const IDE_ATAPI_ID As Integer = &HA1               ' Returns ID sector for ATAPI.

    Private Const IDE_ID_FUNCTION As Integer = &HEC           ' Returns ID sector for ATA.

    Private Const IDE_EXECUTE_SMART_FUNCTION As Integer = &HB0 ' Performs SMART cmd.

    Public Const MAX_IDE_DRIVES As Integer = 4        ' // Max number of drives assuming primary/secondary, master/slave topology

    Public Const READ_ATTRIBUTE_BUFFER_SIZE As Integer = 512

    Public Const IDENTIFY_BUFFER_SIZE As Integer = 512

    Public Const READ_THRESHOLD_BUFFER_SIZE As Integer = 512

    Public Const OUTPUT_DATA_SIZE As Integer = IDENTIFY_BUFFER_SIZE + 16

    Private Const FILE_SHARE_READ As Short = &H1S

    Private Const FILE_SHARE_WRITE As Short = &H2S

    Private Const OPEN_EXISTING As Short = 3

    Private Const FILE_ATTRIBUTE_SYSTEM As Short = &H4S

    Private Const CREATE_NEW As Short = 1

    Private Const IOCTL_STORAGE_CHECK_VERIFY2 As Integer = &H2D0800

    Private Const FILE_READ_ATTRIBUTES As Integer = &H80

    Private Const IOCTL_DISK_GET_DRIVE_GEOMETRY As Integer = &H70000



    Public di As DRIVE_INFO



    Private Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Integer, ByVal dwIoControlCode As Integer, ByRef lpInBuffer As IntPtr, ByVal nInBufferSize As Integer, ByRef lpOutBuffer As IntPtr, ByVal nOutBufferSize As Integer, ByRef lpBytesReturned As Integer, ByVal lpOverlapped As IntPtr) As Integer

    Private Declare Ansi Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Integer, ByVal dwIoControlCode As Integer, ByVal lpInBuffer As Integer, ByVal nInBufferSize As Integer, ByRef lpOutBuffer As Integer, ByVal nOutBufferSize As Integer, ByRef lpBytesReturned As Integer, ByVal lpOverlapped As Integer) As Integer

    Private Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Integer, ByVal dwIoControlCode As Integer, ByRef lpInBuffer As IntPtr, ByVal nInBufferSize As Integer, ByRef lpOutBuffer As DISK_GEOMETRY, ByVal nOutBufferSize As Integer, ByRef lpBytesReturned As Integer, ByVal lpOverlapped As IntPtr) As Integer

    Private Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Integer, ByVal dwIoControlCode As Integer, ByRef lpInBuffer As IntPtr, ByVal nInBufferSize As Integer, ByRef lpOutBuffer As GETVERSIONOUTPARAMS, ByVal nOutBufferSize As Integer, ByRef lpBytesReturned As Integer, ByVal lpOverlapped As IntPtr) As Integer

    'Pentru DFP_RECEIVE_DRIVE_DATA

    Private Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Integer, ByVal dwIoControlCode As Integer, ByRef lpInBuffer As SENDCMDINPARAMS, ByVal nInBufferSize As Integer, ByRef lpOutBuffer As IntPtr, ByVal nOutBufferSize As Integer, ByRef lpBytesReturned As Integer, ByVal lpOverlapped As IntPtr) As Integer

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

    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Integer) As Integer

    Private Declare Ansi Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef i As OSVERSIONINFO) As Boolean

    Private Declare Function GetLastError Lib "kernel32" Alias "GetLastError" () As Integer

    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal Destination As IDSECTOR, ByVal Source As Byte, ByVal Length As Long)



    Structure GETVERSIONOUTPARAMS

        Dim bVersion As Byte       ' Binary driver version.

        Dim bRevision As Byte      ' Binary driver revision.

        Dim bReserved As Byte      ' Not used.

        Dim bIDEDeviceMap As Byte  ' Bit map of IDE devices.

        Dim fCapabilities As Integer  ' Bit mask of driver capabilities.

        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=3)> _

        Dim dwReserved() As Integer

    End Structure



    Structure IDEREGS

        Dim bFeaturesReg As Byte     ' // Used for specifying SMART "commands".

        Dim bSectorCountReg As Byte  ' // IDE sector count register

        Dim bSectorNumberReg As Byte ' // IDE sector number register

        Dim bCylLowReg As Byte       ' // IDE low order cylinder value

        Dim bCylHighReg As Byte      ' // IDE high order cylinder value

        Dim bDriveHeadReg As Byte    ' // IDE drive/head register

        Dim bCommandReg As Byte      ' // Actual IDE command.

        Dim bReserved As Byte        ' // reserved for future use.  Must be zero.

    End Structure



    Structure IDSECTOR

        Dim wGenConfig As Short

        Dim wNumCyls As Short

        Dim wReserved As Short

        Dim wNumHeads As Short

        Dim wBytesPerTrack As Short

        Dim wBytesPerSector As Short

        Dim wSectorsPerTrack As Short

        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> _

        Dim wVendorUnique() As Short

        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=19)> _

        Dim sSerialNumber() As Byte

        Dim wBufferType As Short

        Dim wBufferSize As Short

        Dim wECCSize As Short

        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=7)> _

        Dim sFirmwareRev() As Byte

        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=39)> _

        Dim sModelNumber() As Byte

        Dim wMoreVendorUnique As Short

        Dim wDoubleWordIO As Short

        Dim wCapabilities As Short

        Dim wReserved1 As Short

        Dim wPIOTiming As Short

        Dim wDMATiming As Short

        Dim wBS As Short

        Dim wNumCurrentCyls As Short

        Dim wNumCurrentHeads As Short

        Dim wNumCurrentSectorsPerTrack As Short

        Dim ulCurrentSectorCapacity As Long

        Dim wMultSectorStuff As Short

        Dim ulTotalAddressableSectors As Long

        Dim wSingleWordDMA As Short

        Dim wMultiWordDMA As Short

        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=127)> _

        Dim bReserved() As Byte

    End Structure



    Structure SENDCMDINPARAMS

        Dim cBufferSize As Integer          ' Buffer size in bytes

        Dim irDriveRegs As IDEREGS      ' Structure with drive register values.

        Dim bDriveNumber As Byte        ' Physical drive number to send command to (0,1,2,3).

        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=3)> _

        Dim bReserved() As Byte        ' Bytes reserved

        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=4)> _

        Dim dwReserved() As Integer       ' DWORDS reserved

        Dim bBuffer As Byte           ' Input buffer.

    End Structure



    Public Enum STATUS_FLAGS

        PRE_FAILURE_WARRANTY = &H1

        ON_LINE_COLLECTION = &H2

        PERFORMANCE_ATTRIBUTE = &H4

        ERROR_RATE_ATTRIBUTE = &H8

        EVENT_COUNT_ATTRIBUTE = &H10

        SELF_PRESERVING_ATTRIBUTE = &H20

    End Enum



    Structure ATTR_DATA

        Dim AttrID As Byte

        Dim AttrName As String

        Dim AttrValue As Byte

        Dim ThresholdValue As Byte

        Dim WorstValue As Byte

        Dim StatusFlags As STATUS_FLAGS

    End Structure



    Structure DRIVE_INFO

        Dim bDriveType As Byte

        Dim SerialNumber As String

        Dim Model As String

        Dim FirmWare As String

        Dim Cilinders As Long

        Dim Heads As Integer

        Dim SecPerTrack As Integer

        Dim BytesPerSector As Integer

        Dim BytesperTrack As Integer

        Dim NumAttributes As Byte

        Dim Attributes() As ATTR_DATA

    End Structure



    <StructLayout(LayoutKind.Sequential)> _

Public Structure OSVERSIONINFO

        Public dwOSVersionInfoSize As Integer

        Public dwMajorVersion As Integer

        Public dwMinorVersion As Integer

        Public dwBuildNumber As Integer

        Public dwPlatformId As Integer

        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> _

        Public szCSDVersion As String

    End Structure



    Public Structure DISK_GEOMETRY

        Public Cylinders As Long

        Public MediaType As Integer

        Public TracksPerCylinder As Integer

        Public SectorsPerTrack As Integer

        Public BytesPerSector As Integer

    End Structure



    Private Sub test(ByVal VerParam As GETVERSIONOUTPARAMS, ByVal hdrive As Integer)

        di.bDriveType = 0

        di.NumAttributes = 0

        ReDim di.Attributes(0)

        If Not IsBitSet(VerParam.bIDEDeviceMap, 0) Then

            MsgBox("Not OK")

        Else

            MsgBox("OK")

        End If

    End Sub



    Private Function IsBitSet(ByVal iBitString As Byte, ByVal lBitNo As Integer) As Boolean

        If lBitNo = 7 Then

            IsBitSet = iBitString < 0

        Else

            IsBitSet = iBitString And (2 ^ lBitNo)

        End If

    End Function



    Private Function SwapStringBytes(ByVal sIn As String) As String

        Dim sTemp As String

        Dim i As Short

        sTemp = Space(Len(sIn))

        For i = 1 To Len(sIn) - 1 Step 2

            Mid(sTemp, i, 1) = Mid(sIn, i + 1, 1)

            Mid(sTemp, i + 1, 1) = Mid(sIn, i, 1)

        Next i

        SwapStringBytes = sTemp

    End Function



    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        MsgBox(GetLastError())

        Dim hdrive As Integer

        Dim VersionParams As New GETVERSIONOUTPARAMS()

        hdrive = CreateFile(".PHYSICALDRIVE0", GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero)

        Dim bytesReturned As Integer

        Dim result As Boolean

        MsgBox(GetLastError())

        result = DeviceIoControl(hdrive, DFP_GET_VERSION, IntPtr.Zero, 0, VersionParams, 24, bytesReturned, IntPtr.Zero)

        MsgBox(GetLastError())

        test(VersionParams, hdrive)

        MsgBox(GetLastError())

        Dim SCIP As SENDCMDINPARAMS

        Dim IDSEC As IDSECTOR

        Dim bArrOut(OUTPUT_DATA_SIZE - 1) As Byte

        Dim sMsg As String

        Dim lpcbBytesReturned As Integer

        Dim barrfound(100) As Integer

        Dim i As Integer

        For i = 0 To OUTPUT_DATA_SIZE - 1

            bArrOut(i) = 0

        Next

        Dim lng As Integer

        With SCIP

            .cBufferSize = IDENTIFY_BUFFER_SIZE

            .bDriveNumber = CByte(0)

            With .irDriveRegs

                .bFeaturesReg = 0

                .bSectorCountReg = 1

                .bSectorNumberReg = 1

                .bCylLowReg = 0

                .bCylHighReg = 0

                .bDriveHeadReg = &HA0S

                .bCommandReg = CByte(IDE_ID_FUNCTION)

            End With

        End With

        Dim arraySize As Integer = bArrOut.Length

        Dim buffer As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(arraySize) * bArrOut.Length)

        If DeviceIoControl(hdrive, DFP_RECEIVE_DRIVE_DATA, SCIP, 32, buffer, OUTPUT_DATA_SIZE, lpcbBytesReturned, IntPtr.Zero) Then

            Marshal.Copy(buffer, bArrOut, 0, arraySize)

        End If

        CloseHandle(hdrive)

    End Sub

End Class



Toate bune si frumoase pana la apelul ultimei functii DeviceIoControl unde toti vectorii sunt trecuti pe Nothing.  Apreciez orice sugestie pentru ca eu am ramas in pana de idei!!!

#4
bogdandaniel

bogdandaniel

    Junior Member

  • Grup: Members
  • Posts: 66
  • Înscris: 02.08.2002
Nu are nimeni idee de ce se intampla chestia asta? E din vina mea sau a Microsoftului?

Anunturi

Chirurgia spinală minim invazivă Chirurgia spinală minim invazivă

Chirurgia spinală minim invazivă oferă pacienților oportunitatea unui tratament eficient, permițându-le o recuperare ultra rapidă și nu în ultimul rând minimizând leziunile induse chirurgical.

Echipa noastră utilizează un spectru larg de tehnici minim invazive, din care enumerăm câteva: endoscopia cu variantele ei (transnazală, transtoracică, transmusculară, etc), microscopul operator, abordurile trans tubulare și nu în ultimul rând infiltrațiile la toate nivelurile coloanei vertebrale.

www.neurohope.ro

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Forumul Softpedia foloseste "cookies" pentru a imbunatati experienta utilizatorilor Accept
Pentru detalii si optiuni legate de cookies si datele personale, consultati Politica de utilizare cookies si Politica de confidentialitate