Skip to content

Instantly share code, notes, and snippets.

@kaneta1992
Created October 25, 2017 05:22
Show Gist options
  • Save kaneta1992/8816dcad87d13fb2d9fea739d467ba87 to your computer and use it in GitHub Desktop.
Save kaneta1992/8816dcad87d13fb2d9fea739d467ba87 to your computer and use it in GitHub Desktop.
package main
import (
"log"
"syscall"
"unsafe"
)
type IUnknown struct {
v *IUnknownVTable
}
type IUnknownVTable struct {
QueryInterface uintptr
AddRef uintptr
Release uintptr
}
type ID3D11Device struct {
v *ID3D11DeviceVTable
}
type ID3D11DeviceVTable struct {
IUnknownVTable
CreateBuffer uintptr
CreateTexture1D uintptr
CreateTexture2D uintptr
CreateTexture3D uintptr
CreateShaderResourceView uintptr
CreateUnorderedAccessView uintptr
CreateRenderTargetView uintptr
CreateDepthStencilView uintptr
CreateInputLayout uintptr
CreateVertexShader uintptr
CreateGeometryShader uintptr
CreateGeometryShaderWithStreamOutput uintptr
CreatePixelShader uintptr
CreateHullShader uintptr
CreateDomainShader uintptr
CreateComputeShader uintptr
CreateClassLinkage uintptr
CreateBlendState uintptr
CreateDepthStencilState uintptr
CreateRasterizerState uintptr
CreateSamplerState uintptr
CreateQuery uintptr
CreatePredicate uintptr
CreateCounter uintptr
CreateDeferredContext uintptr
OpenSharedResource uintptr
CheckFormatSupport uintptr
CheckMultisampleQualityLevels uintptr
CheckCounterInfo uintptr
CheckCounter uintptr
CheckFeatureSupport uintptr
GetPrivateData uintptr
SetPrivateData uintptr
SetPrivateDataInterface uintptr
GetFeatureLevel uintptr
GetCreationFlags uintptr
GetDeviceRemovedReason uintptr
GetImmediateContext uintptr
SetExceptionMode uintptr
GetExceptionMode uintptr
}
func main() {
d3d11, err := syscall.LoadLibrary("d3d11.dll")
if err != nil {
log.Fatal(err)
}
d3D11CreateDevice, err := syscall.GetProcAddress(d3d11, "D3D11CreateDevice")
if err != nil {
log.Fatal(err)
}
createDeviceFlags := 2
driverTypes := []int{
1,
2,
3,
}
featureLevels := [1]int {
45056,
}
var featureLevel int
var device *ID3D11Device
var context uintptr
var nargs uintptr = 10
ret, _, err := syscall.Syscall12(uintptr(d3D11CreateDevice),
nargs,
0,
uintptr(driverTypes[0]),
0,
uintptr(createDeviceFlags),
uintptr(unsafe.Pointer(&featureLevels)),
1,
7,
uintptr(unsafe.Pointer(&device)),
uintptr(unsafe.Pointer(&featureLevel)),
uintptr(unsafe.Pointer(&context)),
0,
0)
log.Printf("%v\n", err)
log.Printf("%v\n", ret)
log.Printf("%v\n", featureLevel)
log.Printf("%v\n", device)
log.Printf("%v\n", context)
ret, _, err = syscall.Syscall(uintptr(device.v.GetCreationFlags), 1, uintptr(unsafe.Pointer(device)), 0, 0)
log.Printf("%v\n", err)
log.Printf("%v\n", ret)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment