Ejemplo n.º 1
0
void *
md_load_library(const char * name, char *err_buf, int err_buflen)
{
    void *result;
    
    char *p = strchr(name, '\\');
    if (p == NULL) {
        /*
         * No path elements in this library name and we don't want to
         * load just any version. We could use JVM_LoadSystemLibrary(),
         * but that would require exporting jvm.h into $JAVA_HOME/include
         * which we don't want to do just for this demo. Instead we look
         * for the library relative to the jvm.dll file.
         */
        char      buf[FILENAME_MAX+32];
        HINSTANCE jvm;
        char *    lastSlash;

        /* try to load the library relative to jvm.dll's location */
        buf[0] = 0;
        jvm = GetModuleHandle("jvm.dll");
        if (jvm == NULL) {
            strncpy(err_buf, "Cannot find jvm.dll", err_buflen-2);
            err_buf[err_buflen-1] = '\0';
            return NULL;
        }
        GetModuleFileName(jvm, buf, FILENAME_MAX);
        lastSlash = strrchr(buf, '\\');
        if (lastSlash == NULL) {
            strncpy(err_buf, "Cannot find path to jvm.dll", err_buflen-2);
            err_buf[err_buflen-1] = '\0';
            return NULL;
        }

        *lastSlash = '\0';
        strcat(buf, "\\..\\");
        strcat(buf, name);
        result = LoadLibrary(buf);
    } else {
        result = LoadLibrary(name);
    }

    if (result == NULL) {
	/* Error message is pretty lame, try to make a better guess. */
	long errcode;
	
	errcode = GetLastError();
	if (errcode == ERROR_MOD_NOT_FOUND) {
	    strncpy(err_buf, "Can't find dependent libraries", err_buflen-2);
	    err_buf[err_buflen-1] = '\0';
	} else {
	    get_last_error_string(err_buf, err_buflen);
	}
    }
    return result;
}
Ejemplo n.º 2
0
void *
md_load_library(const char * name, char *err_buf, int err_buflen)
{
    void *result;

    result = LoadLibrary(name);
    if (result == NULL) {
        /* Error message is pretty lame, try to make a better guess. */
        long errcode;

        errcode = GetLastError();
        if (errcode == ERROR_MOD_NOT_FOUND) {
            strncpy(err_buf, "Can't find dependent libraries", err_buflen-2);
            err_buf[err_buflen-1] = '\0';
        } else {
            get_last_error_string(err_buf, err_buflen);
        }
    }
    return result;
}