Does VB6 have the equivalent of #pragma pack?

I am developing a TCP / IP client that deals with a proprietary binary protocol. I considered using custom types to represent protocol headers and using CopyMemory to shuffle data into and out of the UDT and byte array. However, it looks like VB6 adds padding bytes to align user types. Is there a way to prevent VB6 from populating the UDT, similar to the directive #pragma packavailable in many C / C ++ compilers? Perhaps a special switch was passed to the compiler?

+4
source share
2 answers

No.

It is best to write low-level code in C or C ++ (where you have it #pragma pack), and then open the interface through COM.

+5

VB6 UDT, #pragma, C/++, .

Q194609 Visual Basic 4 Visual ++ 8 .

VB6 DLL C, MS "pshpack4.h" , -, ( ) :

// this is in a header file called vbstruct.h
...

# define VBSTRING       char
# define VBFIXEDSTRING  char
# define VBDATE         double
# define VBSINGLE       float

# ifdef _WIN32
#  define VBLONG        long
#  define VBINT         short
# else  // and this was for 16bit code not 64bit!!!!
#  define VBLONG        long
#  define VBINT         int
# endif
...

#  include "pshpack4.h"
...

typedef struct  VbComputerNameStruct
    {
    VBLONG           sName;
    VBSTRING         ComputerName[VB_COMPUTERNAME_LENGTH];
    }           VbComputerNameType;


typedef struct  VbNetwareLoginInfoStruct
    {
    VBLONG              ObjectId;
    VBINT               ObjectType;
    VBSTRING            ObjectName[48];
    }           VbNetwareLoginInfoType;
...

#  include "poppack.h"
+1

Source: https://habr.com/ru/post/1697598/


All Articles