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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:11:12+00:00 2026-05-12T15:11:12+00:00

I have a C# dll that I need to call from unmanaged C++. The

  • 0

I have a C# dll that I need to call from unmanaged C++. The main problem that I have is that my c++ code corresponds to an excel add-in, that can be installed for excel 2003 and excel 2007, when I install my add-in in excel 2007, and I try to call my C# dll, it works just fine, but for some reason that I still haven’t been able to find, in excel 2003 it crashes, excel show me a Runtime Error message, and when debugging my c++ code I can see that the code fails when trying to create an instance of my C# dll, it says that the class is not registered even if I registered with regasm.

this is my C# code:


namespace ManagedDLL
{
    [
        Guid("3C80EE60-D9B8-4daf-89BE-6C7B748F613C"),
        InterfaceType( ComInterfaceType.InterfaceIsDual),
        ComVisible(true)
    ]
    public interface ICalculator
    {
        [DispId(1)]
        int main(string args, IntPtr _handle);
    };


    [
        Guid("5134F342-5B7F-4db2-94F0-F450610419CF"),
        ProgId("myapp.CCOMEntryPoint"),
        ClassInterface(ClassInterfaceType.None),
        ComDefaultInterface(typeof(ICalculator)),
        ComVisible(true)
    ]
    public class COMEntryPoint : ICalculator
    {
        public int main(string args, IntPtr _handle)
        {
            string[] _args = args.Split(new char[] { ':' });

            Program.handle = _handle;
            return Program.Main(_args);
        }
    }
}

and in C++ what I do is to import the .tlb file that is generated when I use regasm to register my C# dll, like this:


\#import "..\bin\release\ManagedDLL.tlb" raw_interfaces_only
using namespace ManagedDLL;
.
.
.
int callMyDll()
{
    long handle = 0, result = 0;
    BSTR args;

    HRESULT hr = CoInitialize(NULL);

    ICalculatorPtr pICalc(__uuidof(COMEntryPoint));

    pICalc->main(bstrStr, handle, &result);

    return result;
}

But as I mentioned before, this code doesn’t work for excel 2003, so my questions are:

  1. I’m I doing something wrong in the way in which I declare my C# dll that is causing me problems in excel 2003?
  2. Just as it is now, can my C# dll be considered an ActiveX object?
  3. How can I call my C# dll in another way from c++? like using IDIspatch for example

Thanks

  • 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-12T15:11:12+00:00Added an answer on May 12, 2026 at 3:11 pm

    I’ve had a similar problem before. I wasn’t calling C# from C++, but the concept is the same.

    I had to load a .NET dll into a host application via COM, which looks like what you are trying to do. The problem was the host application (in your case excel) was loading the .NET runtime 1.1. Our dll was compiled for .NET 2.0.

    It could be that Excel 2003 is loading the 1.1 runtime and 2007 loads a more recent version. Check out this forum this:
    Excel selects wrong .NET runtime.

    You could also test this by using MSBee to target the 1.1 runtime and then try load your dll in Excel 2003.

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

Sidebar

Related Questions

I have an unmanaged (C/C++) DLL which I need to call from a C#
I have a C++ dll that I need to call from C#. One of
I have some C code that compiles to a DLL. From C#, I need
I have a hird-party dll that need to be installed alongside with my app.
I have a C dll that I'm wrapping so that I can call it
I have a legacy DLL written in C that I'd like to call from
I have a Delphi DLL that I did not write, but need to call
I have a DLL that contains all my object I need to build my
I need some clarification. I have a Reportwriter dll that uses Crystal Reports. It
I have a DLL that I can use to pull the following information about

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.