
/*
@param exportName - 导出函数名
@param retType - 返回值类型
@param argTypes - 参数类型数组
@param abiOrOptions - ABI类型或者NativeFunctionOptions类型
@param moduleName — 模块名或者路径默认为"Kernel32.dll"
*/
function EZ生成NativeFunction(exportName: string, 
    retType: NativeFunctionReturnType,
    argTypes: [] | NativeFunctionArgumentType[], 
    abiOrOptions: NativeABI | NativeFunctionOptions = "default",
    moduleName: string = "Kernel32.dll",
  ) {
  let address = Module.findExportByName(moduleName, exportName);
  return new NativeFunction(address!, retType, argTypes, abiOrOptions);
}

export default class Kernel32 {
  // DWORD GetCurrentThreadId();
  private static func_GetCurrentThreadId: AnyFunction;
  static GetCurrentThreadId(): number {
      if (this.func_GetCurrentThreadId == null) {
        this.func_GetCurrentThreadId = EZ生成NativeFunction("GetCurrentThreadId", "int", []);
      }
      return this.func_GetCurrentThreadId();
  }
  
  // void Sleep(
  //     [in] DWORD dwMilliseconds
  // );
  private static func_Sleep: AnyFunction;
  static Sleep(dwMilliseconds: number): void {
      if (this.func_Sleep == null) {
        this.func_Sleep = EZ生成NativeFunction("Sleep", "void", ["int"]);
      }
      return this.func_Sleep(dwMilliseconds);
  }

}