11-28-2012 02:26 AM
Nathand> are there any white papers/articles on this as I am about to hit a similar problem. Thankfully i created the dll so have a bit more control over the data types I use
11-28-2012 03:40 AM
Thank you, nathand, for your help. I will try to do this. Your explained way seems to be legit 🙂
11-28-2012 03:48 AM
Nathand, here is the code, maybe you could show me, what do you mean by saying adding 3 bytes and 2 bytes. The thing is, that I am trying to connect to device and read the values of photodiode and use them with motor sync. But the main problem, is to read that struct.
11-28-2012 04:03 AM
Also, my header file does not includes a #pragma pack() line.
11-28-2012 06:28 AM
I fixed it! Everything is working perfectly, the problem was that short, char or int should be set to u32.
Thank you all for your help!
11-28-2012 08:13 AM
@SimasLTU wrote:
I fixed it! Everything is working perfectly, the problem was that short, char or int should be set to u32.
Thank you all for your help!
Yes, this will have the same effect as adding padding because it will force all elements to be aligned as though they're long (4-byte values). This won't always work, but in your case it does due to the way your struct is arranged. You might find that some values aren't where you expect them to be, though (the short values might end up in the high 2 bytes instead of the low 2 bytes). If the char and short parameters return values larger than those types can hold when you represent them as a U32, then you need to look at whether the data is in the correct byte.
11-28-2012 10:29 AM
@Akiel wrote:
Nathand> are there any white papers/articles on this as I am about to hit a similar problem. Thankfully i created the dll so have a bit more control over the data types I use
I don't know of any one white paper that covers everything, but there are certainly links available that will help. Start with an understanding of struct packing and alignment; an internet search on the "#pragma pack" compiler directive will help (MSDN is usually a good source). These two links on the NI site are useful: How LabVIEW Stores Data in Memory and Clusters in LabVIEW Do Not Line Up With Structures in Visual C++. Also, RolfK has contributed many posts on this topic to this forum, which you may find by searching the forum for "dll alignment." I find that I often get better results from a Google search for "site:forums.ni.com dll alignment" than I do with the forum's built-in search.