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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:41:23+00:00 2026-05-10T14:41:23+00:00

I have a Windows C# program that uses a C++ dll for data i/o.

  • 0

I have a Windows C# program that uses a C++ dll for data i/o. My goal is to deploy the application as a single EXE.

What are the steps to create such an executable?

  • 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. 2026-05-10T14:41:24+00:00Added an answer on May 10, 2026 at 2:41 pm

    Single Assembly Deployment of Managed and Unmanaged Code Sunday, February 4, 2007

    .NET developers love XCOPY deployment. And they love single assembly components. At least I always feel kinda uneasy, if I have to use some component and need remember a list of files to also include with the main assembly of that component. So when I recently had to develop a managed code component and had to augment it with some unmanaged code from a C DLL (thx to Marcus Heege for helping me with this!), I thought about how to make it easier to deploy the two DLLs. If this were just two assemblies I could have used ILmerge to pack them up in just one file. But this doesn´t work for mixed code components with managed as well as unmanaged DLLs.

    So here´s what I came up with for a solution:

    I include whatever DLLs I want to deploy with my component´s main assembly as embedded resources. Then I set up a class constructor to extract those DLLs like below. The class ctor is called just once within each AppDomain so it´s a neglible overhead, I think.

    namespace MyLib {     public class MyClass     {         static MyClass()         {             ResourceExtractor.ExtractResourceToFile('MyLib.ManagedService.dll', 'managedservice.dll');             ResourceExtractor.ExtractResourceToFile('MyLib.UnmanagedService.dll', 'unmanagedservice.dll');         }          ... 

    In this example I included two DLLs as resources, one being an unmanaged code DLL, and one being a managed code DLL (just for demonstration purposes), to show, how this technique works for both kinds of code.

    The code to extract the DLLs into files of their own is simple:

    public static class ResourceExtractor {     public static void ExtractResourceToFile(string resourceName, string filename)     {         if (!System.IO.File.Exists(filename))             using (System.IO.Stream s = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))                 using (System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Create))                 {                     byte[] b = new byte[s.Length];                     s.Read(b, 0, b.Length);                     fs.Write(b, 0, b.Length);                 }     } } 

    Working with a managed code assembly like this is the same as usual – almost. You reference it (here: ManagedService.dll) in your component´s main project (here: MyLib), but set the Copy Local property to false. Additionally you link in the assembly as an Existing Item and set the Build Action to Embedded Resource.

    For the unmanaged code (here: UnmanagedService.dll) you just link in the DLL as an Existing Item and set the Build Action to Embedded Resource. To access its functions use the DllImport attribute as usual, e.g.

    [DllImport('unmanagedservice.dll')] public extern static int Add(int a, int b); 

    That´s it! As soon as you create the first instance of the class with the static ctor the embedded DLLs get extracted into files of their own and are ready to use as if you deployed them as separate files. As long as you have write permissions for the execution directory this should work fine for you. At least for prototypical code I think this way of single assembly deployment is quite convenient.

    Enjoy!

    http://weblogs.asp.net/ralfw/archive/2007/02/04/single-assembly-deployment-of-managed-and-unmanaged-code.aspx

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

Sidebar

Related Questions

I have a Windows C++ program that is doing something like: FILE* pf =
I have a program that creates a Windows user account using the NetUserAdd() API
I have a program that I need to run under *nix and windows. because
I have a cross platform program that runs on Windows, Linux and Macintosh. My
I have a network C++ program in Windows that I'd like to test for
I have an executable that is started by a windows service, this program will
I want to create a C# program to provision Windows Mobile devices. I have
I have a program which needs installing on windows 64 boxes. Most of the
I have a Windows Service written in Delphi which runs a number of programs.

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.