Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

struct and type comparing

Status
Not open for further replies.

Denyson

Programmer
Mar 20, 2001
19
BR
Hi,

I would like to compare a struct created in C++ and a type created in VB 6.0. They must be equal.
Please anybody check the variables types for me.

C++

struct icPar
{
LONG icCmd;
LONG icContPassTotal;
LONG icContCartTotal;
LONG icContPassParc;
LONG icContCartParc;
LONG icEstFita;
LONG icRot;
LONG icCoordX;
LONG icCoordY;
LONG icTipoFonte;
LONG icTamFonte;
LONG icEstilo;
LONG icCoerc;
char icNmArq[8];
LONG icDirEsc;
LONG icTrilha;
LONG icDensTrilha1;
LONG icDensTrilha2;
LONG icDensTrilha3;
LONG icTamBuf;
LONG icTipCodBar;
LONG icIndExiNum;
LONG icAltCodBar;
LONG icCodRet;
LONG icCodErro;
char icBuffer[255];
};

VB 6.0

Private Type icPar
icCmd As Long
icContPassTotal As Long
icContCartTotal As Long
icContPassParc As Long
icContCartParc As Long
icEstFita As Long
icRot As Long
icCoordX As Long
icCoordY As Long
icTipoFonte As Long
icTamFonte As Long
icEstilo As Long
icCoerc As Long
icNmArq As String
icDirEsc As Long
icTrilha As Long
icDensTrilha1 As Long
icDensTrilha2 As Long
icDensTrilha3 As Long
icTamBuf As Long
icTipCodBar As Long
icIndExiNum As Long
icAltCodBar As Long
icCodRet As Long
icCodErro As Long
icBuffer As String
End Type

Thanks
 
Couple notes..

First the variables you declare as STRING should be STRING * 8 or STRING * 255.

icNmq as string * 7

Even better would be

icNmq(0 to 7) as Byte

The reason you need to make this disctinction is that VB strings have length stored in memory (instead of being NULL terminated) and if you are going to read in a C/C++ structure from disk, you need to make sure only 8 bytes are read in, so you need to use a fixed length string. If you leave it as STRING, VB will try to find the length value at the end of the string structure and get very confused.

Second, I am assuming that LONG is a signed 32 bit integer. VB variables are always signed, so keep that in mind if you are going to modify the values.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top