RE: CopyFileEx API Call

new topic     » goto parent     » topic index » view thread      » older message » newer message

Elliott S. de Andrade wrote:
> 
> >
> >posted by: Larry Miller <lmiller7 at mail.com>
> >
> >I have been trying to use the CopyFileEx function with a call back 
> >routine provided by call_back(). The copy works and progress is 
> >reported, but there is a machine exception when CopyFileEx returns. I 
> >believe the problem is that CopyFileEx is passing too many parameters. 
> >It passes no less than 9 separate parameters, 4 of which are 
> >LARGE_INTEGERS, for a total of 13 32 bit values. According to the 
> >Euphoria documentation a maximum of 9 are allowed for a callback 
> >function.
> >
> 
>    A LARGE_INTEGER is a union of a long long and two long's (ie. a 64-bit=
> integer that can be accessed as two 32-bit integers). It should be regarded=
> as a pointer (to the 64-bit integer.) That should give you exactly 9
> parameters, just enough...

Actually, these are passed by value, so he really does have 13 parameters.
You can have an unlimited number of parameters by using fptr.e:

http://www.rapideuphoria.com/fptr.zip

Here is an example:

include fptr.e
include dll.e

constant
k32 = open_dll( "kernel32.dll" ),
xCopyFileEx = define_c_func( k32, "CopyFileExA", repeat( C_POINTER, 6 ), C_LONG
)

constant
PROGRESS_CONTINUE   = 0,
PROGRESS_CANCEL     = 1,
PROGRESS_STOP       = 2,
PROGRESS_QUIET      = 3

function cb_fptr( atom total_file_size1, atom total_file_size2, 
					 atom total_bytes_transferred1, atom total_bytes_transferred2,
					 atom stream_size1, atom stream_size2,
					 atom stream_bytes_transferred1, atom stream_bytes_transferred2,
					 atom rest )
		atom stream_number, call_back_reason, source_file, destination_file, data
		sequence params
		
		params = peek4u( rest & 5 )
		stream_number = params[1]
		call_back_reason = params[2]
		source_file = params[3]
		destination_file = params[4]
		data = params[5]
		
printf(1,
"fptr:\n%08x\t%08x\n%08x\t%08x\n%08x\t%08x\n%08x\t%08x\n%08x\t%08x\t%08x\t%08x\t%08x\n",
{total_file_size1, total_file_size2,
total_bytes_transferred1,total_bytes_transferred2,
stream_size1, stream_size2, stream_bytes_transferred1,
stream_bytes_transferred2,
			 stream_number, call_back_reason, source_file, destination_file, data } )
		return 0
end function

constant 
fptr    = call_back_stdcall( routine_id("cb_fptr"), 13 ),
source  = allocate_string( "test_copy_source.txt" ),
dest    = allocate_string( "test_copy_dest.txt" ),
lpData  = allocate( 4 ),
cancel  = allocate( 4 )
poke4( cancel, 0 )

printf(1,"lpData: %08x\n", lpData )
? c_func( xCopyFileEx, { source, dest, fptr, lpData, cancel, 0 })
puts(1,"Done\n")
include get.e
abort(wait_key())

 

Matt Lewis

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu