once again after a week or 2 to think & read docs I answer my own question.
1. The delegate should be declared as:
Public Delegate Function STREAMPROC_Handler(ByVal handle As Integer, ByVal buffer As System.IntPtr, ByVal length As Integer, ByVal user As Integer) As Integer
that is, the pointer is a ByVal System.IntPtr.
2. In the callback, this is coerced (manhandled) eventually to a short pointer (in my case anyway) & now allows access to the mem:
void* bugger = buffer.ToPointer();
short* bugger2 = (short*)(bugger);
for (int i=0; i<len; i++)
bugger2[i] = (short) ran.Next();
sweet as,
Thanks all.
[quoted text, click to view] "Rua Haszard Morris" wrote:
> I'm trying to use a callback with the following signature from C# code.
>
> DWORD CALLBACK YourStreamProc(
> HSTREAM handle,
> void *buffer,
> DWORD length,
> DWORD user
> );
>
> This callback is invoked from a library (in C; the library is BASS
www.un4seen.com). The buffer parameter points to an array, allocated by the lib, which my callback fills with data.
>
> I'm using the lib wrapped by a (third-party) VB wrapper lib.
>
> It declares a delegate for the callback:
> Public Delegate Function STREAMPROC_Handler(ByVal handle As Integer, ByVal buffer As Integer, ByVal length As Integer, ByVal user As Integer) As Integer
>
> This doesn't seem right
> - it's not possible to cast the buffer int to a pointer /array
> - and the buffer won' t be returned to the caller unless it declared "ByRef"
>
> Am I correct on these points?
>
> I've tried declaring the parameter as ByRef, and various types (object, array, System.IntPtr), but I never recieve a buffer that I can write to. It's always 0 or <undefined value>.
>
> Is it possible to use this callback from managed code?
>
> How do I declare the delegate for the callback (in VB, C#)?
>
> thanks for any help...
> Rua HM
>