如何加载DLL

时间:2015-02-23 09:43:26

标签: vb.net dll

Framework 4.5 我试图直接从我的资源加载我的DLL,我有非常具体的原因,为什么我需要我这样加载我的DLL。

我怎样才能使用此方法? &安培;我做错了什么?

VB.net @ApplicationEvents.vb来源

        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源

#include <Windows.h>

namespace ASSEMBLE{
    extern "C" __declspec(dllexport) class REM {
    public:
        int area() { 
              MessageBoxA(NULL, "Attached", "Attached!", MB_OK);
              return 1; 
        }
    };
}

0 个答案:

没有答案