What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » unicode problem

unicode problem
Author: Message:
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: unicode problem
code:
/*

    _readFile coded by Matty

    This function will read the contents of a file and print out the contents regardless of being unicode or ansi.
    If you use this function please make sure to give credit where credit is due.

*/


function OnEvent_Initialize(MessengerStart) {
    _readFile('C:\\WndSelect.handler.js', true);
}

function _readFile(_s_file, _is_debugging){
    /* Use the windows api function CreateFileW to open the file ONLY if it already exists */
    var _h_file = Interop.Call('kernel32', 'CreateFileW', '\\\\?\\'+_s_file,
                                                          0x80000000 /* GENERIC_READ */,
                                                          0x01 /* FILE_SHARE_READ */,
                                                          0,
                                                          3 /* OPEN_EXISTING */,
                                                          0,
                                                          0);
    /* Check to make sure the pointer is actually to a file instead of an invalid handle */
    if (_h_file > -1 /* INVALID_HANDLE_VALUE */) {
        if (_is_debugging === true) Debug.Trace('_h_file : '+_h_file);
        /* Now that we have a pointer to the file its time to read the size of the file so we know how much to read */
        var _n_size = Interop.Call('kernel32', 'GetFileSize', _h_file, 0);
        if (_is_debugging === true) Debug.Trace('_n_size : '+_n_size);
        /* Create a buffer to read in the data and another buffer to store the number of bytes that have been read */
        var _n_buffer = Interop.Allocate((2*_n_size)+2);
        var _n_bytes_read = Interop.Allocate(4);
        /* Read the file */
        Interop.Call('kernel32', 'ReadFile', _h_file, _n_buffer, _n_size, _n_bytes_read, 0);
        /* Close the file */
        Interop.Call('kernel32', 'CloseHandle', _h_file);
       
        /* Check if the file is unicode, if it is read the contents of _n_buffer as unicode, otherwise read it as ansi */
        if (_n_buffer.ReadString(0, false) === '˙ūv'){
            if (_is_debugging === true) Debug.Trace('_n_buffer : '+_n_buffer.ReadString(0, true));
            return _n_buffer.ReadString(0, true);
        } else {
            if (_is_debugging === true) Debug.Trace('_n_buffer : '+_n_buffer.ReadString(0, false));
            return _n_buffer.ReadString(0, false);
        }
    }
}

This post was edited on 02-03-2007 at 05:50 PM by matty.
02-03-2007 05:47 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
unicode problem - by ceceboy on 02-02-2007 at 10:10 PM
RE: unicode problem - by J-Thread on 02-03-2007 at 09:05 AM
RE: unicode problem - by matty on 02-03-2007 at 05:47 PM
RE: unicode problem - by Eljay on 02-03-2007 at 10:53 PM
RE: unicode problem - by CookieRevised on 02-04-2007 at 12:39 AM
RE: unicode problem - by Eljay on 02-04-2007 at 08:35 AM
RE: unicode problem - by CookieRevised on 02-04-2007 at 03:20 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On