Ugh, stupid TCHAR problems. Anyone able to tell me how to fix this in EUcode?

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

The function should return a text buffer I can parse to get the local system's drives. Unfortunately the API function returns the text in a TCHAR buffer which creates garbage output when I try to read it. Here is my code:

constant kernel32 = open_dll( "kernel32.dll" ), 
                 xGetFreeSpace = define_c_func(kernel32, "GetDiskFreeSpaceExA",  
{C_POINTER, C_POINTER, C_POINTER, C_POINTER}, C_INT), 
                 xGetMetrics = define_c_func(kernel32, "GetDiskFreeSpaceA",  
{C_POINTER, C_POINTER, C_POINTER, C_POINTER, C_POINTER}, C_INT), 
                 xGetDriveType = define_c_func(kernel32, "GetDriveTypeA",  
{C_POINTER}, C_INT), 
                 xGetDriveStrings = define_c_func(kernel32, "GetLogicalDriveStringsA",  
{C_DOUBLE, C_POINTER}, C_INT) 
 
global function get_all_drives() 
 
	sequence drivestrings 
	atom retptr, converted_addr 
	 
	atom buflen 
 
	retptr = allocate(8)	-- allocate 8 bytes for the pointer to the buffer 
	 
	buflen = c_func(xGetDriveStrings, {200, retptr})  
        -- bufeln s/b size of buffer, 200 = max size I am allowing buffer, retptr should catch 
        -- address of buffer 
 
	if buflen > 0 then       -- function has given me a vale > 0 so function succeeded 
		-- ok to work 
		drivestrings = sprintf("GOOD RETURN: %d  ", {buflen}) 
-- convert 8 bytes to address 
                converted_addr = peek4u(retptr)+(peek4u(retptr+4) * #100000000)   
-- peek the text from the buffer  
		drivestrings &= w32peek_string(converted_addr) 	 
 
	else 
		drivestrings = "BAD RETURN" 
	end if 
	 
	free(retptr) 
	 
	return drivestrings 
	 
end function 
 

On my system this code creates the output: GOOD RETURN: 37 222222

EDIT: The output should show the character representations of all my computer drives. (i.e. C:, D:, etc.) EDIT2: I have 9 drives on my system so 3 chars + null * 9 + end null = 37. The function seems to be returning correctly... just don't know how to read the buffer. :(

The MSDN reference site for GetLogicalDriveStringsA says that it creates a buffer using TCHARs. So how can I convert these to a regular euphoria character string?

Any help, as always, is greatly appreciated! I'm using EU 3.1.1

Thanks! Steve A.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu