星期四, 10月 19, 2006
神奇的'\0'
本以為在Arctic加delete file的function是一件很簡單的事~
沒想到…竟然花了3小時多Orz
其一是把char* 轉成LPCWSTR
其二是SHFileOperation的Source與Dest需要在字尾加上'\0\0'
結果用swprintf()搞了老半天,才發現...原來在裡面加\0是無用的!
比如說 swprintf( tmp_wchar, "%S\0\0", source_char )的結果,tmp_wchar字尾不會有\0\0
所以....土法鍊鋼,先用wcslen( tmp_wchar)算出長度,然後tmp_wchar[length]=0
雖說很久沒寫程式了,但是也不是這樣的吧.....
沒想到…竟然花了3小時多Orz
其一是把char* 轉成LPCWSTR
其二是SHFileOperation的Source與Dest需要在字尾加上'\0\0'
結果用swprintf()搞了老半天,才發現...原來在裡面加\0是無用的!
比如說 swprintf( tmp_wchar, "%S\0\0", source_char )的結果,tmp_wchar字尾不會有\0\0
所以....土法鍊鋼,先用wcslen( tmp_wchar)算出長度,然後tmp_wchar[length]=0
雖說很久沒寫程式了,但是也不是這樣的吧.....
星期三, 10月 18, 2006
Convert char* to LPCWSTR
example 1:
char a[] = "aaa";
WCHAR wsz[64];
swprintf(wsz, L"%S", a);
LPCWSTR p = wsz;
example 2:
char aaaa[20]="aaa";
LPCWSTR ppp=(WCHAR *)aaaa;
char a[] = "aaa";
WCHAR wsz[64];
swprintf(wsz, L"%S", a);
LPCWSTR p = wsz;
example 2:
char aaaa[20]="aaa";
LPCWSTR ppp=(WCHAR *)aaaa;
winapi delete file
使用windows api來移除檔案,主要有2種api:
一是windows shell的SHFileOperation
二是DeleteFileTransacted與DeleteFile
相關link:
windowssdk--- DeleteFile DeleteFileTransacted SHFileOperation
examples-------- Deleting locked files SHFileOperation Demo
Common Questions Concerning the SHFileOperation API: Part 1 Part 2
一是windows shell的SHFileOperation
二是DeleteFileTransacted與DeleteFile
相關link:
windowssdk--- DeleteFile DeleteFileTransacted SHFileOperation
examples-------- Deleting locked files SHFileOperation Demo
Common Questions Concerning the SHFileOperation API: Part 1 Part 2
訂閱:
文章 (Atom)