Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6056417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:22:26+00:00 2026-05-23T08:22:26+00:00

Using my non-existent knowledge of C++ (hey, at least I know what a pointer

  • 0

Using my non-existent knowledge of C++ (hey, at least I know what a pointer is 😛 ), I managed to throw together some code samples to create a solution that will inject a DLL file into another program.

Unfortunately, it’s the DLL I’m INJECTING that’s not working properly: it successfully displays the messageboxes (so I know the DLL is running), but it’s not actually creating the instance of the specified type (from the managed DLL, which has a static constructor in type Injectee that writes to a file). So, can anyone help me with where I’m going wrong? (N.B. the managed DLL is the same .Net version, and installed to the GAC. There’s also a copy in the same folder as the application I’m injecting into)

This is the unmanaged injectee (that’s supposed to load the managed DLL):

#include "stdafx.h"

#include "Injectee.h"

#include "stdafx.h"
#include <stdio.h>
#include "objbase.h"
#include "MSCorEE.h"
#import "C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.tlb" raw_interfaces_only
using namespace mscorlib;

void Bootstrap() {
    CoInitializeEx(0, COINIT_MULTITHREADED );
    ICorRuntimeHost* pICorRuntimeHost = 0;
    HRESULT st = CoCreateInstance(CLSID_CorRuntimeHost, 0, CLSCTX_ALL,
        IID_ICorRuntimeHost, (void**)&pICorRuntimeHost);
    if(!pICorRuntimeHost) {
        MessageBox(NULL, TEXT("Failed at stage 1."), TEXT("Error"), MB_OK); 
    }

    HDOMAINENUM hEnum = NULL;
    pICorRuntimeHost->EnumDomains(&hEnum);

    if(!hEnum) {
        MessageBox(NULL, TEXT("Failed at stage 2."), TEXT("Error"), MB_OK); 
    }

    IUnknown* pUunk = 0;
    st = pICorRuntimeHost->NextDomain(hEnum, &pUunk);
    if(!pUunk) {
        MessageBox(NULL, TEXT("Failed at stage 3."), TEXT("Error"), MB_OK); 
    }

    _AppDomain * pCurDomain = NULL;
    st = pUunk->QueryInterface(__uuidof(_AppDomain), (VOID**)&pCurDomain);
    if(!pCurDomain) {
        MessageBox(NULL, TEXT("Failed at stage 4."), TEXT("Error"), MB_OK); 
    }

    _bstr_t assemblyName = "ZAI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9db2aaea0fceabbb";
    _bstr_t typeName = "Injectee";

    _ObjectHandle* pObjectHandle = 0;

    MessageBox(NULL, TEXT("Loading DLL."), TEXT("Error"), MB_OK); 

    pCurDomain->CreateInstance(assemblyName, typeName, &pObjectHandle);
}

Any help?

(Note, managed assembly is built against both architectures (target app is x64), has base namespace ZAI))

Any advice is appreciated.

(In case you’re wondering, I’m trying to add an API to a freeware, closed-source .Net app)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:22:27+00:00Added an answer on May 23, 2026 at 8:22 am

    I imagine that creating a new CorRuntimeHost instance creates a new AppDomain.

    I would suggest writing a mixed-mode C++/CLI DLL and injecting that.


    If you’ve confirmed you did get a reference to the right AppDomain, call AppDomain::Load before CreateInstance. Or even AppDomain::ExecuteAssembly, if you set the entry point of your assembly to do something useful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 12 errors, but some are just pure non existent. I'm using the
I'm using the following code to have a non-JS navigation: <ol id=navigation> <li id=home><a
When I try to request for a non existent resource using a GET request
What is the quickest most efficient way to search text for words using non-casesensitive
AssemblyInstaller.Install expects a System.Collections.IDictionary. Am I right to be 'allergic' to using non-generic collections
I'm using Delphi7 (non-unicode VCL), I need to store lots of WideStrings inside a
I have a page that is using a non-standard font and arial as a
I unsuccessfully tried using txredis (the non blocking twisted api for redis) for a
I'm using the Django ORM in a non-Django application and would like to turn
I'm using SQL Server 2008 (non-R2) and trying to use Report Builder 3.0. When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.