[問題] 如何用thread執行其他檔案的函式

看板C_and_CPP作者 (痴漢)時間10年前 (2014/04/07 23:55), 10年前編輯推噓0(002)
留言2則, 2人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) VC++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) window.h 問題(Question): 目前是想用CreateThread來執行ReadData(LPVOID param)這個函式 這個函式因為有多個參數要傳入 因此是以class指標的形式傳入 因為不想把ReadData寫在同一個檔案 後來就把它分開寫到其他cpp和h檔 但後來在呼叫這個函式 就出現nonstatic member function的錯誤 想問有甚麼方法可以將ReadData(LPVOID param)改成static function 並且將參數一起傳入CreateThread()? 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版) 由於程式有點長,我只貼重要部分,共寫兩個程式 Serial類別的程式: DWORD WINAPI Serial::ReadData(LPVOID param){ // Read_param是Serial class裡的一個class Serial::Read_param *ptrRead_param = (Read_param*)param; // 採用指標方法存取class /* 其他code */ } 主程式: int main(){ float Serial_out; // 創一個class裝要傳入thread的參數 Serial::Read_param ReadData_argument={&Serial_out}; hThread_Read = CreateThread(NULL, 0, &Serial::ReadData, &ReadData_argument, 0, &dwThread); } 補充說明(Supplement): 裡面其他參數較不重要的參數我就沒打上去 錯誤主要就是CreateThread裡 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.114.14.135 ※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1396886126.A.5E7.html ※ 編輯: cwhgraham (140.114.214.68), 04/08/2014 00:41:05

04/08 03:26, , 1F
用一個struct把Serial object的this傳給stub function
04/08 03:26, 1F

04/10 15:52, , 2F
感謝
04/10 15:52, 2F
文章代碼(AID): #1JGifkNd (C_and_CPP)