VBGamer |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
Argh tatsuo (2 replies, 0 views) (2000-Aug-12) Okay, I've been working on this same problem since I asked about it a few days ago, and I'm stumped. The function below is used to create new surfaces in Rahaji. When the current demo runs, it's first used to load a JPEG. And this part works. :) But the next time it's called, to load a bitmap, the program crashes. The error occurs on the line 'Set surface = dd.CreateSurfaceFromFile(p, desc)', and generates run time error 5, invalid function or argument.
This error only occurs on three computers that the demo has been on, and mine isn't one of em. It makes it painfully hard to debug. ^_^ Does anyone have any ideas as to what could be wrong?
Public Function createSurface(p As String, w As Integer, h As Integer) As DirectDrawSurface7
'This function returns a surface containing a picture contained in the file 'p', that is w wide
'and h high.
Dim surface As DirectDrawSurface7 'The new surface which will be passed back.
Dim desc As DDSURFACEDESC2 'A description of the new surface
Dim sDC As Long 'The surface's device context, if needed (JPEG)
Dim dc As Long 'DC used to blit a JPEG onto a surface if needed
Dim bmp As Long 'DC old bmp
'Set the description of the surface
desc.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT 'Look at caps, height, and width
desc.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN 'An off-screen surface, like a buffer
desc.lWidth = w 'Set the width
desc.lHeight = h 'Set the height
'Find out if the file we are loading is a bitmap. If it is, CreateSurfaceFromFile
If Mid(p, (Len(p) - 2), 3) = "bmp" Then
'Create a surface based on these attributes, and then load the specified bitmap into it
Set surface = dd.CreateSurfaceFromFile(p, desc)
Else 'It's a JPEG. Then use loadPicture and load it the surface DC...
Set surface = dd.createSurface(desc) 'Create a blank surface
sDC = surface.GetDC 'Get the surface's DC
dc = CreateCompatibleDC(frmRahaji.hdc) 'Create new DC
bmp = SelectObject(dc, LoadPicture(p)) 'Load pic into DC
BitBlt sDC, 0, 0, w, h, dc, 0, 0, SRCCOPY 'Blit onto the surface's DC
SelectObject dc, bmp
DeleteDC dc 'Delete the temp device context created
surface.ReleaseDC sDC 'Release the surface's DC
End If
Set createSurface = surface 'Pass back new created surface
End Function
Thanks,
Greg
|