I've got a strange problem...

I made a form for resizing a pic and uploading it to a server. Played around with to make sure it fully works, and it does what it's supposed to do for now. But then I restarted my pc, and now when I run the program and it goes into the ftp-part of it, everything still works, but if I close the program it seems to crash for about 20-25sec. If I check my task manager it shows processes of the running exe, and vb6, both "not responding" but after those 25sec (more or less) they both become "running" again and everything goes back to normal.

Any idea how this can happen?? Nothing changed in the code before or after rebooting the pc. I'm absolutely clueless about it, but it sucks big time of course.

Here's the code:

VB Code:
  1. 'Option Explicit
  2.  
  3. Private Declare Function BmpToJpeg Lib "Bmp2Jpeg.dll" ( _
  4. ByVal BmpFilename As String, _
  5. ByVal JpegFilename As String, _
  6. ByVal CompressQuality As Integer) As Integer
  7.  
  8. 'ftp functions via vbforums.com, Joacim Andersson
  9. Private Declare Function FtpGetFile Lib "wininet.dll" _
  10. Alias "FtpGetFileA" ( _
  11. ByVal hFtpSession As Long, _
  12. ByVal lpszRemoteFile As String, _
  13. ByVal lpszNewFile As String, _
  14. ByVal fFailIfExists As Boolean, _
  15. ByVal dwFlagsAndAttributes As Long, _
  16. ByVal dwFlags As Long, _
  17. ByVal dwContext As Long) As Boolean
  18.  
  19. Private Declare Function FtpPutFile Lib "wininet.dll" _
  20. Alias "FtpPutFileA" ( _
  21. ByVal hFtpSession As Long, _
  22. ByVal lpszLocalFile As String, _
  23. ByVal lpszRemoteFile As String, _
  24. ByVal dwFlags As Long, _
  25. ByVal dwContext As Long) As Boolean
  26.  
  27. Private Declare Function InternetOpen Lib "wininet.dll" _
  28. Alias "InternetOpenA" ( _
  29. ByVal sAgent As String, _
  30. ByVal nAccessType As Long, _
  31. ByVal sProxyName As String, _
  32. ByVal sProxyByPass As String, _
  33. ByVal nFlags As Long) As Long
  34.  
  35. Private Declare Function InternetConnect Lib "wininet.dll" _
  36. Alias "InternetConnectA" ( _
  37. ByVal hInternetSession As Long, _
  38. ByVal sServerName As String, _
  39. ByVal nServerPort As Integer, _
  40. ByVal sUserName As String, _
  41. ByVal sPassword As String, _
  42. ByVal nService As Long, _
  43. ByVal dwFlags As Long, _
  44. ByVal dwContext As Long) As Long
  45.  
  46. Private Declare Function FtpCreateDirectory _
  47.  Lib "wininet.dll" Alias "FtpCreateDirectoryA" ( _
  48.  ByVal hFtpSession As Long, _
  49.  ByVal lpszDirectoryName As String) As Boolean
  50.  
  51. Private Declare Function FtpSetCurrentDirectory _
  52.  Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" ( _
  53.  ByVal hFtpSession As Long, _
  54.  ByVal lpszDirectoryName As String) As Boolean
  55.  
  56. Private Declare Function InternetCloseHandle Lib "wininet.dll" ( _
  57. ByVal hInet As Long) As Integer
  58.  
  59. Private Const INTERNET_SERVICE_FTP = 1
  60. Private Const INTERNET_SERVICE_GOPHER = 2
  61. Private Const INTERNET_SERVICE_HTTP = 3
  62.  
  63. Public Sub resizePic()
  64. Dim filename, picpath, reverse As String
  65. Dim start, i As Integer
  66. Picture1.Picture = LoadPicture()
  67. Picture2.Picture = LoadPicture()
  68.  
  69. reverse = ""
  70. For i = 1 To Len(frmSwitchboard.rsProperty.Fields("pr_pic").Value)
  71.         reverse = reverse & Mid(frmSwitchboard.rsProperty.Fields("pr_pic").Value, Len(frmSwitchboard.rsProperty.Fields("pr_pic").Value) - i + 1, 1)
  72. Next
  73. start = InStr(1, reverse, "\")
  74. 'picpath = Mid(rsProperty.Fields("pr_pic"), 1, Len(rsProperty.Fields("pr_pic")) - start)
  75. filename = Mid(frmSwitchboard.rsProperty.Fields("pr_pic"), Len(frmSwitchboard.rsProperty.Fields("pr_pic")) - start + 2, start - 5)
  76. 'filename = Left(dlg.filename, Len(dlg.filename) - 4)
  77. Picture1.Picture = LoadPicture(frmSwitchboard.rsProperty.Fields("pr_pic"))
  78. 'Resizing
  79.  
  80. Picture2.AutoRedraw = True
  81. 'Picture2.Width = 400
  82. 'Picture2.Height = 300
  83. Picture2.PaintPicture Picture1.Picture, _
  84. Picture2.ScaleLeft, Picture2.ScaleTop, _
  85. Picture2.ScaleWidth, Picture2.ScaleHeight, _
  86. Picture1.ScaleLeft, Picture1.ScaleTop
  87. Picture2.Picture = Picture2.Image
  88.  
  89. 'Saving the file as Bitmap
  90. SavePicture Picture2.Picture, "C:\" & filename & ".bmp"
  91. 'For saving into jpg format you must have
  92. 'the Bmp2Jpeg.dll file in your windows folder
  93. 'Change the bitmap file to the jpg file with the Bmp2Jpg.dll
  94. '60 is the Compress Quality
  95. BmpToJpeg "C:\" & filename & ".bmp", "C:\" & filename & ".jpg", 60
  96. 'Deleting the bitmap file
  97. Kill "C:\" & filename & ".bmp"
  98. uploadPic frmSwitchboard.rsProperty.Fields("pr_code").Value, "C:\", filename & ".jpg"
  99. Kill "C:\" & filename & ".jpg"
  100. End Sub
  101.  
  102. Public Sub uploadPic(dirName As String, filePath As String, file As String)
  103. 'dirName = name of target folder on server
  104. 'filePath is e.g. "C:\"
  105. 'file full name of the file, e.g. "picture.jpg"
  106. 'Dim hINetSession As Variant
  107. 'Dim hsession As Variant
  108. retry:
  109. hINetSession = InternetOpen("testftp", 0, vbNullString, vbNullString, 0)
  110. hsession = InternetConnect(hINetSession, "127.0.0.1", "21", "test", "test", INTERNET_SERVICE_FTP, 0, 0)
  111.  
  112. If FtpSetCurrentDirectory(hsession, dirName) = False Then
  113.     FtpCreateDirectory hsession, dirName
  114. End If
  115. FtpSetCurrentDirectory hsession, dirName
  116.     If FtpPutFile(hsession, filePath & file, file, 1, 0) = False Then
  117.         If MsgBox("Error occurred. Code: " & Err.LastDllError & vbCrLf & "Retry?", vbYesNo + vbQuestion) = vbYes Then
  118.             GoTo retry:
  119.         Else
  120.             MsgBox ("Upload failed.")
  121.             Exit Sub
  122.         End If
  123.     Else
  124.         MsgBox "upload success"
  125.     End If
  126. Call InternetCloseHandle(hsession)
  127. Call InternetCloseHandle(hINetSession)
  128. End Sub

to start it I just attached it to a menu item in my main form.
so that on click it goes "frmFTP.resizePic"