pckoster
asked on
Importing a binary file which contains packed datatypes
Hi,
I'm trying to import a file in VB, which is exported in a C++ routine. However, they used a pragma pack(1) in C++ to export the structure to the file. When I'm trying to import the file in VB, I get a shifting in the different members of the datatype.
The size of the struct saved in C++ is also smaller than the size of the datatype created in VB that I'm trying to import.
I'm using this datatype in C++:
struct {
char name[33];
char nRecChannels;
char invertedACChannels;
short maximumVoltage;
short normalVoltage;
short calibrationSignal;
short calibrationScale;
short videoControl;
unsigned short nSensitivities;
unsigned short nLowFilters;
unsigned short nHighFilters;
float sensitivity[32];
float lowFilter[32];
float highFilter[32];
char montageName[33];
};
And this equivalent in VB:
Type RecorderInfo
name As String * 33
nRecChannels As Byte
invertedACChannels As Byte
maximumVoltage As Integer
normalVoltage As Integer
calibrationSignal As Integer
calibrationScale As Integer
videoControl As Integer
nSensitivities As Integer
nLowFilters As Integer
nHighFilters As Integer
sensitivity(32) As Single
lowFilter(32) As Single
highFilter(32) As Single
montageName As String * 33
End Type
Everything until the 3 float-array's is imported as expected, then it goes wrong. The sensitivity float array imports nicely, but only 14 of the 32 items are filled in the file. Then there is a sort of overlap in the lowfilter array.
I guess this got to do with the pragma pack (1) used in C++, which is apperently not supported in VB.
Is there some sort of command for it, or a workaround?
Best regards.
I'm trying to import a file in VB, which is exported in a C++ routine. However, they used a pragma pack(1) in C++ to export the structure to the file. When I'm trying to import the file in VB, I get a shifting in the different members of the datatype.
The size of the struct saved in C++ is also smaller than the size of the datatype created in VB that I'm trying to import.
I'm using this datatype in C++:
struct {
char name[33];
char nRecChannels;
char invertedACChannels;
short maximumVoltage;
short normalVoltage;
short calibrationSignal;
short calibrationScale;
short videoControl;
unsigned short nSensitivities;
unsigned short nLowFilters;
unsigned short nHighFilters;
float sensitivity[32];
float lowFilter[32];
float highFilter[32];
char montageName[33];
};
And this equivalent in VB:
Type RecorderInfo
name As String * 33
nRecChannels As Byte
invertedACChannels As Byte
maximumVoltage As Integer
normalVoltage As Integer
calibrationSignal As Integer
calibrationScale As Integer
videoControl As Integer
nSensitivities As Integer
nLowFilters As Integer
nHighFilters As Integer
sensitivity(32) As Single
lowFilter(32) As Single
highFilter(32) As Single
montageName As String * 33
End Type
Everything until the 3 float-array's is imported as expected, then it goes wrong. The sensitivity float array imports nicely, but only 14 of the 32 items are filled in the file. Then there is a sort of overlap in the lowfilter array.
I guess this got to do with the pragma pack (1) used in C++, which is apperently not supported in VB.
Is there some sort of command for it, or a workaround?
Best regards.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanx,
so simple indeed. But when used to a C++ compiler so confusing :$
so simple indeed. But when used to a C++ compiler so confusing :$
Dim MyStruct as RecorderInfo
Input #1, MyStruct.name
Input #1, MyStruct.nRecChannels
Input #1, MySturct.invertedACChannel
Keep going like this, and the structure should be filled out correctly.