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

  • SEARCH
  • Home
  • 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 9114923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:18:34+00:00 2026-06-17T04:18:34+00:00

I am currently trying to call a function from a C# DLL from an

  • 0

I am currently trying to call a function from a C# DLL from an unmanaged C++ app.

After searching for hours on the web and SO, I found I have a few options.

I can use COM, DllExport, or use reverse PInvoke with delegates. The last sounded most appealing to me, so after searching SO I ended up here.

It states that the article shows how to use reverse PInvoke, but it looks like the C# code has to first import the C++ Dll, before it can be used.

I need to be able to use C++ to call my C# Dll functions, without running a C# app first.

Maybe reverse PInvoke isn’t the way to do it, but I am quite inexperienced when it comes to low level stuff, so any pointers or tips on how to do this would be great.

The code in the link is

C#

using System.Runtime.InteropServices;

public class foo    
{    
    public delegate void callback(string str);

    public static void callee(string str)    
    {    
        System.Console.WriteLine("Managed: " +str);    
    }

    public static int Main()    
    {    
        caller("Hello World!", 10, new callback(foo.callee));    
        return 0;    
    }

    [DllImport("nat.dll",CallingConvention=CallingConvention.StdCall)]    
    public static extern void caller(string str, int count, callback call);    
}

C++

#include <stdio.h>    
#include <string.h>

typedef void (__stdcall *callback)(wchar_t * str);    
extern "C" __declspec(dllexport) void __stdcall caller(wchar_t * input, int count, callback call)    
{    
    for(int i = 0; i < count; i++)    
    {    
        call(input);    
    }    
}
  • 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-06-17T04:18:36+00:00Added an answer on June 17, 2026 at 4:18 am

    Meh, just spin up your own CLR host and run what you need to:

    #include <mscoree.h>
    #include <stdio.h>
    #pragma comment(lib, "mscoree.lib") 
    
    void Bootstrap()
    {
        ICLRRuntimeHost *pHost = NULL;
        HRESULT hr = CorBindToRuntimeEx(L"v4.0.30319", L"wks", 0, CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (PVOID*)&pHost);
        pHost->Start();
        printf("HRESULT:%x\n", hr);
    
        // target method MUST be static int method(string arg)
        DWORD dwRet = 0;
        hr = pHost->ExecuteInDefaultAppDomain(L"c:\\temp\\test.dll", L"Test.Hello", L"SayHello", L"Person!", &dwRet);
        printf("HRESULT:%x\n", hr);
    
        hr = pHost->Stop();
        printf("HRESULT:%x\n", hr);
    
        pHost->Release();
    }
    
    int main()
    {
        Bootstrap();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to register a JS function call from a .NET page which
On a function call from an image, I am trying to insert the alt
I'm trying to call a jquery function from a Grails .gsp page using g:link.
I'm trying to call a function in a delphi dll using JNA . the
I'm currently trying to make a set of conversion functions which, through one call,
I am currently trying to call a method in the aspx.cs inside of my
Currently trying at add ajax to a site, after much reading I discovered that
Im currently trying to downlaod a audio track from a WCF, i need some
I am currently trying to port a .Net app to Objective C and Cocoa.
I'm currently having an issue where I have a javascript object that is trying

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.