[ create a new paste ] login | about

Link: http://codepad.org/voP5cIMb    [ raw code | fork ]

C++, pasted on Jan 8:
#define CYL_DET_NATIVE_IMPL
#include "CylonDetectorNative.h"

namespace {

ref struct AssemblyResolver
{
    static System::Reflection::Assembly^
    MyResolveEventHandler(System::Object^ sender,
            System::ResolveEventArgs^ args)
    {
        namespace sr = System::Reflection;
        namespace sio = System::IO;

        return sr::Assembly::LoadFile(
                sio::Path::Combine(sio::Path::GetDirectoryName(
                        sr::Assembly::GetExecutingAssembly()->Location),
                    "Util.dll"));
    }
};

}

// "Invisible"
// {
// LoadLibrary("Util.dll")
static detector* real_initialize()
{
    return new detector(gcnew Util::CylonDetector);
}
// } throws FileNotFoundException / EELoadFileException / SEH Wrapper thereof

DLL detector* DLLCALL get_cylon_detector()
{
    try {
        System::AppDomain::CurrentDomain->AssemblyResolve +=
            gcnew System::ResolveEventHandler(
                    AssemblyResolver::MyResolveEventHandler);
        return real_initialize();
    } catch (...) {
        return nullptr;
    }
}

DLL void DLLCALL release_cylon_detector(detector *det)
{
    delete det;
}

DLL bool DLLCALL is_cylon(detector *det, const char *name)
{
    try {
        return det->get()->isCylon(gcnew System::String(name));
    } catch (...) {
        // innocent until proven guilty...
        return false;
    }
}


Create a new paste based on this one


Comments: