pb调用SHFileOperation出错的问题

//

PB11里直接按网上的写法。执行是有OK有错误。还是pfrom和pto末尾需要两个null字符的问题。本想在string后面直接加两个字符,也是不行(因为字符串后面你加再多的"\0"都不起作用,null本来就是字符串的结束符--我是这样理解的)。后面看到blob的例子。方才搞定。看来对数据块的引用传递时,还是blob好。另外记得EncodingANSI!

声明:

Function long SHFileOperation(ref SHFILEOPSTRUCT lpFileOp) Library "shell32.dll" Alias FOR "SHFileOperationA;ansi"

//变量

Private Constant int FO_MOVE = 1 // &H1
Private Constant int FO_COPY = 2 //&H2
Private Constant int FO_DELETE =3 //&H3
Private Constant int FO_RENAME =4 //&H4
Private Constant int FOF_NOCONFIRMATION =16 //&H10
Private Constant int FOF_SILENT = 4 //&H4
Private Constant int FOF_NOERRORUI = 1024 //&H400

//stru

type SHFILEOPSTRUCT from structure
uLong hwnd
uLong wFunc
blob pFrom
blob pTo
long fFlags
long fAnyOperationsAborted
long hNameMappings
string lpszProgressTitle
end type

//func

//public function long of_rename_file (long lfrmhwnd, string sfrom, string sto, boolean fshowprogress)

SHFILEOPSTRUCT udtPath

udtPath.hwnd = lfrmhWnd
udtPath.wFunc = FO_RENAME

udtPath.pFrom = blob(sfrom,EncodingANSI!) + blob(char(0),EncodingANSI!) + blob(char(0),EncodingANSI!)
udtPath.pTo = blob(sto,EncodingANSI!) + blob(char(0),EncodingANSI!) + blob(char(0),EncodingANSI!)

long ll_bitvalues[]

ll_bitvalues[1] = FOF_NOCONFIRMATION
ll_bitvalues[2] = FOF_NOERRORUI
If fShowProgress then
ll_bitvalues[3] = 0
else
ll_bitvalues[3] = FOF_SILENT
end if

udtPath.fFlags = gf_bit_or(ll_bitvalues)

return SHFileOperation(udtPath)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值