0

Framework 4.5 I am trying to load my DLL directly from my resources, i have very specific reasons on why i need my DLL loaded this way.

How can i get this method to work? & what am i doing wrong?

VB.net @ ApplicationEvents.vb source

        Private Sub AppStart(ByVal sender As Object,
      ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
            AddHandler AppDomain.CurrentDomain.AssemblyResolve, AddressOf ResolveAssemblies
        End Sub

    Private Function ResolveAssemblies(sender As Object, e As System.ResolveEventArgs) As Reflection.Assembly
        Dim desiredAssembly = New Reflection.AssemblyName(e.Name)

        If desiredAssembly.Name = "ASSEMBLE.REM" Then
            Dim assembly1 As System.Reflection.Assembly = Reflection.Assembly.Load(My.Resources.Attatch_standard)
            Dim t As Type = assembly1.GetType("ASSEMBLE.REM")
            Dim c As Object = Activator.CreateInstance(t)
            MsgBox(desiredAssembly.Name)
            Return Reflection.Assembly.Load(My.Resources.Attatch_standard) 'replace with your assembly's resource name
        Else
            Return Nothing
        End If
    End Function

C++ DLL source

#include <Windows.h>

namespace ASSEMBLE{
    extern "C" __declspec(dllexport) class REM {
    public:
        int area() { 
              MessageBoxA(NULL, "Attached", "Attached!", MB_OK);
              return 1; 
        }
    };
}
THE AMAZING
  • 1,496
  • 2
  • 16
  • 38
  • This can only work for .NET assemblies, not DLLs that contain native code. They need to exist on disk. Only reason it works for assemblies is because they contain data, not code. – Hans Passant Feb 23 '15 at 11:02
  • 1
    http://stackoverflow.com/a/768429/2319909 - Enjoy – Sam Makin Feb 23 '15 at 13:06

0 Answers0