This repository was archived by the owner on Jan 2, 2024. It is now read-only.
reading a double value from an Exchange array #7
davecalkinshexagon
started this conversation in
General
Replies: 1 comment
-
Although BitConverter didn't work for making a generic version of the above, the below approach works. This uses Marshal.Copy to copy the bytes representing any generic type into the memory for a pinned variable of the generic type. With this, given an unmanaged pointer to an array of values, you can get the ith value (double, uint, etc).
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In Brad's intro video for ExchangeSharp, he provided a nice example of accessing individual pointer array elements. For example, when enumerating a product occurrence's child product occurrences, we can do something like the below, using Marshal.ReadIntPtr. In this case, m_ppPOccurrences is a pointer to an array of pointers and we can access one of them using this code.
Another case involves a pointer to an array of doubles. For example, A3DTessBaseData has m_pdCoords. This provides double values for markup tessellation. Marshal has methods for reading integral types in addition to pointers, but nothing for reading double values. I found and adapted some code for this and wanted to post it here in case its helpful to others.
I was hoping on making this a generic method to work with arbitrary primitive types, however, I couldn't figure out how to get BitConverter to support conversion to a generic type. If anyone has figured this out, I'd be curious to hear how they did it.
Beta Was this translation helpful? Give feedback.
All reactions