How to use syscall.Syscall to call a C function accept/return a structure on Windows

144 views
Skip to first unread message

aihui zhu

unread,
Oct 31, 2020, 5:51:36 AM10/31/20
to golang-nuts
the syscall.Syscall function accept/return only uintptr, how should i deal with structure?

i'm asking this question is because that i want to avoid CGo and use pure Go in my module.
thank you.

Ian Lance Taylor

unread,
Oct 31, 2020, 11:40:59 AM10/31/20
to aihui zhu, golang-nuts
On Sat, Oct 31, 2020 at 2:52 AM aihui zhu <mr.z...@gmail.com> wrote:
>
> the syscall.Syscall function accept/return only uintptr, how should i deal with structure?
>
> i'm asking this question is because that i want to avoid CGo and use pure Go in my module.

What Windows function do you want to call, and what is the structure type?

Ian

aihui zhu

unread,
Oct 31, 2020, 8:45:55 PM10/31/20
to golang-nuts
for example:

void D2D1MakeRotateMatrix(
  FLOAT             angle,
  D2D1_POINT_2F     center,
  D2D1_MATRIX_3X2_F *matrix
);
and a COM based function: D2D1_SIZE_F ID2D1Bitmap_GetSize();

On Saturday, October 31, 2020 at 11:40:59 PM UTC+8, Ian Lance Taylor wrote:

Ian Lance Taylor

unread,
Nov 10, 2020, 10:24:41 AM11/10/20
to aihui zhu, golang-nuts
On Sat, Oct 31, 2020 at 5:46 PM aihui zhu <mr.z...@gmail.com> wrote:
>
> for example:
>
> void D2D1MakeRotateMatrix(
> FLOAT angle,
> D2D1_POINT_2F center,
> D2D1_MATRIX_3X2_F *matrix
> );
> and a COM based function: D2D1_SIZE_F ID2D1Bitmap_GetSize();

Based on reading
https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention I
think the right way to call this will be to define a variable of type
D2D1MakeRotateMatrix and then pass the address of that variable as the
argument to Bitmap_GetSize. But I haven't tried this or anything.

A simple approach would be to use cgo.

Ian


> On Saturday, October 31, 2020 at 11:40:59 PM UTC+8, Ian Lance Taylor wrote:
>>
>> On Sat, Oct 31, 2020 at 2:52 AM aihui zhu <mr....@gmail.com> wrote:
>> >
>> > the syscall.Syscall function accept/return only uintptr, how should i deal with structure?
>> >
>> > i'm asking this question is because that i want to avoid CGo and use pure Go in my module.
>>
>> What Windows function do you want to call, and what is the structure type?
>>
>> Ian
>
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/eebb0188-fea8-4aba-8e6b-296e41b0da8co%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages