Open Core Interface - MLPI
MLPI-MotionLogicProgrammingInterface(mlpi4COM)  1.26.2
Run a C# application without dll registration

Learn what you need to do to run a C# application without registration of the commlpiwin32.dll on the end users computer.

Note
Although this guide is written for the x86 platform, it is also valid for the x64 platform.

Problem description

COM projects are based on interface definitions which you include into your application as references and are located in the COM dll (commlpiwin32.dll). These references need to be resolved when running your application. One way to resolve these interfaces is by using a lookup in the registry of your Windows PC. For this to work, you have to register the COM dll on every PC you want to run your application on. Of course, this makes the process of deploying your application to other PCs more complicated. But there is another approach. By using an application manifest you can configure your application to find the interfaces in the COM dll without the need to register. The steps below show you how to do this.

Create a project

Create a C# project by following the instructions in Creating a new C# project for Windows using Visual Studio 2005.

Note
To do this, you need to register the commlpiwin32.dll on your development computer.

Creating a Manifest for your Application

There are two ways to include a manifest in your application, which are described below.

  • Embedded manifest which is compiled into your applications executable. (recommended)
  • An external manifest in a separate file which has to be located in the same folder as your applications executable.

Creating an embedded Manifest for your Application

To use an embedded manifest you need to add an 'app.manifest' file to your Visual Studio project. Do this by selecting New->Add Item... in the context menu of your project and choose an Application Manifest File. After the file has been added to your application project, you need to add the following lines to the section near the end of the file.

<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="commlpiwin32.dll" version="1.20.0.0" />
</dependentAssembly>
</dependency>
Note
You need to change the version string to the version of the commlpiwin32.dll that you want to deploy with your application.

To use your application without registration of the dll, the end user needs at least the following files (all in the same directory):

  • YourApplication.exe
  • commlpiwin32.dll Located in the MLPI-SDK at <install>\mlpi4COM\bin\win-vs2005sp1-x86.
  • commlpiwin32.dll.manifest Located in the MLPI-SDK at <install>\mlpi4COM\bin\win-vs2005sp1-x86.
  • (Interop.commlpiLib.dll) Only for older Visual Studio Versions without the property Embed Interop Types.

The application should now be able to run without registration of the commlpiwin32.dll. To prove this, unregister the commlpiwin32.dll and run your application outside of Visual Studio. It should still work.

Creating an external Manifest for your Application

Another approach is to use an external manifest file. You can write the manifest by hand or use the dedicated tool included in the SDK, which is called 'ManifestMaker'. Execute the ManifestMaker ('<install>\mlpi4COM\bin\ManifestMaker.exe'). The following image shows the ManifestMaker's main window.

ManifestMakerGUI.png

First Step:
Select the commlpiwin32.dll.manifest file by clicking the 'Select dll-manifest' button. If the Manifest Maker is still in the default folder (<install>\mlpi4COM\bin), you just have to change the directory to <install>\mlpi4COM\bin\win-vs2005sp1-x86 and select the commlpiwin32.dll.manifest.

Second Step:
Select your application's 'exe' file ('YourApplication.exe') by clicking the 'Select Application' button.

Final Step:
Create a manifest for your application by clicking the 'Make Manifest' button.

After this, the main window should report 'Manifest created'. Your application's execution folder should now contain a file named 'YourApplication.exe.manifest' and the 'commlpiwin32.dll.manifest'.

Note
When using this approach with an external manifest, then you need to disable the embedded manifest in your project settings of Visual Studio. This is, because newer versions of Windows seem to ignore an external application manifest if it finds a manifest embedded inside the .exe as a resource. When creating a new Visual Studio project it will embed a manifest with default settings, so your need to disable it by entering the project settings and selecting 'Create application without a manifest' in the 'Application' tab.
vsDisableManifest.png
The content of the manifest file does get cached by windows on the first run of your application. This means, that changes on the manifest file might not have an immediate effect on subsequent runs of your application. Keep this is mind, when changing the manifest file during development, as this might result in unexpected behaviour. This is, why it is recommended for most use cases to embed your manifest inte the application as described above. For more details please read: http://csi-windows.com/blog/all/27-csi-news-general/245-find-out-why-your-external-manifest-is-being-ignored
If you are using Visual Basic (which does not allow to disable the embedded manifest), you have to use the approach with the embedded manifest in your project settings as described above. See Creating an embedded Manifest for your Application.

To use your application without registration of the dll, the end user needs at least the following files (all in the same directory):

  • YourApplication.exe
  • YourApplication.exe.manifest Generated by ManifestMaker
  • commlpiwin32.dll Located in the MLPI-SDK at <install>\mlpi4COM\bin\win-vs2005sp1-x86.
  • commlpiwin32.dll.manifest Located in the MLPI-SDK at <install>\mlpi4COM\bin\win-vs2005sp1-x86.
  • (Interop.commlpiLib.dll) Only for older Visual Studio Versions without the property Embed Interop Types.

The application should now be able to run without registration of the 'commlpiwin32.dll'. To prove this, unregister the 'commlpiwin32.dll' and run your application outside of Visual Studio. It should still work.