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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:52:18+00:00 2026-05-27T22:52:18+00:00

I have an unmanaged DLL which I’m currently calling from C# using a COM

  • 0

I have an unmanaged DLL which I’m currently calling from C# using a COM Class Wrapper.

[ComImport(), Guid("75E81043-CAD5-11D3-800D-00105A5E2FA0")]
public class MyObject { }

[ComImport(), Guid("75E81042-CAD5-11D3-800D-00105A5E2FA0"),
 InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface MyInterface
{
    string EncryptString([In, MarshalAs(UnmanagedType.BStr)] string bstrOrginal);    
}

Then to call:

MyInterface obj = (MyInterface)new MyObject();
string crypt = obj.EncryptString("something");

This works, the return value is as I expect. However, it requires that the dll is registered with regsvr32.

I’m looking for a way to do this without the requirement of needing to regsvr32. Preferably, by just having a copy of the dll available. It is worth noting, I have the source for the unmanaged dll, and the ability to modify it if necessary.

A shove in the right direction would be greatly appreciated.

  • 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-27T22:52:19+00:00Added an answer on May 27, 2026 at 10:52 pm

    I have wanted to do the same thing myself. As Jim mentions it is possible to get the address of DllRegisterServer and call it, but that still modifies your registry with the various entries. If you don’t want to do this (for example, you might not have the necessary privileges to write to the Registry), then there is another way.

    Any DLL that houses one or more in-process COM objects must expose the DllGetClassObject function. This function is used to acquire an instance of the COM class factory that is used to create a COM object. What you need to do is:

    1. Load the library (DLL) that houses the desired COM object
    2. Locate the DllGetClassObject function
    3. Call DllGetClassObject, passing it the CLSID of the desired COM object, this will return an IClassFactory instance.
    4. Call the CreateInstance method on the class factory to get an instance of the COM object.
    5. Cast the returned object to the interface you wish to use.

    Note that there be dragons with this approach — it is fairly low level. If you get anything wrong you will experience access violation exceptions or worse. (For instance, your interface declaration has to exactly match the COM interface).

    I have included some sample code at gist which you might like to use if you want to go this way.

    Using this code would look something like this:

    // Load the library. You dispose this after you are finished with
    // all of your COM objects. 
    var library = new LibraryModule();
    library.Load("mylibrary.dll"); or whatever your dll is called
    
    var clsid = new Guid("75E81043-CAD5-11D3-800D-00105A5E2FA0");
    
    var myObject = (MyInterface)ComHelper.CreateInstance(library, clsid);
    

    Just note that if you dispose of the LibraryModule object, then this will unload the DLL. Depending on your needs, you might just assign the value to a static field so that it exists for the lifetime of the program.

    • 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++ DLL which merely exports a single class (not COM...it's
I have an unmanaged (C/C++) DLL which I need to call from a C#
I have a situation in which a managed DLL calls some unmanaged DLL. I
I have an unmanaged dll with a class MyClass in it. Now is there
Here's my problem: I have an unmanaged dll that I made.I'm calling one of
I have a very simple DLL written in unmanaged C++ that I access from
I have an unmanaged COM object, and I would like to call it from
I have a project in C#, which references unmanaged third-party DLL (which is ChilkatDotNet2.dll
I have a DLL which contains unmanaged classes with methods. I'm trying to call
I have a vb.net dll which I imported in an unmanaged c++ project. I

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.