Last active
December 15, 2015 13:58
-
-
Save leviwilson/5270867 to your computer and use it in GitHub Desktop.
Dynamic assembly resolver in MC++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "StdAfx.h" | |
#include "DynamicAssemblyResolver.h" | |
void DynamicAssemblyResolver::PrivatePath::set(String^ path) { | |
_PrivatePath = path; | |
AppDomain::CurrentDomain->AssemblyResolve += gcnew ResolveEventHandler(Resolve); | |
} | |
Assembly^ DynamicAssemblyResolver::Resolve(Object^ sender, ResolveEventArgs^ args) | |
{ | |
try | |
{ | |
auto fullPrivatePath = Path::Combine(_PrivatePath, AssemblyFromQualifiedName(args->Name)); | |
return Assembly::LoadFrom(fullPrivatePath); | |
} | |
catch(...) { } | |
return nullptr; | |
} | |
String^ DynamicAssemblyResolver::AssemblyFromQualifiedName(String^ qualifiedName) | |
{ | |
return qualifiedName->Substring(0, qualifiedName->IndexOf(",")) + ".dll"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ffi' | |
module ExternalLibrary | |
extend FFI::Library | |
ffi_lib 'SomeExternalLibrary.dll' | |
attach_function :init, :InitializeLoadPath, [:string], :void | |
end | |
ExternalLibrary::init File.expand_path(File.dirname(__FILE__)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment