<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                [TOC] `test.h` ``` #ifndef TEST_H #define TEST_H #ifdef TEST_DLL_EXPORT #define TEST_API __declspec(dllexport) #else #define TEST_API __declspec(dllimport) #endif TEST_API void greet(char *name); TEST_API char *name(); #endif ``` `test.c` ``` #define TEST_DLL_EXPORT #include "test.h" #include <stdio.h> #include <stdlib.h> #include <string.h> void greet(char *name) { printf("Hello, %s!\n", name); } char *name() { char buf[] = "Gopher"; char *n = malloc(strlen(buf) + 1); strcpy(n, buf); n[strlen(buf)] = '\0'; return n; } ``` 執行gcc,生成dll `gcc -shared -o test.dll test.c` 調用 ``` dll := syscall.MustLoadDLL("test.dll") procGreet := dll.MustFindProc("greet") procGreet.Call(uintptr(unsafe.Pointer(syscall.StringBytePtr("Cynhard")))) //StringBytePtr 可用 BytePtrFromString 替換 procName := dll.MustFindProc("name") r, _, _ := procName.Call() // 獲取C返回的指針。 // 注意C返回的r為char*,對應的Go類型為*byte p := (*byte)(unsafe.Pointer(r)) // 定義一個[]byte切片,用來存儲C返回的字符串 data := make([]byte, 0) // 遍歷C返回的char指針,直到 '\0' 為止 for *p != 0 { data = append(data, *p) // 將得到的byte追加到末尾 r += unsafe.Sizeof(byte(0)) // 移動指針,指向下一個char p = (*byte)(unsafe.Pointer(r)) // 獲取指針的值,此時指針已經指向下一個char } name := string(data) // 將data轉換為字符串 fmt.Printf("Hello, %s!\n", name) ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看