Hello all
I am looking for a way to retrieve data from the unmanaged code (legacy) DLL to the .NET code as described below. I could NOT find any articles that would help me to do so successfully. Please help
Unmanaged-Code DLL (LEGACY.DLL)
---------------------------
struct EMBEDDED_ARRAY_DATA_STRUCTUR
short * pValueArray
INT32 nElementCount
}
void WINAPI FillData(EMBEDDED_ARRAY_DATA_STRUCTURE * pData
pData->nElementCount = 5
pData->pValueArray = new short [pData->nElementCount]
for (short i = 0; i < pData->nElementCount; i++
pData->pValueArray[i] = i
Managed-Code
------------------
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)
public struct EMBEDDED_ARRAY_DATA_STRUCTUR
public IntPtr pValueArray
public Int32 nElementCount
}
public class MyLegac
...
[DllImport("legacy.dll", CharSet=Charset.Ansi)
public static extern void FillData(ref EMBEDDED_ARRAY_DATA_STRUCTURE pData)
...
}
...
EMBEDDED_ARRAY_DATA_STRUCTURE pData = new EMBEDDED_ARRAY_DATA_STRUCTURE
MyLegacy.FillData(ref pData)
short [] myShortValueArray = new short [pData->nElementCount]
for (int i = 0; i < pData->nElementCount; i++
myShortValueArray[i] = Marshal.ReadInt16(pData->pValueArray, (int) i)
// The problem is that the contents of myShortValueArray is bogus! Please point out what I've done wrong or if there is
// better way to do so....I am desperately needing help!!!!
Peter N