Copyright © 2001-2018 MultiMedia Soft

LoadSoundFromMemory method

Previous pageReturn to chapter overviewNext page



Loads a sound file stored inside a memory buffer. The sound file can be a stream file (see the LoadSound method for accepted stream formats) or a MOD music file.

If the sound is in RAW format use the LoadSoundFromRawMemory method.


A successful call to this method will fire the SoundLoaded event.





[Visual Basic]

control.LoadSoundFromMemory (

nPlayer as Integer,

pBuffer as Variant,

nBufferLen as Long

) as enumErrorCodes



short control.LoadSoundFromMemory (

short nPlayer,

const VARIANT FAR& pBuffer,

long nBufferLen









Number representing the zero-based index of the player that will load the memory sound


Variant parameter containing the pointer to sound data previously loaded in memory.


Length in bytes of the given buffer



Return value






Negative value

An error occurred (see the LastError property for further error details)

enumErrorCodes.NOERROR (0)

The file has been loaded correctly.




Below you can find a couple of samples that demonstrate how to load a memory sound in Visual Basic 6 and Visual C++ 6: the memory sound has been taken from a .RES resource file using the "identifier" variable.


Visual Basic 6


' the memory buffer must be declared as global

Dim bytSound() As Byte


Private Sub Command1_Click()

 Dim length As Long

 bytSound = LoadResData(identifier, 10)

 length = UBound(bytSound)


 Amp3dj1.LoadSoundFromMemory 0, VarPtr(bytSound(0)), length

 Amp3dj1.PlaySound 0

End Sub



Visual C++ 6 with MFC


void CMyDialog::OnButton1()


 HINSTANCE hInst = AfxGetResourceHandle();

 HRSRC hrsrc = ::FindResource(hInst, MAKEINTRESOURCE (identifier), RT_RCDATA);

 if (!hrsrc)



 HGLOBAL hg = LoadResource(hInst, hrsrc);

 if (!hg)



 BYTE    *pRes = (BYTE*) LockResource(hg);


 int iSize = ::SizeofResource(hInst, hrsrc);


 VARIANT      va;

 VariantInit (&va);

 va.vt = VT_BYREF | VT_UI1;

 va.pbVal = (BYTE *) pRes;


 m_ctrlActiveDJ.LoadSoundFromMemory (0, va, iSize);

 m_ctrlActiveDJ.PlaySound (0);