[C] String Copy

while (*s++ = *t++);

1. *s = *t
2. *s+=1 and *t+=1
3. *t == NULL ||  -> Exit
     *t != NULL     -> do 1

[MFC]Timer

.h
afx_msg void OnTimer(UINT_PTR nIDEvent)

Message map
ON_WM_TIMER()

void CDialog:: OnTimer(UINT nIDEvent)
{
CView:: OnTimer(nIDEvent);
switch (nIDEvent) ...

}

//OnInitialDialog
SetTimer(ANIMATE_MFT, 20, NULL);

//When Used
OnTimer(ANIMATE_TIMER);
OnTimer(ANIMATE_MFT);


//Destructor
KillTimer(ANIMATE_TIMER);

[MFC]Thread用到UpdateData

可參考http://realchecko.blogspot.com/2007/06/updatedata-in-thread.html
這篇寫得所蠻詳細的。

[MFC]Rich Edit 2.0 Control

在使用Rich Edit 2.0 Control時,要在App::InitInstance()裡,產生Dialog物件之前呼叫AfxInitRichEdit2()
這樣才能使得編譯出來的程式可以執行,不然會在.DoModal()的時候就會出現handle錯誤而結束。

SMTP Client - send mail

目前參照http://www.codeproject.com/KB/IP/CSmtp.aspx?fid=1525693&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=26所做出來的client端程式可正常運行。

唯獨在附加檔案的部份,一開始測試是讀取8k資料並傳送之,但是用outlook卻都收不到郵件。
由此可推測,是否是單一個section大小過大導致SMTP server拒絕接收郵件資料。

後來根據sample裡面設定的section大小(5k)來傳送,則可正常收到郵件。
故此目前先暫時用5k的section大小來傳遞檔案,以後有空的時候在來研究一下RFC。

Ref:RFC5246RFC2487

Mail Format:(以下每一段建立後皆立即送出,括弧內或是藍色文字為註解)
Mail From:<SP>UserName<MailAddress><CRLF>
RCPT To:<SP>UserName<MailAddress><CRLF>(包含副本跟密件副本的收件人)
DATA (以下為郵件本體)
Header Content Start
Date:<SP>day<SP>month<SP>year<SP>hour:min:sec<SP>zone<CRLF>
From:<SP>UserName<MailAddress><CRLF>
X-Mailer:<SP>X-Mailer<CRLF>
Reply-To:<SP>MailAddress<CRLF>
X-Priority:<SP>Priority<CRLF>
To:UserName<MailAddress>,UserName<MailAddress>,...<CRLF>
Cc:UserName<MailAddress>,UserName<MailAddress>,...<CRLF>
Bcc:UserName<MailAddress>,UserName<MailAddress>,...<CRLF>
Subject:<SP>Subject<CRLF>
MIME-Version:<SP>version<CRLF>
(無附加檔)
Content-type: text/plain; charset=US-ASCII<CRLF>
Content-Transfer-Encoding: 7bit<CRLF><CRLF>
(*有附加檔,BOUNDARY_TEXT自定,網路上範例都將內容寫的很長)
Content-Type: multipart/mixed; boundary="BOUNDARY_TEXT"<CRLF><CRLF>
--BOUNDARY_TEXT<CRLF>
Content-type: text/plain; charset=US-ASCII<CRLF>
Content-Transfer-Encoding: 7bit<CRLF><CRLF>
Header Content End
Message body
<CRLF>(每一行資料後面都要有crlf,但測試只有lf也是可以的。這邊郵件內容長度無限制,最好是一次送出)
(加入附加檔內容)
--BOUNDARY_TEXT<CRLF>
Content-Type: application/x-msdownload; name="FileName.ext"<CRLF>
Content-Transfer-Encoding: base64<CRLF>
Content-Disposition: attachment; filename="FileName.ext"<CRLF><CRLF>

(由Base64加密過的檔案內容,每一送出的Section大小不可超過6k)
(重覆做*,到所有檔案傳完為止)
--BOUNDARY_TEXT--(附加檔結束)
<CRLF>.<CRLF> (郵件內容傳送完畢)
QUIT<CRLF> (離開)

_SplitPath

C:\abc\123.txt => Drive = C:, Path = \abc\, FileName = 123, Extension = .txt
C:\abc\123.12.txt => Drive = C:, Path = \abc\, FileName = 123.12, Extension = .txt
C:\abc\123.txt.12 => Drive = C:, Path = \abc\, FileName = 123.txt, Extension = .12
\\192.168.1.1\abc\123.txt => Drive = "", Path = \\192.168.1.1\abc\, FileName = 123, Extension = .txt

[Win]Service存取網路磁碟

目前測試在要進行存取時,先呼叫LogonUser()
之後就可以用所輸入的使用者帳號來存取網路磁碟了。

存取完後需使用CloseHandle()來關閉Token並釋放記憶體即可。

dwLogonType設成 LOGON32_LOGON_INTERACTIVE或是LOGON32_LOGON_NEW_CREDENTIALS則都可以。

只是網路磁碟的路徑要使用UNC路徑才行,不然還是一樣會找不到路徑。

mapping過的路徑目前測試結果是service是一定讀不到檔案,原因則目前不明。

如有需讀取mapping路徑內之資料,請參考[Win]Mapping Disk的紀錄位置

PS.如有需要讓呼叫的執行檔也有同樣的權時,dwLogonType需設成LOGON32_LOGON_INTERACTIVEdwLogonProvider則要設為LOGON32_PROVIDER_DEFAULT

之後再使用 CreateProcessAsUser()來執行執行檔即可。需傳入的Token則為先前使用LogonUser()所取得的token。

[Container] 存有pointer的vector使用iterator取內容

使用方式如下

vector<CObj*>::iterator iterEnd = cObj.end();
vector<CObj*>::iterator iter = --iterEnd;

string strData = (*iter)->GetData();

[Reg]登入後自動啟動程式

將需執行的程式之路徑寫到下列Registry Key底下即可
Current User:
\\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

Local Machine:
\\HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run

一樣可以加入command line來使用。

KeyValue的Type為String,KeyValue名稱可自定

已知所支援之平台:
XP、Vista、Server2008

Build docker image from multiple build contexts

Build docker image from multiple build contexts ...