I'm using WINAPI dll written in C++ using DllImport for accessing USB ADC/DAC converter values. The only problem is:
long ZGetBufferADC(long typeDevice, long numberDSP, void **buffer, long *size)
I've translated it into
[DllImport("Zadc.dll")]
public static extern Int32 ZGetBufferADC(Int32 typeDevice, Int32 numberDSP, out IntPtr buffer, out Int32 size);
I call this function like that
Int32 err = ZGetBufferADC(typeDevice, numberDSP, out pBuffer, out sizeBufferADC);
Then I need to access resulting pBuffer in C# like that in C++:
short *pBuffer16ADC = (short*) pBuffer
volt0 = resolutionADC0 * (pBuffer16ADC[pointerADC]) / amplifyADC0;
where pointerADC is Int32 pointing to current value of ADC converter, i managed to get it w/o problems correctly
so how could i implement that structure in c#? I tried defining variables like that
IntPtr pBuffer;
Int16 pBuffer16ADC;
pBuffer16ADC = (Int16)pBuffer;
volt0 = resolutionADC0 * (pBuffer16ADC[pointerADC]) / amplifyADC0;
but that throws an error
Cannot apply indexing with [] to an expression of type 'short'
Any help will be appreciated! If additional info is needed please ask i'll provide ASAP. This issue is driving me nuts for almost a week :( Thanks!
IntPtr bufferfilled byZGetBufferADC, useIntPtr p = Marshal.ReadIntPtr(buffer);ThenpBuffer16ADC = Marshal.ReadInt16(p);short *pBuffer16ADC = (short*) *pBuffer;Your C++ code fragment doesn't match function definition.code short *pBuffer16ADC = (short*)pBuffer (w/o asterisk before pBuffer) that it's how it's written in c++ assuming pBuffer is defined like void *pBuffer; Can I upload code somewhere? It's not large, and easy-to-read. Maybe I am missing something.&pBuffer16ADCto the function. And that is a double pointer.