C# dllimport 备忘录

dllImport的入口点问题 通过Dependencies查询Dll对应方法的EntryPoint 然后在dllimport的attribute中显式申明EntryPoint [DllImport("demo.dll", SetLastError = true,EntryPoint ="??0DemoManager@EcgParser@Gfeit@@AEAA@XZ")] public static extern IntPtr DemoManager(); 导入类方法的问题 最好的方式还是使用C++构造wrapper,然后通过windowsApi的方式调用Pinvoke 参考链接 swig nuget swig C++/C# interoperability Working with C++ Interface Classes from C# Call function in unmanaged DLL from C# and pass custom data types [Marshal] SWIG and C# Example for SWIG to wrap C++ library in .Net 6

golang http Reverse Proxy使用备忘

创建 一般使用 使用 httputil.NewSingleHostReverseProxy 即可 返回Response 当我们想实现获取通过ReverseProxy的请求结果时,可以使用自定义的 responsewriter 来实现。参考定义 func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) { .... } type ResponseWriter interface { // Header returns the header map that will be sent by // WriteHeader. The Header map also is the mechanism with which // Handlers can set HTTP trailers. // // Changing the header map after a call to WriteHeader (or // Write) has no effect unless the modified headers are // trailers....

tailscale的泛型SingleFlight

源地址 tailscale仓库 完整代码如下 // Copyright (c) 2022 Tailscale Inc & AUTHORS All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Copyright 2013 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Package singleflight provides a duplicate function call suppression // mechanism....

Rasp3b 安装Postgresql

安装 系统信息 使用命令安装 yay -S postgresql 初始化及配置 启用数据库服务 sudo systemctl enable --now postgresql 开启数据库服务 sudo systemctl start postgresql 初始化数据 su - postgres -c "initdb --locale en_US.UTF-8 -D '/var/lib/postgres/data'" 查询配置文件路径 su - postgres [postgres@homeserver ~]$ ls data [postgres@homeserver ~]$ psql psql (14.5) 输入 "help" 来获取帮助信息. postgres=# SHOW config_file; config_file ---------------------------------------- /var/lib/postgres/data/postgresql.conf (1 行记录) 修改监听 修改配置/var/lib/postgres/data/postgresql.conf 文件中的listen_addresses = '*'监听所有地址,重启服务sudo systemctl restart postgresql生效。 允许远程访问 修改配置文件同级目录下的pg_hba.conf,添加一行 # TYPE DATABASE USER CIDR-ADDRESS METHOD host all all 0....

.NET6 从JSON获取配置

环境准备 nuget包 Microsoft.Extensions.Configuration Microsoft.Extensions.Configuration.Binder Microsoft.Extensions.Configuration.Json (当需要从Json文件添加记录时,安装此nuget包) Microsoft.Extensions.Configuration.EnvironmentVariables (当需要从环境变量添加记录时,安装此nuget包) C#开发环境 visual studio 2019 + visual Code 示例代码 // See https://aka.ms/new-console-template for more information using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration.Json; Console.WriteLine("Hello, World!"); ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); IConfiguration c = configurationBuilder.AddJsonFile("appsettings.json").AddEnvironmentVariables().Build(); var k = c.GetRequiredSection("Settings").Get<Settings>().KeyOne; var n = 1; public class NestedSettings { public string Message { get; set; } = null!; } public class Settings { public int KeyOne { get; set; } public bool KeyTwo { get; set; } public NestedSettings KeyThree { get; set; } = null!...

浅谈windows默认Shell的替换

Windows XP时代 Xp时代提供的是通过注册表来自定义shell 设置所有用户的shell 注册表键HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell 设置当前用户的shell注册表键 HKEY_Current_User\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell 注册表键值类型 REG_SZ 值修改为你要自定义为shell的程序的完整路径。 在windows10下使用该技巧可能会出现黑屏的现象,参考stackoverflow的回答 Simply replacing the “explorer.exe” (HKLM\SOFTWARE\Microsoft\Window NT\Winlogon\Shell) with a custom app location provided a black screen. A much simpler way, and it works great, was to create a BATCH script to call the custom app through elevated powershell… powershell -nologo -noprofile -executionpolicy bypass -command "start-process -verb 'runas' -filepath <full path of custom app executable>" By replacing “explorer.exe” with this batch script I was able to successfully create a kiosk style lockdown under Windows 10 PRO with a non-UWP app....

Golang 默认的CGO参数编译导致的GLIBC错误

问题描述 使用go正常编译了Linux下的程序,放到服务器上报错 ./app: /lib64/libc.so.6: version `GLIBC_2.34' not found (required by ./app) 解决 Google了下,发现相同的Issue,于是通过go env检查本机golang运行环境,发现CGO默认启用而且程序也不涉及CGO相关的东西,于是设置CGO参数为关闭。然后编译程序 CGO_ENABLED="0" go build -v 重新上传,运行OK.

在Alibaba Cloud Linux上安装MongoDB

安装步骤 查询系统版本 执行命令lsb_release -a返回下面的内容 LSB Version: :core-4.1-amd64:core-4.1-noarch Distributor ID: AlibabaCloud Description: Alibaba Cloud Linux release 3 (Soaring Falcon) Release: 3 Codename: SoaringFalcon 添加yum源 创建repo文件etc/yum.repos.d/mongodb.repo并输入下面的内容,这里安装的mongodb版本为6.0,其他版本请参考官网(配置偶数版本,奇数版不适合生产使用)。 官网的配置文件如下: [mongodb-org-6.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/6.0/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc 使用这个配置文件是安装不了的,需要修改$releasever为相应的版本,Alibaba Cloud Linux 3修改为8 (设置一个releasever的环境变量也许也可以,没有验证。)即可。即下面的样子 [mongodb-org-6.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/8/mongodb-org/6.0/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc 使用命令 yum -y install mongodb-org 安装即可。另外阿里云也提供了国内的镜像源,上面的配置文件可以修改为下面的内容,也是等效的。 [mongodb-org-6.0] name=MongoDB Repository baseurl=http://mirrors.aliyun.com/mongodb/yum/redhat/8/mongodb-org/6.0/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc 参考链接 如何在Alibaba Cloud Linux 3上安装MongoDB 5.0

golang http客户端使用自定义dns

摘自互联网 原文 package main import ( "context" "io/ioutil" "log" "net" "net/http" "time" ) func main() { var ( dnsResolverIP = "8.8.8.8:53" // Google DNS resolver. dnsResolverProto = "udp" // Protocol to use for the DNS resolver dnsResolverTimeoutMs = 5000 // Timeout (ms) for the DNS resolver (optional) ) dialer := &net.Dialer{ Resolver: &net.Resolver{ PreferGo: true, Dial: func(ctx context.Context, network, address string) (net.Conn, error) { d := net.Dialer{ Timeout: time.Duration(dnsResolverTimeoutMs) * time....

golang转换任意长度[] byte为int

package main import ( "encoding/binary" "fmt" ) func main() { slices := [][]byte{ {1}, {1, 2}, {1, 2, 3}, {1, 2, 3, 4}, {1, 2, 3, 4, 5}, {1, 2, 3, 4, 5, 6}, {1, 2, 3, 4, 5, 6, 7}, {1, 2, 3, 4, 5, 6, 7, 8}, } for _, s := range slices { fmt.Println(getInt1(s), getInt2(s)) } } func getInt1(s []byte) int { var b [8]byte copy(b[8-len(s):], s) return int(binary....