Call COM object method from Go without CGo

后端 未结 2 609
一整个雨季
一整个雨季 2021-02-10 23:40

I have created a Direct3D9 wrapper in Go which uses CGo to interface with the COM objects in C.

I would like to get rid of the dependency on a C-compiler under Windows s

2条回答
  •  臣服心动
    2021-02-11 00:17

    (Not a comprehensive answer as I have no time to actually test this, but still…)

    While MSDN most of the time assumes you work with COM objects using some platform which has built-in "glue" for them (such as Visual C++™ product or something like this), in fact it is possible to work with COM objects using plain C—look here and here for starters.

    Studying those resources you can learn that calling methods on a "COM interface" amounts to properly working with its "VTBL" (Virtual function TaBLe) block which is always located in a well-known place relative to the pointer disguised by that "interface" "thing" returned by functions instantiating COM objects.

    The go-ole package implements in plain Go what you'd otherwise do in plain C, so armed with the knowledge of "to call methods on a COM objects we need to operate on its VTBL" we can find the implementation of IDispatch support in that package. So I'd start there.


    I'd also go right into the go-ole issue tracker asking for implementing a piece of example code which would show how to call methods on a COM object's handler acquired by means other than calling functions from go-ole package.

提交回复
热议问题