Does DeleteDC() even work ?
Correct me if I'm wrong, but surely the code below should be able to run indefinitely, as it is deleting the DC right after it creates it ??
If not, then how does one actually recover the lost resources ?
VB Code:
Option Explicit
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hDc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDc As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hDc As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hDc As Long, ByVal hObject As Long) As Long
Private Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As MEMORYSTATUS)
Private Type MEMORYSTATUS
dwLength As Long
dwMemoryLoad As Long
dwTotalPhys As Long
dwAvailPhys As Long
dwTotalPageFile As Long
dwAvailPageFile As Long
dwTotalVirtual As Long
dwAvailVirtual As Long
End Type
Private Function GenerateDC(FileName As String) As Long
Dim DC As Long, picTemp As IPictureDisp
DC = CreateCompatibleDC(0)
If DC < 1 Then
Exit Function
End If
Set picTemp = LoadPicture(FileName)
SelectObject DC, picTemp
DeleteObject picTemp
Set picTemp = Nothing
GenerateDC = DC
End Function
Private Sub Form_Load()
Dim i As Long
Do
DoEvents
Debug.Print "Memory Free : " & (x.dwAvailPhys / 1024) & "Kb : " & IIf(DeleteDC(GenerateDC("c:\boilogo.gif")) <> 0, "DeleteDC() Worked", "DeleteDC() Failed")
DoEvents
Loop
End Sub
Re: Does DeleteDC() even work ?
Quote:
Originally posted by plenderj
Correct me if I'm wrong, but, Don't DCs can be negative too? I think you should change that "< 1" to "= 0".