Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

IntPtr troubles with VB .Net 2005

cernek
Beginner
322 Views

I am doing a migration of some MS/VS 2003 C++ code to MS/VS 2005 Visual Basic. The code references some IPP Signal Processing Library routines. To make matters more complicated, the legacy C++ code references version 4.x of the library, and I am using version 5.1.

I have arrived at a point where most of the compiler errors have been addressed, but there are a couple that just won't go away. The biggest problem has to do with passing an array of doubles to routines which expect a type IntPtr.

Following are some code-fragments to illustrate the issue(s). In most cases I have included the legacy C++ code as comments.

Focus here on the declaration of dWinData.

'double WindowFunction
' (
' short intWindowOption,
' long lFFTSize,
' double *dSignalCorrectiondB,
' double *dNoiseCorrectiondB,
' double *dWinData
' )
Public Function WindowFunction( _
ByVal intWindowOption As Short, _
ByVal lFFTSize As Integer, _
ByRef dSignalCorrectiondB As Double, _
ByRef dNoiseCorrectiondB As Double, _
ByRef dWinData() As Double _
) As Double

Here dWinData is passed as a pointer to a double (or array of doubles) in the original C code. In my VB code I have declared dWinData to be an array of doubles, passed by reference. When I get to the following statement...

'inStatus = ippsSet_64f(1.0, dWinData, lFFTSize); //Set elements of dWinData = 1.0
inStatus = ipp.sp.ippsSet_64f(1.0, dWinData, lFFTSize)

... the compiler complains about dWinData: "... Value of type '1-dimensional array of Double' cannot be converted to 'System.IntPtr'...". For reference, the declaration of ippsSet_64f is

Declare Function ippsSet_64f Lib "ipps-5.1.dll" _
( ByVal val As Double , ByVal pDst As IntPtr , ByVal len As Integer ) As IppStatus

Note that ippsSet_64f expects the second passed parameter to be of type IntPtr.

What can I do about this?

My background is that I am very familiar with C and VB6,a littlefamiliar with C++ and just getting up to speed with .Net and the VS 2005 development environment.

Any assistance is greatly appreciated.

0 Kudos
2 Replies
Albert_Stepanov
New Contributor I
322 Views

Hi!

You should use Marshal.UnsafeAddrOfPinnedArrayElement method to get the address of the element inside the specified array similarly to the following code:

Dim dWinData() As Double = {0, 0, 0, 0, 0}

Dim pdWinData As IntPtr = Marshal.UnsafeAddrOfPinnedArrayElement(dWinData, 0)

inStatus= ipp.sp.ippsSet_64f(1.0, pdWinData, dWinData.Length)

Regards,

Albert

0 Kudos
cernek
Beginner
322 Views

Hi Albert, Thank you. The compiler likes it. Now I see whether it works...

EdC

0 Kudos
Reply