[go-nuts] Re: Please help me with structure data alignment

2022-11-24 Thread Maxim Velivanov
My bad. it turns out that the API dll has a directive
#pragma pack (1)

On Thursday, November 24, 2022 at 7:08:54 AM UTC+2 Maxim Velivanov wrote:

> Hi,
>
> I'm developing a Go wrapper for a dll.
> dll contains the following structure:
> struct ck_version {
>   unsigned char major;
>   unsigned char minor;
> };
>
> struct ck_info {
>   struct ck_version cryptoki_version;
>   unsigned char manufacturer_id[32];
>   ck_flags_t flags;
>   unsigned char library_description[32];
>   struct ck_version library_version;
> };
>
> in Go there is its analogue:
> type Ck_version struct {
> Major uint8
> Minor uint8
> }
>
> type Ck_info struct {
> Cryptoki_versionCk_version
> Manufacturer_id [32]byte
> Flags   uint32
> Library_description [32]byte
> Library_version Ck_version
> }
>
> when i call the function
> info := Ck_info{}
> rv, _, _ := c_GetInfo.Call(uintptr(unsafe.Pointer()))
>
> then I get the data offset starting from the flags field.
>
> I understand that Go has different data alignment in structures than C 
> compiler. But how then does a wrapper with tons of structures work in this 
> project golang.org/x/sys/windows? Maybe I missed something?
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/89d7405b-a55b-42d6-8e2b-ccc006c137e9n%40googlegroups.com.


[go-nuts] Please help me with structure data alignment

2022-11-23 Thread Maxim Velivanov
Hi,

I'm developing a Go wrapper for a dll.
dll contains the following structure:
struct ck_version {
  unsigned char major;
  unsigned char minor;
};

struct ck_info {
  struct ck_version cryptoki_version;
  unsigned char manufacturer_id[32];
  ck_flags_t flags;
  unsigned char library_description[32];
  struct ck_version library_version;
};

in Go there is its analogue:
type Ck_version struct {
Major uint8
Minor uint8
}

type Ck_info struct {
Cryptoki_versionCk_version
Manufacturer_id [32]byte
Flags   uint32
Library_description [32]byte
Library_version Ck_version
}

when i call the function
info := Ck_info{}
rv, _, _ := c_GetInfo.Call(uintptr(unsafe.Pointer()))

then I get the data offset starting from the flags field.

I understand that Go has different data alignment in structures than C 
compiler. But how then does a wrapper with tons of structures work in this 
project golang.org/x/sys/windows? Maybe I missed something?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20cc4c3b-b7fb-4c6b-b09d-333069d59d76n%40googlegroups.com.