Jump to content

need help with dll calls and data they return


Recommended Posts

im not so good with dll call
im trying to save a vst plugin last status in autoit via the bass udf + bassVst udf
i tried some stuff with trial error but got nothing
this is what i have so far, the link and funk names the example C of the site and my autoit function

BASS_VST_GetChunk http://www.bass.radio42.com/help/html/9d82cc1a-9ac0-3ff6-a599-9dd1dc898938.htm

public static byte[] BASS_VST_GetChunk(
    int vstHandle,
    bool isPreset
)
Func _BASS_VST_GetChunk($vstHandle,$isPreset)
    $_BASSFX_ret_ = DllCall($_ghbassVSTDll, "BYTE", "BASS_VST_GetBypass", "int", $vstHandle,"BOOLEAN", $isPreset)
    If @error Then Return SetError(1, 1, 0)
    If $_BASSFX_ret_[0] = $BASS_DWORD_ERR Then Return SetError(_BASS_ErrorGetCode(), 0, 0)
    Return $_BASSFX_ret_[0]
EndFunc   ;==>_BASS_VST_GetBypass

BASS_VST_SetChunk http://www.bass.radio42.com/help/html/66f64176-cb25-27e2-a734-8bd0c2255be7.htm

public static int BASS_VST_SetChunk(
    int vstHandle,
    bool isPreset,
    byte[] chunk
)
Func _BASS_VST_SetChunk($vstHandle,$isPreset,$chunk)
    $_BASSFX_ret_ = DllCall($_ghbassVSTDll, "int", "BASS_VST_SetChunk", "int", $vstHandle,"BOOLEAN", $isPreset,"BYTE",$chunk)
    If @error Then Return SetError(1, 1, 0)
    If $_BASSFX_ret_[0] = $BASS_DWORD_ERR Then Return SetError(_BASS_ErrorGetCode(), 0, 0)
    Return $_BASSFX_ret_[0]
EndFunc   ;==>_BASS_VST_GetBypass

as far as i understand,BASS_VST_GetChunk  is supposed to return a chunk of data i can store and later send it to the vst plugin with BASS_VST_SetChunk

i don't understand how to get the BASS_VST_GetChunk output, and have trouble to fit $ispreset in to the equation

Edited by jvds
Link to comment
Share on other sites

Hello. You can need to use ptr and DllStructCreate to store your byte array.

I'm no sure but It would be better if the function support had the byte array length as return. something like (DWORD vstHandle, BOOL isPreset, DWORD* length)

Otherwise You will need to allocate an unkown memory space.

Edit 

;~ public static byte[] BASS_VST_GetChunk(
;~     int vstHandle,
;~     bool isPreset
;~ )

;~ This could be something like this



Local $aRet=DllCall($_ghbassVSTDll,"ptr","BASS_VST_GetChunk","int",$vstHandle,"boolean",$isPreset)
Local $tByteArray=DllStructCreate("byte[1024]",$aRet[0]) ;Of couse you need to allocate more than 1024


;if the dll call allow the return size  required (as I said before) if would look like
Local $aRet=DllCall($_ghbassVSTDll,"ptr","BASS_VST_GetChunk","int",$vstHandle,"boolean",$isPreset,"dword*",0)

;then you could do something like this to allocate your byte array memory space.
Local $tByteArray=DllStructCreate("byte[" & $aRet[3] & "]",$aRet[0])

Saludos

Edited by Danyfirex
Link to comment
Share on other sites

hi, it crashes the script, would this help? the dll source is on github
https://github.com/r10s/BASS_VST/blob/master/source/bass_vst_impl.cpp

char* BASS_VSTDEF(BASS_VST_GetChunk)(DWORD vstHandle, BOOL isPreset, DWORD* length)
{
	*length = 0;
	BASS_VST_PLUGIN* this_ = refHandle(vstHandle);
	if( this_ == NULL )
		RETURN_ERROR( BASS_ERROR_HANDLE );

	if (!(this_->aeffect->flags&effFlagsProgramChunks))
		RETURN_ERROR( BASS_ERROR_NOTAVAIL );

	enterVstCritical(this_);

		void* data = 0;
		int size = (int)this_->aeffect->dispatcher(this_->aeffect, effGetChunk, isPreset ? 1 : 0, 0, &data, 0.0f);
		if (data != 0 && size > 0)
        {
			// alloc our temp buffer
			this_->tempChunkData = (char*)realloc(this_->tempChunkData, size );
            memcpy(this_->tempChunkData, data, size);
			*length = size;
        }
		else
		{
			if (this_->tempChunkData)
			{
				free(this_->tempChunkData);
				this_->tempChunkData = NULL;
			}
		}

	leaveVstCritical(this_);

	unrefHandle(vstHandle);

	RETURN_SUCCESS( this_->tempChunkData );
}

i dont know why it chrashes , but lets say your code worked

;if the dll call allow the return size  required (as I said before) if would look like
Local $aRet=DllCall($_ghbassVSTDll,"ptr","BASS_VST_GetChunk","int",$vstHandle,"boolean",$isPreset,"dword*",0)

;then you could do something like this to allocate your byte array memory space.
Local $tByteArray=DllStructCreate("byte[" & $aRet[3] & "]",$aRet[0])

how would i read the dll info in to autoit in this case?
$info = DllStructGetData($tByteArray,"byte") ??

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...