Noitidart / ostypes

Submodule for Firefox addons that need js-ctypes to tap into platform (Windows, Mac, Linux/Unix) APIs
2 stars 4 forks source link

How do i check for INVALID_HANDLE_VALUE from ReadFileEx #3

Open tofutim opened 8 years ago

tofutim commented 8 years ago

Previously I used if (ctypes.Int64.compare(pipeHandleInt.value, INVALID_HANDLE_VALUE.value) != 0) { with const INVALID_HANDLE_VALUE = ctypes.Int64(-1);

I'm tempted to switch INVALID_HANDLE_VALUE to ctypes.Int64(-1) but maybe even better to be able to directly compare?

tofutim commented 8 years ago

For now I will use

if (ctypes.Int64.compare(pipeHandleInt.value, ctypes.Int64(ostypes.CONST.INVALID_HANDLE_VALUE)) != 0) {

Noitidart commented 8 years ago

I was doing the same thing - https://github.com/Noitidart/jsc-pipes/blob/master/modules/pipe/PipeWorker.js#L242-L251

        var hFile = ostypes.API('CreateFile')(aPath, pipeMode, ostypes.CONST.FILE_SHARE_READ | ostypes.CONST.FILE_SHARE_WRITE, null, dwCreationDisposition, ostypes.CONST.FILE_ATTRIBUTE_NORMAL, null);
        var hFileInt = ctypes.cast(hFile, ctypes.int).value.toString();

        console.log('hFile:', hFile);
        console.log('hFile deep:', cutils.jscGetDeepest(hFile));
        console.log('hFile deep 10:', cutils.jscGetDeepest(hFile, 10));
        console.log('hFile deep 16:', cutils.jscGetDeepest(hFile, 16));
        console.log('hFileInt:', hFileInt);

        if (cutils.jscEqual(hFileInt, -1)) {

we should be able to use cutls.jscEqual(hFile, -1, 16), the third argument of 16 will turn the -1 into 0xffffff and it will find that hFile is the same. I havent landed this to ostypes repository though yet. Haven't worked on it yet .

Noitidart commented 8 years ago

Actually I think we should change the CONST declaration of INVALID_HANDLE_VALUE to match that of:

 WAIT_FAILED: self.TYPE.DWORD('0xFFFFFFFF'),

So then we can just do cutils.jscEqual(hFile, ostypes.CONST.INVALID_HANDLE_VALUE), what do you think?

So we would make it be:

 INVALID_HANDLE_VALUE: self.TYPE.HANDLE(ctypes.UInt64('0xFFFFFFFF')),
tofutim commented 8 years ago

I agree with that. Do you even need jscEqual? Can you compare directly?

On Mon, Mar 21, 2016 at 11:04 PM, Noitidart notifications@github.com wrote:

Actually I think we should change the CONST declaration of INVALID_HANDLE_VALUE to match that of:

WAIT_FAILED: self.TYPE.DWORD('0xFFFFFFFF'),

So then we can just do cutils.jscEqual(hFile, ostypes.CONST.INVALID_HANDLE_VALUE), what do you think?

So we would make it be:

INVALID_HANDLE_VALUE: self.TYPE.HANDLE(ctypes.UInt64('0xFFFFFFFF')),

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/Noitidart/ostypes/issues/3#issuecomment-199650975

Noitidart commented 8 years ago

You can compare directly but you have to turn them into strings first. Otherwise it's comparing a voidptr_t to a voidptr_t. Even though they are the same you can't compare javascript objects, and that's what it is. They are actually CData objects. So you can compare hFile.toString() == ostypes.CONST.INVALID_HANDLE_VALUE.toString().