Click here to Skip to main content
15,898,035 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Folder Copying History Pin
DaveAuld7-Mar-10 2:41
professionalDaveAuld7-Mar-10 2:41 
GeneralRe: Folder Copying History Pin
Richard MacCutchan7-Mar-10 2:42
mveRichard MacCutchan7-Mar-10 2:42 
GeneralRe: Folder Copying History Pin
Dave Kreskowiak7-Mar-10 3:45
mveDave Kreskowiak7-Mar-10 3:45 
GeneralRe: Folder Copying History Pin
εїзεїзεїз7-Mar-10 10:29
εїзεїзεїз7-Mar-10 10:29 
GeneralRe: Folder Copying History Pin
Anubhava Dimri7-Mar-10 20:34
Anubhava Dimri7-Mar-10 20:34 
GeneralRe: Folder Copying History Pin
Dave Kreskowiak8-Mar-10 7:21
mveDave Kreskowiak8-Mar-10 7:21 
GeneralRe: Folder Copying History Pin
Anubhava Dimri8-Mar-10 17:53
Anubhava Dimri8-Mar-10 17:53 
QuestionSHFormatDrive error Pin
Gagan.206-Mar-10 20:55
Gagan.206-Mar-10 20:55 
Hi all...

I am trying to format my pen drive by calling API SHFormatDrive function but it gives an error message.

I am using the following lines of code :

Private Declare Function SHFormatDrive Lib "shell32" (ByVal hwnd As Long, ByVal iDrive As Long, ByVal iCapacity As Long, ByVal iFormatType As Long) As Long
    Const SHFD_CAPACITY_DEFAULT = 0 'default drive capacity
    Const SHFD_FORMAT_QUICK = 0 'Quick format.
    Const SHFD_FORMAT_FULL = 1 'Full format.

    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click

             Try
       
                Dim drvToFormat As Long = 6 '6 is the index of pendrive for G: drive.
                Dim ret As Long

                If chkQuickFormat.Checked Then 'Check for quick format.
                    ret = SHFormatDrive(Me.Handle.ToInt32, _
                    drvToFormat, _
                    SHFD_CAPACITY_DEFAULT, _
                    SHFD_FORMAT_QUICK)
                Else
                    ret = SHFormatDrive(Me.Handle.ToInt32, _
                    drvToFormat, _
                    SHFD_CAPACITY_DEFAULT, _
                    SHFD_FORMAT_FULL)
                End If

                Select Case ret
                    Case -1
                        MsgBox("Error during format operation")
                    Case -2
                        MsgBox("Operation canceled by user")
                    Case -3
                        MsgBox("This drive cannot be formatted")
                    Case Else
                        MsgBox("Done")
                End Select
            Catch ex As Exception
         
                MsgBox(ex.Message)
            End Try
        End If
    End Sub


The above code is giving an error that "A call to PInvoke function 'SHFormatDrive' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature."

I don't know exactly what is going wrong and when I am trying to format my pen drive, the above code is first checking for A: drive and then it is giving error.

Suggest me what should I do.

Thanks.

Gagan
AnswerRe: SHFormatDrive error [modified] Pin
Eddy Vluggen7-Mar-10 0:20
professionalEddy Vluggen7-Mar-10 0:20 
GeneralRe: SHFormatDrive error Pin
Gagan.207-Mar-10 1:53
Gagan.207-Mar-10 1:53 
GeneralRe: SHFormatDrive error Pin
Eddy Vluggen7-Mar-10 3:33
professionalEddy Vluggen7-Mar-10 3:33 
AnswerRe: SHFormatDrive error [modified] Pin
DaveAuld7-Mar-10 0:53
professionalDaveAuld7-Mar-10 0:53 
GeneralRe: SHFormatDrive error Pin
Gagan.207-Mar-10 1:33
Gagan.207-Mar-10 1:33 
GeneralRe: SHFormatDrive error Pin
DaveAuld7-Mar-10 1:45
professionalDaveAuld7-Mar-10 1:45 
AnswerRe: SHFormatDrive error [Update] Pin
DaveAuld7-Mar-10 3:29
professionalDaveAuld7-Mar-10 3:29 
AnswerRe: SHFormatDrive error Pin
Dave Kreskowiak7-Mar-10 3:43
mveDave Kreskowiak7-Mar-10 3:43 
AnswerRe: SHFormatDrive error Pin
Gagan.207-Mar-10 3:51
Gagan.207-Mar-10 3:51 
GeneralRe: SHFormatDrive error Pin
DaveAuld7-Mar-10 4:09
professionalDaveAuld7-Mar-10 4:09 
GeneralRe: SHFormatDrive error Pin
Gagan.208-Mar-10 2:23
Gagan.208-Mar-10 2:23 
GeneralRe: SHFormatDrive error Pin
DaveAuld8-Mar-10 2:34
professionalDaveAuld8-Mar-10 2:34 
GeneralRe: SHFormatDrive error Pin
Gagan.2013-Mar-10 3:56
Gagan.2013-Mar-10 3:56 
QuestionCopy a whole directory with files and subfolders with progressbar in vb Pin
majan116-Mar-10 17:31
majan116-Mar-10 17:31 
AnswerRe: Copy a whole directory with files and subfolders with progressbar in vb Pin
Luc Pattyn6-Mar-10 18:09
sitebuilderLuc Pattyn6-Mar-10 18:09 
GeneralRe: Copy a whole directory with files and subfolders with progressbar in vb Pin
majan117-Mar-10 11:50
majan117-Mar-10 11:50 
AnswerRe: Copy a whole directory with files and subfolders with progressbar in vb Pin
Gregory Gadow8-Mar-10 6:55
Gregory Gadow8-Mar-10 6:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.