#ifdef _MSC_VER
# if _MSVC_LANG <= 201402L
# include <complex.h>
typedef _Fcomplex GoComplex64;
typedef _Dcomplex GoComplex128;
# else
# include <complex>
typedef std::complex<float> GoComplex64;
typedef std::complex<double> GoComplex128;
# endif
#else
typedef float _Complex GoComplex64;
typedef double _Complex GoComplex128;
#endif
-
CGO生成的头文件,_Fcomplex、_Dcomplex未定义的解决办法
-
通过dll构建lib
首先根据dll编写一个def文件。然后在VS执行环境里执行以下命令就可以生成对应的lib文件。
lib /def:https_server.def /machine:x64 /out:https_server.lib
-
C EXE调用GO DLL实现HTTPS Server
这是一个HTTPS Server的例子,CEXE调用GODLL的函数启动HTTPS Server,Server收到数据后会调用CEXE中的回调函数将HTTP请求数据发送给CEXE并从CEXE处获得HTTP响应数据。
需要注意的是在C和GO之间进行变量类型转换的时候,如果使用C.CString和C.CBytes转换字符串或数据,则需要调用C.free释放内存,使用C.free的需要在import “C”前的C代码中引入头文件stdlib.h,否则会报错。
-
golang编写http server dll
package main // //Needed for build import "C" import ( "fmt" "io" "net/http" ) func homeHandler(w http.ResponseWriter, r *http.Request) { header := fmt.Sprintf("%s %s %s\r\n", r.Method, r.RequestURI, r.Proto) header += fmt.Sprintf("Host: %s\r\n", r.Host) for k, vs := range r.Header { header += fmt.Sprintf("%s: ", k) for _, v := range vs { header += v } header += "\r\n" } header += "\r\n" fmt.Fprintf(w, "%s", header) body, err := io.ReadAll(io.Reader(r.Body)) if err != nil { http.Error(w, "Error reading request body", http.StatusInternalServerError) return } w.Write(body) } //export main func main() { http.HandleFunc("/", homeHandler) http.ListenAndServe(":8000", nil) }
-
编译openssl-1.1.1w
我需要的是静态库,所以这里的内容都是围绕静态库的。
我需要以下3个版本:
1 release /MT 发布版本 2 debug /MDd 大多数情况下使用的调试版本 3 debug /MTd 主要用于使用debug_and_release方式编译的qt程序的调试 下面3个配置命令分别对应上面3个版本。但要注意的是,2和3在配置完成后,一定要手动修改makefile文件,将原本的/MT改成目标参数(/MDd或/MTd)。
- release
perl Configure VC-WIN64A no-asm no-shared no-sse2 zlib --with-zlib-include="D:\zlib-1.3.1\build" --with-zlib-lib="D:\zlib-1.3.1\zlibstatic.lib"
- debug (/MDd)
perl Configure no-asm no-shared no-sse2 zlib VC-WIN64A --debug --with-zlib-include=D:\zlib-1.3.1\build --with-zlib-lib=D:\zlib-1.3.1\zlibstaticd.lib
- debug (/MTd)
perl Configure no-asm no-shared no-sse2 zlib VC-WIN64A --debug --with-zlib-include=D:\zlib-1.3.1\build --with-zlib-lib=D:\zlib-1.3.1\zlibstaticd_mtd.lib
不拷贝手册文件
执行nmake install命令会消耗很多时间,因为该命令会拷贝很多手册文件。我并不需要这些文件,可以使用nmake install_sw命令,该命令只拷贝软件。
关于-–prefix和–openssldir参数
无论我怎么指定-–prefix和–openssldir参数,都无法修改安装目录,在Windows下始终是程序目录。
-
VisualStudio.gitignore
Visual Studio .gitignore文件,另外下面这个页面里还有很多其它IDE或编程语言的的.gitignore文件。
https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
(更多…)
-
使用wincrypt生成随机字符串
低效代码,用于生成少量随机字符串的场景。
//定义WIN32_LEAN_AND_MEAN以排除加密、DDE、RPC、Shell 和 Windows 套接字等 API。 #define WIN32_LEAN_AND_MEAN #include <Windows.h> #include <wincrypt.h> #include <stdio.h> //两个参数,分别是接收字符串的缓冲区地址和缓冲区长度(包含结尾的0,也就是说字符串的有效长度是len-1) BOOL GenRandomString(char *str, int len) { HCRYPTPROV hCryptProv; BYTE c; BOOL r = TRUE; if (CryptAcquireContextA( &hCryptProv, NULL, (LPCSTR) "Microsoft Base Cryptographic Provider v1.0", PROV_RSA_FULL, CRYPT_VERIFYCONTEXT) == FALSE) { return FALSE; } for (int i = 0; i < len - 1; i++) { if (CryptGenRandom(hCryptProv, 1, (BYTE *)&c)) { if (c >= 48 && c <= 57) { str[i] = c; } else if (c >= 65 && c <= 90) { str[i] = c; } else if (c >= 97 && c <= 122) { str[i] = c; } else { str[i] = c % 26 + 97; } } else { r = FALSE; break; } } CryptReleaseContext(hCryptProv, 0); if (r) { str[len - 1] = 0; } return r; } int main(void) { char str[10]; for (int i = 0; i < 100; i++) { GenRandomString(str, sizeof(str)); printf("%s\n", str); } return 1; }
-
《如何阅读一本书》摘要
(更多…)阅读的四个层次
- 基础阅读
这个层次中,要问读者的问题是“这个句子在说什么?”
- 检视阅读
在这个阅读层次,学生必须在规定的时间内完成一项阅读的功课。这个层次的典型问题就是“这本书在谈什么?”
- 分析阅读
这是全盘的阅读、完整的阅读,或者说是更优质的阅读,就是要咀嚼消化一本书。分析阅读就是特别在追寻理解的。
- 主题阅读
也可称为比较阅读。在做主题阅读时,阅读者会读很多书,而不是一本书,并列举出这些书之间相关之处,提出一个所有书都谈到的主题。主题阅读要求读者要能够架构出一个可能在哪一本书里都没提过的主题分析。