Shoutbox

ReadFile API - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: ReadFile API (/showthread.php?tid=66116)

ReadFile API by matty on 09-11-2006 at 08:52 PM

code:
var GENERIC_READ = 0x80000000;
var FILE_BEGIN = 0;
var FILE_SHARE_READ = 1;
var OPEN_EXISTING = 3;

function OnEvent_Initialize(MessengerStart){
    var hOrgFile = Interop.Call('kernel32', 'CreateFileW', 'c:\\test.txt', GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
    var nSize = Interop.Call('kernel32', 'GetFileSize', hOrgFile, 0);
    Debug.Trace('nSize: '+nSize);
    var sText = Interop.Allocate(nSize+1);
    var lRet = Interop.Allocate(4);
    Interop.Call('kernel32', 'ReadFile', hOrgFile, sText, nSize, lRet.DataPtr, 0);
    Debug.Trace(lRet.ReadDWORD(0));
    Debug.Trace(sText.ReadString(0));
    Interop.Call('kernel32', 'CloseHandle', hOrgFile);
}

sText.ReadDWORD(0) is null and lRet.ReadDWORD(0) is 0.

Not sure what I am doing wrong.

ReadFile API msdn
RE: ReadFile API by Mnjul on 09-11-2006 at 09:04 PM

Confirmed, I was testing this with Matty...WriteFile doesn't seem to work either, by the way.


RE: ReadFile API by -dt- on 09-11-2006 at 11:07 PM

I had a problem with this ages ago aswell http://shoutbox.menthix.net/showthread.php?tid=58419


RE: ReadFile API by RaceProUK on 09-11-2006 at 11:18 PM

Isn't there an ActiveX control you can use for file I/O instead of the raw API? I'm sure I've seen one before.

Edit: Like below.


RE: ReadFile API by alexp2_ad on 09-11-2006 at 11:20 PM

Can't you just use the Scripting.FileSystemObject?

http://mpwiki.net/Text_Files

It's a lot easier and works.

Unless I'm missing some obvious reason you had to use that.


RE: ReadFile API by matty on 09-12-2006 at 01:01 AM

Screenshot Sender 4 already uses FileSystemObject but for some very odd reason it gives errors when initializing for some people however it is properly installed because I can call it on that PC through a normal EXE. So instead of having ActiveX dependencies why not make it pure API.

quote:
Originally posted by alexp2_ad
Can't you just use the Scripting.FileSystemObject?

http://mpwiki.net/Text_Files

It's a lot easier and works.

Unless I'm missing some obvious reason you had to use that.

And I don't mean to be rude, but obviously if I am going as far as using the Windows API I would know about simple scripting objects.
RE: ReadFile API by Patchou on 09-12-2006 at 05:46 AM

Thanks for the report, I can't believe those two bugs were not fixed before now:

Interop.GetLastError() now actually works
Values from 0x80000000 to 0xFFFFFFFF can now be passed safely to Interop.Call

For those of you interested in the details: I just foudn out that values above 0x80000000 are always sent by JScript as "double" (8bit) instead of "integer" (probably because unsigned values arent generally safe in scripting environement).


RE: RE: ReadFile API by alexp2_ad on 09-12-2006 at 09:18 AM

quote:
Originally posted by Matty
Screenshot Sender 4 already uses FileSystemObject but for some very odd reason it gives errors when initializing for some people however it is properly installed because I can call it on that PC through a normal EXE. So instead of having ActiveX dependencies why not make it pure API.

And I don't mean to be rude, but obviously if I am going as far as using the Windows API I would know about simple scripting objects.

Lol, why to people say "I don't mean to be rude but" then be rude. :P

I just wanted to know why you couldn't use the fso so I could learn more. :^)