基於Ifilter介面的文件解析

2021-06-16 11:51:45 字數 968 閱讀 6797

ifilter介面是windows自帶的文件解析的介面,windows search, sql 檢索, share point等使用的都是該介面,目前該介面在win7 和 xp系統中都可使用。

ifilter介面派生於iunknow, 所以自帶函式queryinte***ce, addeef, release, 其主要使用以下幾個函式:init, getchunk, gettext, getvalue; 各函式具體情況見msdn。

以下是實現解析的函式:

(原始碼來自 原始碼其實比較簡單的使用了ifilter介面的函式,直接使用原始碼會使得解析出來的中文標點符號出現錯誤,所以要去掉validunicode()和cleanupcharacters()函式.

hresult cifilter::extracttext(bstr filename, long maxlength, bstr * filetext)

hr = spifilter->getchunk(&statchunk);

atltrace(_t("getchunk() hr=%x, breaktype=%d, flags=%x\n"), hr, statchunk.breaktype, statchunk.flags);

if (succeeded(hr))

bool moretext = true;

while (moretext)

if (filter_s_last_text == hr)

if (filter_e_no_more_text ==hr)

if (filter_e_no_text == hr)}}

*filetext = sysallocstring(wout.str().c_str());

}else}}

else}}

else

}else}}

catch (...)

return hr;

}

基於Ifilter介面的文件解析 2

本節是對 基於ifilter介面的文件解析 的補充,根據loadfilter的原理重寫該函式,重寫後不需要安裝office軟體,只需取出相應的ifilter元件,通過自行進行登錄檔註冊就可以了。loadfilter的流程如下 以.pdf為例,開啟登錄檔 1.在hkey local machine s...

C 基於介面的排序

需要注意的是int32,int16 string,decimal等資料型別已經實現了icomparable介面 因此對於複雜的資料型別進行排序的時候才考慮讓資料型別繼承自icomparable介面。icomparable介面只有乙個方法compareto。因此還要實現compareto方法。comp...

基於字元介面的聊天程式1 0

編譯器 vs2013 community vc6.0 執行亦可,但要注意函式的更新,如更安全的函式,etc 伺服器端程式流程 1 載入套接字型檔 2 建立套接字 socket 3 將套接字繫結到乙個本地位址和埠上 bind 4 將套接字設為監聽模式,準備接收客戶請求 listen 5 等待客戶請求到...