C 學習摘要

2021-10-02 01:37:45 字數 2308 閱讀 2762

q:動態載入dll後, 延遲解除安裝

記錄每次踩過的坑方便查詢.

場景說明

專案中有兩個標頭檔案(define.hclientudp.h),clientudp類中需要用到define.h中的型別定義.

define.h中定義函式指標型別時需要用到clientudp.h中的類定義

這就導致兩個標頭檔案迴圈包含???

編譯不通過

clientudp.h相關**

#pragma once

#include

"define.h"

#include

"result.h"

class networkudp;

// 客戶端連線

class clientudp

;

define.h相關**

#pragma once

// 這裡導致迴圈引用

#include

"clientudp.h"

#ifndef net_work_handle_func

#define net_work_handle_func

//udp資料處理函式

//@param _this 呼叫者

//@param ip 客戶端ip

//@param data 原始資料

//@param startpos 有效資料開始位置

//@param len 資料總長度

typedef

void

(*udphandlefunc)

(void

* _this, clientudp* clientudp, cbytearray data,

int startpos,

int len)

;#endif

// !net_work_handle_func

define.h中去掉型別定義標頭檔案(clientudp.h), 同時在使用的地方使用class type var做提前宣告

#pragma once

// 這裡導致迴圈引用

// #include "clientudp.h"

#ifndef net_work_handle_func

#define net_work_handle_func

//udp資料處理函式

//@param _this 呼叫者

//@param ip 客戶端ip

//@param data 原始資料

//@param startpos 有效資料開始位置

//@param len 資料總長度

typedef

void

(*udphandlefunc)

(void

* _this,class clientudp* clientudp, cbytearray data,

int startpos,

int len)

;#endif

// !net_work_handle_func

場景說明:

程式中需要動態載入各種元件, 同時希望在呼叫unload(string modname)時才解除安裝

先前按照正常思維, 通過new的方式獲取指標再解除安裝.(失敗)

hinstance的定義在wtypes.h中, 本身就是乙個指標. 因此直接使用即可

typedef

void

*hinstance;

使用場景

// 已載入dll

map loadeddlls;..

.// 解除安裝dll

freelibrary

(loadeddlls[modulename]);

loadeddlls.

erase

(modulename)

;

c 學習摘要

1.析構函式為什麼多為虛函式 基類的成員函式如果為虛函式,那麼其子類可以重新實現該函式,如果基類成員函式不為虛函式,那麼子類如果想擁有該方法需要過載。析構函式在物件銷毀時呼叫,用以銷毀物件內那些未被銷毀的變數。這就要求子類可以有自己的析構函式,來銷毀自己的需要銷毀的變數。2.什麼是純虛函式 基類本身...

C學習摘要

在 c 語言中,凡不加返回值型別限定的函式,就會被編譯器作為返回整型值處理。在多重迴圈中,如果有可能,應當將最長的迴圈放在最內層,最短的迴圈放在最外層,以減少 cpu 跨切迴圈層的次數。return 語句不可返回指向 棧記憶體 的 指標 因為該內存在函式體結束時被自動銷毀。大端模式 big endi...

C 學習摘要5

include using namespace std class point point int main include include using namespace std class document void getname class book public document void...