⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mtools.bas

📁 一个d3d实例程序
💻 BAS
📖 第 1 页 / 共 2 页
字号:
        
    ' Copy format data to local structure ...
        CopyMemory VarPtr(L_dWFX), VarPtr(L_nWaveBytes(L_nPosition + 8)), Len(L_dWFX)
        
            
    ' Search for audio data position ...
            
        ' Look for data expression
        Do While Not (Chr(L_nWaveBytes(L_nPosition)) + Chr(L_nWaveBytes(L_nPosition + 1)) + Chr(L_nWaveBytes(L_nPosition + 2)) + Chr(L_nWaveBytes(L_nPosition + 3)) = "data")
            
            L_nPosition = L_nPosition + 1
            
            ' Cancel if no data expression found
            If L_nPosition > UBound(L_nWaveBytes) - 4 Then
                AppError 0, "Invalid file format", "LoadWaveIntoDSB"
            End If
            
        Loop
        
        ' Copy data size to local variable
        CopyMemory VarPtr(L_nDataSize), VarPtr(L_nWaveBytes(L_nPosition + 4)), 4
            
    ' Create and fill DirectSound buffer ...
    
        ' Fill description structure to create buffer from
        With L_dDSBD
            .dwSize = Len(L_dDSBD)
            .dwFlags = DSBCAPS_CTRLDEFAULT
            .dwBufferBytes = L_nDataSize
            .lpwfxFormat = VarPtr(L_dWFX)
        End With
        
        ' Create buffer from structure
        G_oDSInstance.CreateSoundBuffer L_dDSBD, LoadWaveIntoDSB, Nothing
        
        ' Check for existance of buffer
        If LoadWaveIntoDSB Is Nothing Then
           AppError 0, "Buffer could not be created", "LoadWaveIntoDSB"
           Exit Function
        End If
        
        ' Lock buffer to access its data
        LoadWaveIntoDSB.Lock 0&, L_nDataSize, L_nPointer1, L_nLength1, L_nPointer2, L_nLength2, 0&
        
        ' Copy left (or only, if mono wave file) track to DirectSound buffer
        CopyMemory L_nPointer1, VarPtr(L_nWaveBytes(L_nPosition + 8)), L_nLength1
        
        ' Copy right track to DirectSound buffer, if exists
        If L_nLength2 <> 0 Then
            CopyMemory L_nPointer2, VarPtr(L_nWaveBytes(L_nPosition + 8 + L_nLength1)), L_nLength2
        End If
        
        ' Unlock buffer
        LoadWaveIntoDSB.Unlock L_nPointer1, L_nLength1, L_nPointer2, L_nLength2
        
    ' Error handler ...
        Exit Function
    
E_LoadWaveIntoDSB:

        AppError Err.Number, Err.Description, "LoadWaveIntoDSB"
    
End Function

Public Function GetDXError(nError As Long) As String

    Select Case nError
        Case DDERR_DCALREADYCREATED
            GetDXError = "A device context (DC) has already been returned for this surface. Only one DC can be retrieved for each surface."
        Case DDERR_DIRECTDRAWALREADYCREATED
            GetDXError = "A IDirectDraw object representing this driver has already been created for this process."
        Case DDERR_EXCEPTION
            GetDXError = "An exception was encountered while performing the requested operation."
        Case DDERR_EXCLUSIVEMODEALREADYSET
            GetDXError = "An attempt was made to set the cooperative level when it was already set to exclusive."
        Case DDERR_HEIGHTALIGN
            GetDXError = "The height of the provided rectangle is not a multiple of the required alignment."
        Case DDERR_HWNDALREADYSET
            GetDXError = "The IDirectDraw cooperative level window handle has already been set. It cannot be reset while the process has surfaces or palettes created."
        Case DDERR_HWNDSUBCLASSED
            GetDXError = "IDirectDraw is prevented from restoring state because the IDirectDraw cooperative level window handle has been subclassed."
        Case DDERR_ALREADYINITIALIZED
            GetDXError = "The object has already been initialized."
        Case DDERR_BLTFASTCANTCLIP
            GetDXError = "A IDirectDrawClipper object is attached to a source surface that has passed into a call to the IDirectDrawSurface2::BltFast method."
        Case DDERR_CANNOTATTACHSURFACE
            GetDXError = "A surface cannot be attached to another requested surface."
        Case DDERR_CANNOTDETACHSURFACE
            GetDXError = "A surface cannot be detached from another requested surface."
        Case DDERR_CANTCREATEDC
            GetDXError = "Windows cannot create any more device contexts (DCs)."
        Case DDERR_CANTDUPLICATE
            GetDXError = "Primary and 3D surfaces, or surfaces that are implicitly created, cannot be duplicated."
        Case DDERR_CANTLOCKSURFACE
            GetDXError = "Access to this surface is refused because an att    empt was made to lock the primary surface without DCI support."
        Case DDERR_CANTPAGELOCK
            GetDXError = "An attempt to page lock a surface failed. Page lock will not work on a display-m    emory surface or an     emulated primary surface."
        Case DDERR_CANTPAGEUNLOCK
            GetDXError = "An attempt to page unlock a surface failed. Page unlock will not work on a display-m    emory surface or an     emulated primary surface."
        Case DDERR_CLIPPERISUSINGHWND
            GetDXError = "An attempt was made to set a clip list for a IDirectDrawClipper object that is already monitoring a window handle."
        Case DDERR_COLORKEYNOTSET
            GetDXError = "No source color key is specified for this operation."
        Case DDERR_CURRENTLYNOTAVAIL
            GetDXError = "No support is currently available."
        Case DDERR_IMPLICITLYCREATED
            GetDXError = "The surface cannot be restored because it is an implicitly created surface."
        Case DDERR_INCOMPATIBLEPRIMARY
            GetDXError = "The primary surface creation request does not match with the existing primary surface."
        Case DDERR_INVALIDCAPS
            GetDXError = "One or more of the capability bits passed to the callback function are incorrect."
        Case DDERR_INVALIDCLIPLIST
            GetDXError = "IDirectDraw does not support the provided clip list."
        Case DDERR_INVALIDDIRECTDRAWGUID
            GetDXError = "The globally unique identifier (GUID) passed to the IDirectDrawCreate function is not a valid IDirectDraw driver identifier."
        Case DDERR_INVALIDMODE
            GetDXError = "IDirectDraw does not support the requested mode."
        Case DDERR_INVALIDOBJECT
            GetDXError = "IDirectDraw received a pointer that was an invalid IDirectDraw object."
        Case DDERR_INVALIDPIXELFORMAT
            GetDXError = "The pixel format was invalid as specified."
        Case DDERR_INVALIDPOSITION
            GetDXError = "The position of the overlay on the destination is no longer legal."
        Case DDERR_INVALIDRECT
            GetDXError = "The provided rectangle was invalid."
        Case DDERR_INVALIDSURFACETYPE
            GetDXError = "The requested operation could not be performed because the surface was of the wrong type."
        Case DDERR_LOCKEDSURFACES
            GetDXError = "One or more surfaces are locked, causing the failure of the requested operation."
        Case DDERR_NO3D
            GetDXError = "No 3D hardware or emulation is present."
        Case DDERR_NOALPHAHW
            GetDXError = "No alpha acceleration hardware is present or available, causing the failure of the requested operation."
        Case DDERR_NOBLTHW
            GetDXError = "No blitter hardware is present."
        Case DDERR_NOCLIPLIST
            GetDXError = "No clip list is available."
        Case DDERR_NOCLIPPERATTACHED
            GetDXError = "No IDirectDrawClipper object is attached to the surface object."
        Case DDERR_NOCOLORCONVHW
            GetDXError = "The operation cannot be carried out because no color-conversion hardware is present or available."
        Case DDERR_NOCOLORKEY
            GetDXError = "The surface does not currently have a color key."
        Case DDERR_NOCOLORKEYHW
            GetDXError = "The operation cannot be carried out because there is no hardware support for the destination color key."
        Case DDERR_NOCOOPERATIVELEVELSET
            GetDXError = "A create function is called without the IDirectDraw2::SetCooperativeLevel method being called."
        Case DDERR_NODC
            GetDXError = "No DC has ever been created for this surface."
        Case DDERR_NODDROPSHW
            GetDXError = "No IDirectDraw raster operation (ROP) hardware is available."
        Case DDERR_NODIRECTDRAWHW
            GetDXError = "Hardware-only IDirectDraw object creation is not possible; the driver does not support any hardware."
        Case DDERR_NODIRECTDRAWSUPPORT
            GetDXError = "IDirectDraw support is not possible with the current display driver."
        Case DDERR_NOEMULATION
            GetDXError = "Software emulation is not available."
        Case DDERR_NOEXCLUSIVEMODE
            GetDXError = "The operation requires the application to have exclusive mode, but the application does not have exclusive mode."
        Case DDERR_NOFLIPHW
            GetDXError = "Flipping visible surfaces is not supported."
        Case DDERR_NOGDI
            GetDXError = "No GDI is present."
        Case DDERR_NOHWND
            GetDXError = "Clipper notification requires a window handle, or no window handle has been previously set as the cooperative level window handle."
        Case DDERR_NOMIPMAPHW
            GetDXError = "The operation cannot be carried out because no mipmap texture mapping hardware is present or available."
        Case DDERR_NOMIRRORHW
            GetDXError = "The operation cannot be carried out because no mirroring hardware is present or available."
        Case DDERR_NOOVERLAYDEST
            GetDXError = "The IDirectDrawSurface2::GetOverlayPosition method is called on an overlay that the IDirectDrawSurface2::UpdateOverlay method has not been called on to establish a destination."
        Case DDERR_NOOVERLAYHW
            GetDXError = "The operation cannot be carried out because no overlay hardware is present or available."
        Case DDERR_NOPALETTEATTACHED
            GetDXError = "No palette object is attached to this surface."
        Case DDERR_NOPALETTEHW
            GetDXError = "There is no hardware support for 16- or 256-color palettes."
        Case DDERR_NORASTEROPHW
            GetDXError = "The operation cannot be carried out because no appropriate raster operation hardware is present or available."
        Case DDERR_NOROTATIONHW
            GetDXError = "The operation cannot be carried out because no rotation hardware is present or available."
        Case DDERR_NOSTRETCHHW
            GetDXError = "The operation cannot be carried out because there is no hardware support for stretching."
        Case DDERR_NOT4BITCOLOR
            GetDXError = "The IDirectDrawSurface object is not using a 4-bit color palette and the requested operation requires a 4-bit color palette."
        Case DDERR_NOT4BITCOLORINDEX
            GetDXError = "The IDirectDrawSurface object is not using a 4-bit color index palette and the requested operation requires a 4-bit color index palette."
        Case DDERR_NOT8BITCOLOR
            GetDXError = "The IDirectDrawSurface object is not using an 8-bit color palette and the requested operation requires an 8-bit color palette."
        Case DDERR_NOTAOVERLAYSURFACE
            GetDXError = "An overlay component is called for a non-overlay surface."
        Case DDERR_NOTEXTUREHW
            GetDXError = "The operation cannot be carried out because no texture-mapping hardware is present or available."
        Case DDERR_NOTFLIPPABLE
            GetDXError = "An attempt has been made to flip a surface that cannot be flipped."
        Case DDERR_NOTFOUND
            GetDXError = "The requested item was not found."
        Case DDERR_NOTLOCKED
            GetDXError = "An attempt is made to unlock a surface that was not locked."
        Case DDERR_NOTPAGELOCKED
            GetDXError = "An attempt is made to page unlock a surface with no outstanding page locks."
        Case DDERR_NOTPALETTIZED
            GetDXError = "The surface being used is not a palette-based surface."
        Case DDERR_NOVSYNCHW
            GetDXError = "The operation cannot be carried out because there is no hardware support for vertical blank synchronized operations."
        Case DDERR_NOZBUFFERHW
            GetDXError = "The operation to create a z-buffer in display memory or to perform a blit using a z-buffer cannot be carried out because there is no hardware support for z-buffers."
        Case DDERR_NOZOVERLAYHW
            GetDXError = "The overlay surfaces cannot be z-layered based on the z-order because the hardware does not support z-ordering of overlays."
        Case DDERR_OUTOFCAPS
            GetDXError = "The hardware needed for the requested operation has already been allocated."
        Case DDERR_OUTOFVIDEOMEMORY
            GetDXError = "IDirectDraw does not have enough display memory to perform the operation."
        Case DDERR_OVERLAYCANTCLIP
            GetDXError = "The hardware does not support clipped overlays."
        Case DDERR_OVERLAYCOLORKEYONLYONEACTIVE
            GetDXError = "An attempt was made to have more than one color key active on an overlay."
        Case DDERR_OVERLAYNOTVISIBLE
            GetDXError = "The IDirectDrawSurface2::GetOverlayPosition method is called on a hidden overlay."
        Case DDERR_PALETTEBUSY
            GetDXError = "Access to this palette is refused because the palette is locked by another thread."
        Case DDERR_PRIMARYSURFACEALREADYEXISTS
            GetDXError = "This process has already created a primary surface."
        Case DDERR_REGIONTOOSMALL
            GetDXError = "The region passed to the IDirectDrawClipper::GetClipList method is too small."
        Case DDERR_SURFACEALREADYATTACHED
            GetDXError = "An attempt was made to attach a surface to another surface to which it is already attached."
        Case DDERR_SURFACEALREADYDEPENDENT
            GetDXError = "An attempt was made to make a surface a dependency of another surface to which it is already dependent."
        Case DDERR_SURFACEBUSY
            GetDXError = "Access to the surface is refused because the surface is locked by another thread."
        Case DDERR_SURFACEISOBSCURED
            GetDXError = "Access to the surface is refused because the surface is obscured."
        Case DDERR_SURFACELOST
            GetDXError = "Access to the surface is refused because the surface memory is gone. The IDirectDrawSurface object representing this surface should have the IDirectDrawSurface2::Restore method called on it."
        Case DDERR_SURFACENOTATTACHED
            GetDXError = "The requested surface is not attached."
        Case DDERR_TOOBIGHEIGHT
            GetDXError = "The height requested by IDirectDraw is too large."
        Case DDERR_TOOBIGSIZE
            GetDXError = "The size requested by IDirectDraw is too large. However, the individual height and width are OK."
        Case DDERR_TOOBIGWIDTH
            GetDXError = "The width requested by IDirectDraw is too large."
        Case DDERR_UNSUPPORTEDFORMAT
            GetDXError = "The FourCC format requested is not supported by IDirectDraw."
        Case DDERR_UNSUPPORTEDMASK
            GetDXError = "The bitmask in the pixel format requested is not supported by IDirectDraw."
        Case DDERR_UNSUPPORTEDMODE
            GetDXError = "The display is currently in an unsupported mode."
        Case DDERR_VERTICALBLANKINPROGRESS
            GetDXError = "A vertical blank is in progress."
        Case DDERR_WASSTILLDRAWING
            GetDXError = "The previous blit operation that is transferring information to or from this surface is incomplete."
        Case DDERR_WRONGMODE
            GetDXError = "This surface cannot be restored because it was created in a different mode."
        Case DDERR_XALIGN
            GetDXError = "The provided rectangle was not horizontally aligned on a required boundary."
        Case Else
            GetDXError = "Unknown Error: Out of memory or invalid parameters passed."
    End Select
    
End Function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -