#include "stdafx.h"
#include "apr_general.h"
#include "apr_strings.h"
#include "apr_thread_proc.h"
#include "apr_dso.h"
#include "apr_errno.h"

static apr_pool_t *context;

#define LIB_NAME ""
#define FILE_NAME "C:\\projects\\ApacheAPR\\TstApr\\SampleDLL\\Debug\\sampledll.dll"

typedef int (*SampleFunc)(void);

void TstDSO() {
    apr_dso_handle_t *h = NULL;
    apr_dso_handle_sym_t func = NULL;
    apr_status_t status;
	SampleFunc function;
    int retval;
    char filename[256];   

	printf( "Loading the DSO\n");
    if ((status = apr_dso_load(&h, FILE_NAME, context)) != APR_SUCCESS){
        char my_error[256];
        apr_strerror(status, my_error, sizeof(my_error));
        printf( "%s!\n", my_error);
        exit (-1);
    }

    if ((status = apr_dso_sym(&func, h, "fnSampleDLL")) != APR_SUCCESS) { 
        char my_error[256];
        apr_dso_error(h, my_error, sizeof(my_error));
        printf( "%s\n", my_error);
        exit (-1);
    }        

	function = (SampleFunc)func;    
    retval = (*function)();

    if (apr_dso_unload(h) != APR_SUCCESS) {
        printf( "Failed unload!\n");
        exit (-1);
    }
}

void APRMisc() {
	// Create the pool context
    if (apr_pool_create(&context, NULL) != APR_SUCCESS) {
        fprintf(stderr, "Couldn't allocate context.");
        exit(-1);
    }

	//TstDSO();

	apr_pool_destroy( context);
	return;
}

