-
May 31st, 2012, 07:18 AM
#1
Inject .NET assembly into running .NET process
Hello!
I have a problem: I have a .NET process in which my unmanaged FreeBasic DLL is loaded by a global windows hook.
From this DLL, I wanted to inject a VB.NET DLL into the project and call a VB.NET function in the context of the already running .NET runtime.
I created the following C++ DLL as a "loader":
Code:
// HermesLibLoader.cpp : Definiert die exportierten Funktionen für die DLL-Anwendung.
//
#include "stdafx.h"
#include "mscoree.h"
#include "HermesLibLoader.h"
#pragma comment(lib, "mscoree.lib")
HERMESLIBLOADER_API HRESULT fnHermesLibLoader(LPCWSTR szFilename, LPCWSTR szParam)
{
ICLRRuntimeHost *pClrHost = NULL;
HRESULT hr = CorBindToRuntimeEx(NULL, L"wks", 0, CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (PVOID*)&pClrHost);
if(!SUCCEEDED(hr)) return hr;
DWORD dwRet = 0;
hr = pClrHost->ExecuteInDefaultAppDomain(szFilename, L"HermesClass", L"Init", szParam, &dwRet);
pClrHost->Release();
if(!SUCCEEDED(hr)) return hr;
if(dwRet != 42) return ERROR_INVALID_DATA;
return ERROR_SUCCESS;
}
...and the following VB.NET DLL ("HermesLib.dll"):
Code:
Public Class HermesClass
Public Shared Function Init(ByVal Parameter As String) As Integer
HelloWorld(Parameter)
Return 42
End Function
Public Shared Sub HelloWorld(ByVal Parameter As String)
MsgBox("Hello World from Hermes! (Param = """ & Parameter & """)")
End Sub
End Class
What happens is, I get a HRESULT of 0x80131522 (COR_E_TYPELOAD).
Can you help me?
Best regards,
Cherry
-
May 31st, 2012, 07:20 AM
#2
Re: Inject .NET assembly into running .NET process
Addition (I cannot find the post edit function...?!):
I am calling fnHermesLibLoader from my FreeBasic DLL like this:
Code:
fnHermesLibLoader("c:\full\path\to\HermesLib.dll", "Test Parameter")
-
May 31st, 2012, 07:36 AM
#3
Re: Inject .NET assembly into running .NET process
EDIT2: I also tried "HermesLib.HermesClass" in my ExecuteInDefaultAppDomain call, but I get the same error...
-
May 31st, 2012, 11:54 PM
#4
Re: Inject .NET assembly into running .NET process
Problem resolved: The second attempt ("HermesLib.HermesClass") was actually correct, but I made a mistake and put a comma there instead of a period.
Thanks anyway.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|