/* OCaml-Win32
 * win32_string.c
 * Copyright (c) 2002-2004 by Harry Chomsky
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "win32.h"

/********************************************************************/
/* User Interface: Windows User Experience: Windows Management: Windows User Interface: Resources: Strings */

CAMLprim value load_string(value hinstance, value id, value max_length)
{
    CAMLparam3(hinstance, id, max_length);
    HINSTANCE h;
    int n;
    char* s;
    int length;
    CAMLlocal1(result);

    h = Handle_val(hinstance);
    n = Int_val(max_length) + 1;
    s = malloc(n);
    enter_blocking_section();
    length = LoadString(h, Int_val(id), s, n);
    leave_blocking_section();
    if (length == 0) {
        free(s);
        raise_last_error();
    }
    result = copy_string(s);
    free(s);
    CAMLreturn(result);
}
