N
Nik
Hi,
I am having a problem while trying to use a buffer in a Function call. I
have ported the code from the MSDN documentation and it seems that the
function expects a different type of input parameter than the one MSDN is
configured for. I need some help to convert it.
Here is the ported block of code --
Dim buf As Int16() 'a buffer into which integer values are read
ReDim buf(1000) 'resize the buffer
Dim v As Double() = readValues(startTime, endTime)
Dim i As Integer
' I have to copy the values as my function returns an array of Doubles
For i = 0 To 999
buf(i) = CType(v(i), Int16)
Next
Dim b(2000) As Byte
Buffer.BlockCopy(buf, 0, b, 0, 2000)
'This is where the thing gets stuck in between the !!'s
m_dsb.WriteBuffer(0, 1000, !! b !!,
DxVBLibA.CONST_DSBLOCKFLAGS.DSBLOCK_ENTIREBUFFER)
End code----
In the MSDN doc the 3rd parameter is the first byte of the buffer,
essentially it seems that they want the address of the buffer. The online
documentation of the function says that this parameter is of type Any.
However, the dll on my machine asks for a parameter of type IntPtr. The VS
environment gives me an error saying that Value of type '1-dimensional array
of Byte' cannot be converted to 'System.IntPtr'.
If I try putting in b(0) as was in the original code then also it does not
work with the error being Value of type 'Byte' cannot be converted to
'System.IntPtr'.
I believe that obtaining the memory address of the buffer would solve my
problems. Can anyone help me get the address of b(0) ?? I see that it needs
to be done through the Marshal class, but I have never used it and I dont
see a function where I can pass in a byte array as input.
TIA,
Nik
P.S. Sorry for writing this message in HTML format, but that was the best
way to provide links to MSDN rather than have them show as long strings in
the message itself.
I am having a problem while trying to use a buffer in a Function call. I
have ported the code from the MSDN documentation and it seems that the
function expects a different type of input parameter than the one MSDN is
configured for. I need some help to convert it.
Here is the ported block of code --
Dim buf As Int16() 'a buffer into which integer values are read
ReDim buf(1000) 'resize the buffer
Dim v As Double() = readValues(startTime, endTime)
Dim i As Integer
' I have to copy the values as my function returns an array of Doubles
For i = 0 To 999
buf(i) = CType(v(i), Int16)
Next
Dim b(2000) As Byte
Buffer.BlockCopy(buf, 0, b, 0, 2000)
'This is where the thing gets stuck in between the !!'s
m_dsb.WriteBuffer(0, 1000, !! b !!,
DxVBLibA.CONST_DSBLOCKFLAGS.DSBLOCK_ENTIREBUFFER)
End code----
In the MSDN doc the 3rd parameter is the first byte of the buffer,
essentially it seems that they want the address of the buffer. The online
documentation of the function says that this parameter is of type Any.
However, the dll on my machine asks for a parameter of type IntPtr. The VS
environment gives me an error saying that Value of type '1-dimensional array
of Byte' cannot be converted to 'System.IntPtr'.
If I try putting in b(0) as was in the original code then also it does not
work with the error being Value of type 'Byte' cannot be converted to
'System.IntPtr'.
I believe that obtaining the memory address of the buffer would solve my
problems. Can anyone help me get the address of b(0) ?? I see that it needs
to be done through the Marshal class, but I have never used it and I dont
see a function where I can pass in a byte array as input.
TIA,
Nik
P.S. Sorry for writing this message in HTML format, but that was the best
way to provide links to MSDN rather than have them show as long strings in
the message itself.