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 1108129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:02:04+00:00 2026-05-17T02:02:04+00:00

I have been tasked with maintaining a legacy unmanaged c++ system. I do not

  • 0

I have been tasked with maintaining a legacy unmanaged c++ system. I do not have access to the source of the entire system but I do have the source to a number of extension dlls that, when included in the same directory as the core system, will be loaded instead of the built in defaults.

I have used the extensions in the past for small changes without problems. My issue now, however, is that I’m being asked to overhaul one of the extension dlls with a substantial amount of extra functionality. Creating this extra functionality in C# is going to be significantly faster (time-to-develop) and more maintainable (our team is primarily composed of C# devs).

The extension dll only has two functions that get called by the core system. The two functions take a bool, int, uint, RECT, Point, CString and return void. Some of the parameters they accept are const.

I’m really keen to find a solid way to bridge these extension functions to C# (.NET 4). So far I’ve put considerable effort into researching COM Visible, Regasm, c++ mixed mode and interop wrapping libraries. I’ve also lost a considerable amount of time on proof of concept projects during this research and so far I do not have a working ‘bridge’.

What is the most pain free method to get this up and running?


I’m under considerably more pressure on this project than normal – I’m literally starting the C# now and assuming I will get this working somehow.

Really appreciate help and feedback.


Here is the .h and .def files:

modeldll.h

    #ifndef INC_MODELDLL_H
    #define INC_MODELDLL_H

    #ifdef MODELDLL_EXPORTS
    #define MODELDLL_API __declspec(dllexport)
    #else
    #define MODELDLL_API __declspec(dllimport)
    #endif

    typedef int (*model_updatemodel_t)(const bool update_model, const HWND hwnd, const RECT rect, const POINT next_point, const CString title);
    MODELDLL_API int UpdateModel(const bool update_model, const HWND hwnd, const RECT rect, const POINT next_point, const CString title);

    typedef int (*model_updatemodelpoint_t)(const bool update_model, const HWND hwnd, const RECT rect, UINT update, const POINT next_point);
    MODELDLL_API int UpdateModelPoint(const bool update_model, const HWND hwnd, const RECT rect, UINT update, const POINT next_point);

    typedef void (*model_process_message_t)(const char *message, const void *param);
    MODELDLL_API void ProcessMessage(const char *message, const void *param);

    #endif // INC_MODELDLL_H

modeldll.def:

    LIBRARY model.dll
    EXPORTS
    ProcessMessage    @1
    UpdateModel       @2
    UpdateModelPoint  @3
  • 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-17T02:02:05+00:00Added an answer on May 17, 2026 at 2:02 am

    I’ve investigated this topic couple of years ago: I want to use log4net and Npgsql libraries from native code that compiles even withour /clr key.

    The main idea behind this technique described by Paul DiLascia in his two remarkable articles:

    Managed Code in Visual Studio 2005
    Use Our ManWrap Library to Get the Best of .NET in Native C++ Code

    For example, here some code snippets that uses log4net library from native code (this code resides in simple non-managed dll, but you should compile this with /clr, but it’s not nessary to compile with /clr key code that would use this dll from native code):

    // Log4NetWrapper.h
    
    #pragma once
    
    using namespace System;
    //facade for log4net library (you may create something like this too)
    ref class Log4NetWrapper
    {
    public:
        //I intentionally remove additional methods, because
        //I'm trying to show the main principle
        static void ReportDebugMessage(char* msg);
    private:
        static property log4net::ILog^ Logger
        {
            log4net::ILog^ get();
        }
        static Object^ syncObject_ = gcnew Object();
        static String^ loggerName_ = "";
    };
    
    //C-interface that could be accessed from native code
    extern "C" 
    {
        _declspec(dllexport) void ReportDebugMessage(char* msg) 
        {
            Log4NetWrapper::ReportDebugMessage(msg);
        }
    
    }
    
    // This is the main DLL file.
    
    #include "stdafx.h"
    
    #include "Log4NetWrapper.h"
    
    void Log4NetWrapper::ReportDebugMessage(char* msg) 
    {
        String^ data = gcnew String(msg);
        Logger->Debug(data);
    }
    log4net::ILog^ Log4NetWrapper::Logger::get()
    {
        if ( loggerName_ == nullptr )
            return log4net::LogManager::GetLogger("");
        return log4net::LogManager::GetLogger(loggerName_);
    }
    

    Compile this code as native dll, than add this dll to your native project, add something like this to that project:

    #pragma once
    
    #pragma comment(lib, "Log4NetWrapper")
    
    extern "C"
    {
        _declspec(dllimport) void ReportDebugMessage(char* msg); 
    }
    

    And use ReportDebugMessage to access managed code from native code.

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

Sidebar

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.