Link to home
Start Free TrialLog in
Avatar of karmi
karmiFlag for Palestine, State of

asked on

Using WaveIn* functions to record wav

How to define the callback function in visual basic that is addressed in the WaveInOpen? And how to use pointers in visual basic for memory structures? like when allocating memory for the WAVEHDR structure and assining it to pointer variable in visual basic?.
Avatar of abhinavm
abhinavm

i don't know the details about waveInopen Function but you can define call back function by using 'AddressOf' key word. Write a procedure or function to define the callback function. While passing the parameters to WaveInOpen function where address of callback function is required you can write AddressOf(FunctionName) .
    you won't get the pointers in VB actually while passing the parameters VB Passes it thru reference so if you haven't written ByVal keyword while passing parameter VB will Pass Poiter to the variable. So you need not to worry about pointer. Just define Same type Structure in VB(Using Type keyword) and pass the variable of that type to The function. While creating type you have to take care of VB and C Type Mappings.

Avatar of karmi

ASKER

I am using AddressOf function , and already declared the callback function as it is described at the MSDN documentation but that didnot work, may be because that was written in C, this is why I am asking if something else should be done with Visual Basic.

Sometimes I need to allocate memory using GlobalAlloc, then assign the address to a pointer variable "I do it using Long variable", but the variable is not accepted when calling some APIs because of type missmatch! as an example: allocating memory for WAVEHDR structure, then use the pointer variable in some API calls. I know how to that in C, but I need to know how to do the same thing in VB.

I don't know why your call back function is not working it should work.
   For the second thing storing address in a long variable is OK just you have to change the declare statement there instead of specifying type declare it as ANY and you won't get any type mismatch error.
Avatar of karmi

ASKER

declaring the callback function as it is described at the msdn documentation was ok for program compilation, but was not at run time, the blue screen and some other windows critical errors appeared after openning the wave file "when expecting a callbac to say file open".

msdn :
void CALLBACK waveInProc( HWAVEIN hwi,UINT uMsg,DWORD wInstance,
                         DWORD dwParam1, DWORD dwParam2 );
 

My VB :
Sub mciCallBack(hWaveIn As Long, hMsg As Integer, dInstance As Long, Par1 As Long, Par2 As Long)


According to set the variable type to Any in the decleration statement, I did but I received an error 87 by GetLasError which is Parameter Error, anyway this is not as important as the above case which I really I do care about.

Thanks for your help
ASKER CERTIFIED SOLUTION
Avatar of Aikema
Aikema

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial