PB代码,请大虾帮忙翻译成VB的,重分酬谢!!

xiaowen01 2006-10-09 11:27:50
$PBExportHeader$nv_compression_untitle.sru
$PBExportComments$Compression NVO(无头信息)
forward
global type nv_compression_untitle from nonvisualobject
end type
end forward

global type nv_compression_untitle from nonvisualobject
end type
global nv_compression_untitle nv_compression_untitle

type prototypes
/* Win32 declarations */

function integer compress (ref blob dest, ref long DestLen, ref blob src, long srcLen) library "zlib.dll"
function integer uncompress (ref blob dest, ref long DestLen, ref blob src, long srcLen) library "zlib.dll"

/* Win16 declarations */

function integer compress16 (ref blob dest, ref long DestLen, ref blob src, long srcLen) alias for compress library "zlib16.dll"
function integer uncompress16(ref blob dest, ref long DestLen, ref blob src, long srcLen) alias for uncompress library "zlib16.dll"

end prototypes

type variables
boolean ib_Win32
end variables

forward prototypes
public function integer of_selectfile (ref string as_filename)
public function integer of_getfilename (string as_filename, ref string as_file, ref string as_dir)
public function string of_getfilename (string as_filename)
public function integer of_readfile (string as_filename, ref blob abl_data)
public function integer of_uncompressfile (string as_filename)
public function integer of_compressfile (string as_filename)
public function long of_writefile (string as_filename, ref blob abl_data)
public function integer of_uncompress (ref string as_indicator, ref blob abl_data, ref blob abl_res)
public function integer of_alloc (long al_len, ref blob abl_data)
public function integer of_compress (string as_indicator, ref blob abl_data, ref blob abl_res)
end prototypes

public function integer of_selectfile (ref string as_filename);/*

returns : integer (1=ok,-1=error)
arg1 : string as_FileName (FileName of he selected file)
This function selects a filename.
string ls_docname, ls_named
integer li_Value
/* get a filename with the standard dialog box */
li_value = GetFileOpenName("Select File", &
+ ls_docname, ls_named )
if li_Value <= 0 then return -1
/* return the selected filename */
as_filename = ls_named
return 1
end function
...全文
75 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
woods 2006-10-09
好麻烦!哈哈
回复
xiaowen01 2006-10-09
主要是上方这几句
回复
xiaowen01 2006-10-09
of_alloc(4,abl_res)
blobedit(abl_res,1,ll_Srclen)
lbl_temp = blobmid(lbl_Temp,1,ll_DestLen)
abl_res = lbl_temp + abl_res
回复
xiaowen01 2006-10-09
接上:
public function integer of_getfilename (string as_filename, ref string as_file, ref string as_dir);String ls_filename

Long ll_pos,ll_pos_act
ls_filename = as_filename
If Pos(ls_filename,'\') <= 0 Then Return -1
DO
ll_pos_act = ll_pos
ll_pos = Pos(ls_filename,'\',ll_pos + 1)
LOOP WHILE ll_pos > 0

as_file = Right(ls_filename,Len(ls_filename) - ll_pos_act)
as_dir = Left(ls_filename,ll_pos_act)
end function

public function string of_getfilename (string as_filename);Long ll_pos
ll_pos = Pos(as_filename,'.')
If ll_pos > 0 Then Return Left(as_filename,ll_pos - 1) Else Return as_filename

end function

public function integer of_readfile (string as_filename, ref blob abl_data);/*

SetPointer(HourGlass!)

blob lbl_temp
long ll_file

/* open the file */
ll_file = fileopen(as_filename,streammode!)

if ll_File <= 0 then
messagebox('Error reading file',as_filename)
return -1
end if

/* read the whole file */
do while fileread(ll_file,lbl_temp) > 0
abl_data += lbl_temp
loop

fileclose(ll_file)

/* return the binair data */
return 1
end function

public function integer of_uncompressfile (string as_filename);blob lbl_org
blob lbl_dest

if of_Readfile(as_Filename,lbl_org) < 0 then return -1
/* uncompress it */
if of_unCompress(as_FileName,lbl_Org,lbl_Dest) < 0 then return -1
/* write it */
if of_WriteFile(as_FileName,lbl_dest) < 0 then return -1
return 1

end function

public function integer of_compressfile (string as_filename);/*

string ls_filename
blob lbl_org
blob lbl_dest


/* read file */
if of_Readfile(as_Filename,lbl_org) < 0 then return -1
/* compress file */
if of_Compress(as_FileName,lbl_Org,lbl_Dest) < 0 then return -1
/* write compressed file */
if of_WriteFile( mid(as_FileName, 1, len(as_filename) - 3 ) + 'zli',lbl_dest) < 0 then return -1
return 1

end function

public function long of_writefile (string as_filename, ref blob abl_data);/*
Function : nv_Compression::of_writefile
Author : Eric-Jan Aling, Cypres Informatisering bv
Date : 21-09-1998

returns : integer (-1=error, >=0 number of bytes written)
arg1 : string as_FileName (Filename of the file to write)
arg2 : ref blob abl_data (source data)

This function writes the contents of the abl_data blob to disk
with the specified filename.

Revision record
Date Author Modification
------ ---------- ------------------
21-09-98 EALI1 Initial revision
*/

SetPointer(HourGlass!)

long ll_file
long ll_written
long ll_tot
long ll_writ

/* Open or create the file in replace mode */

ll_file = fileopen(as_filename,streammode!,write!,lockwrite!,replace!)


if ll_File <= 0 then
messagebox('Error writing file',as_filename)
return -1
end if

/* write the contents to that file */
ll_tot = len(abl_data)
do while true

ll_writ = filewrite(ll_file,blobmid(abl_data,ll_written+1) )
if ll_writ = 0 then exit
ll_written += ll_writ
if ll_Written >= ll_tot then exit

loop

/* don't forget to close the file */
fileclose(ll_file)

/* return the number of bytes written */
return ll_written
end function

public function integer of_uncompress (ref string as_indicator, ref blob abl_data, ref blob abl_res);/*
Function : nv_Compression::of_uncompress
Author : Eric-Jan Aling, Cypres Informatisering bv
Date : 21-09-1998

returns : integer (1=ok,-1=error)
arg1 : ref string as_Indicator (indicator to indicate the data)
arg2 : ref blob abl_data (source data)
arg3 : ref blob abl_res (compressed destination data)

This function uncompresses the blob abl_data and returns the uncompressed
blob and the indicator through the arguments by reference.

Revision record
Date Author Modification
------ ---------- ------------------
21-09-98 EALI1 Initial revision
*/


SetPointer(HourGlass!)

/* the function uncompresses the compressed data */

blob lbl_result
integer li_Ret
blob lbl_Src
long ll_SrcLen
long ll_DestLen

/* 16bit variables */

blob lbl_temp
blob lbl_data[]
long ll_begin[]
long ll_end[]
long ll_len[]
long ll_SegMents
long ll_SegMent

/* in 32bit mode, we presume we have 1 chunk only */

if ib_Win32 then

ll_srcLen = FileLength(as_indicator)
ll_destlen = long(blobmid(abl_data,len(abl_data) - 3,4))
as_indicator = of_getfilename(as_indicator) + ".txt"
/* allocate memory for the uncompress proces */
of_Alloc(ll_DestLen,abl_res)
// lbl_Src = blobmid(abl_data,256 + 13)
lbl_Src = blobmid(abl_data,1)
ll_Srclen = len(lbl_Src)
//
/* uncompress the comporessed chunk */
li_Ret = uncompress(abl_res,ll_DestLen,lbl_Src,ll_Srclen)

if li_Ret <> 0 then
messagebox('Error Uncompresssing',li_Ret)
return -1
end if

/* return the uncompressed data */
return 1
end if

end function

public function integer of_alloc (long al_len, ref blob abl_data);/*
Function : nv_Compression::of_Alloc
Author : Eric-Jan Aling, Cypres Informatisering bv
Date : 21-09-1998

returns : integer (1=ok, -1=error)
arg1 : long al_len (number of bytes to allocate)
arg2 : ref blob abl_data (blob to hold the data)

This function allocates the specified amount of memory and
stores the allocation in a blob variable which is passed
by reference.

Revision record
Date Author Modification
------ ---------- ------------------
21-09-98 EALI1 Initial revision
*/



SetPointer(HourGlass!)

/* in 32bit mode, we can allocate in one go */

if ib_Win32 then

abl_data = blob(space(al_len))
return 1


else

/* in 16bit mode, we allocate in chunks of 64K if size is bigger than 60000 bytes */

if al_len > 60000 then
blob{65535} lbl_Chunk
do while true
abl_data += lbl_Chunk
if len(abl_data) >= al_len then exit
loop
abl_data = blobmid(abl_data,1,al_len)
return 1
else
abl_data = blob(space(al_len))
return 1
end if

end if

return 0




end function

public function integer of_compress (string as_indicator, ref blob abl_data, ref blob abl_res);/*
Function : nv_Compression::of_compress
Author : Eric-Jan Aling, Cypres Informatisering bv
Date : 21-09-1998

returns : integer (1=ok,-1=error)
arg1 : string as_Indicator (indicator to indicate the data)
arg2 : ref blob abl_data (source data)
arg3 : ref blob abl_res (compressed destination data)

This function compresses the blob abl_data and returns the compressed blob with the indicator.

Revision record
Date Author Modification
------ ---------- ------------------
21-09-98 EALI1 Initial revision
*/


SetPointer(HourGlass!)

/* 32bit variables */

long ll_OrigLen
blob lbl_Temp
long ll_DestLen
long ll_SrcLen
integer li_ret
blob lbl_Src

/* 16bit variables */

blob lbl_Temp16[]
long ll_Segments
long ll_Segment
long ll_begin
long ll_DestLen16[]
long ll_Chunk = 60000

/* in 32bit mode, we can compress in 1 chunk */

if ib_Win32 then

ll_OrigLen = len(abl_data)
ll_Srclen = ll_OrigLen
ll_DestLen = ll_SrcLen + (ll_SrcLen*0.01) + 12

/* Allocate memory for the compress process */

of_alloc(ll_DestLen,lbl_Temp)
li_Ret = compress( lbl_Temp, ll_DestLen, abl_Data, ll_srcLen)
if li_ret <> 0 then
messagebox('Error compressing', li_ret)
return -1
end if

/* Allocate memory for the 'prefix'*/

of_alloc(4,abl_res)
blobedit(abl_res,1,ll_Srclen)
lbl_temp = blobmid(lbl_Temp,1,ll_DestLen)
abl_res = lbl_temp + abl_res
return 1
end if
end function

on nv_compression_untitle.create
call super::create
TriggerEvent( this, "constructor" )
end on

on nv_compression_untitle.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on

event constructor;environment lenv_Env

GetEnvironment(lenv_Env)

ib_Win32 = not lenv_Env.win16

return 0
end event


回复
相关推荐
发帖
PowerBuilder
创建于2007-09-28

891

社区成员

PowerBuilder 相关问题讨论
申请成为版主
帖子事件
创建了帖子
2006-10-09 11:27
社区公告
暂无公告