view R/scratch/callbacks.R @ 46:c21d1c2c84e1

- removed pydc.py wrapper overhead (which only called pydcext.so functions, directly, anyways) * implies renaming pydcext.* to pydc.* * while at it, iterate directly over args that are passed in (before we did extract fptr, sig and a tuple for the args and iterated over latter afterwards); we might have a tiny perf improvement now - added type stub as package_data
author Tassilo Philipp
date Fri, 13 Nov 2020 14:10:31 +0100
parents 0cfcc391201f
children
line wrap: on
line source



dynbind("user32","RegisterClassEx(p)p;")


C.struct <- function(signature) {
	map <- strsplit(signature,'[; \t\n]+')[[1]]
	if (map[1] == "")
	  map <- map[-1]
	n <- length(map)
	types   <- map[seq(1,n,by=2)]
	ids     <- map[seq(2,n,by=2)]
	sizes   <- C.sizes[types]
	offsets <- c(0,cumsum(sizes))
	ids     <- c(ids,".sizeof")
	types   <- c(types,"")
	sizes   <- c(sizes,"")
	data.frame(
		id=ids,
		type=types,
		size=sizes,
		offset=offsets,
		row.names=1
	)
}

WNDCLASSEX <- "
UINT cbSize;
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HINSTANCE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCTSTR lpszMenuName;
LPCTSTR lpszClassName;
HICON hIconSm;
"

WNDCLASSEX <- C.struct("
UINT cbSize;
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HINSTANCE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCTSTR lpszMenuName;
LPCTSTR lpszClassName;
HICON hIconSm;
") 

library(rdyncall)

allocC <- function(info)
{
  x <- malloc(sizeof(info))
  attr(x, "cstruct") <- info
  class(x) <- "cstruct"
  return(x)
}

packC <- function( address, offset, type, value )
{
  
}


"$.Cstruct<-" <- function (cstruct, name, value)
{
  info <- attr(x, "cstruct")
  element <- info[name,]
  packC( cstruct, element$offset, sigchar(element$type), value )
  return(value)
}

winclass <- allocC(WNDCLASS) 
winclass$cbSize <- sizeofC(WNDCLASS) 
RegisterClassEx(winclass)