Skip to main content

Testing COM components


Here's some code you can use to try to load your Type through COM.
You can use the GetPEKind method to get the platform that the assembly was compiled for.

(Recently ran into a problem where I couldn't be sure the assembly I'd registered was registered correctly, my query was particular to win64, there are some changes in the registry entries for 64bit windows when running 32 bit applications.)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Reflection;

namespace ComTest
{

class MyGetTypeFromCLSIDSample
{
public static void Main()
{
try
{
Guid myGuid1 = new Guid("3A21CE6B-8571-4955-9780-BAE1EE3215C0");//my Types GUID, regasm was ran on this assembly.

// Get the type associated with the CLSID
// and specify whether to throw an exception if an error occurs
// while loading the type.

//if this shows The type of the GUID is System.__ComObject.
//The current module is mscorlib.dll.
//assembly kind ILOnly, PE32Plus , platform AMD64
//then your assembly isn't registered.


Type myType1 = Type.GetTypeFromCLSID(myGuid1, true);
Console.WriteLine("The GUID associated with myType1 is {0}.", myType1.GUID);
Console.WriteLine("The type of the GUID is {0}.", myType1.ToString());

// Show the current module.
Module m = myType1.Module;
Console.WriteLine("The current module is {0}.", m.Name);

PortableExecutableKinds peKind;
ImageFileMachine machine;
m.GetPEKind(out peKind, out machine);

Console.WriteLine("assembly kind {0} , platform {1}", peKind.ToString(), machine);//assembly kind ILOnly , platform I386

Console.ReadLine();
}
catch
{
Console.WriteLine();
}
}
}

Comments

Popular posts from this blog

BootStrapper BootStrapping

Bootstrapping is the creation of a wrapper installer around already existing installars or files. It's useful if you have multiple installation files that you'll like the user to install in on step. The Bootstrapper itself is a .exe installer file, it also may have .SED file which contains details of the contents of the .exe. There are a few applications out there to generate a bootstrapper, the most simple I've seen is the an app called IEXpress . IExpress Is actually installed on windows (System32/iexpress.exe). This creates an installer, you tell it what files you wish it to include in the installation. I've only played with this so far and it appears to me that the isntaller can only install upto 2 setup.exes. You can include as many files as you like, but the files cannot have the same name, because of this you will probably need to rename your setup.exes to something else because you cannot have 2 files with the same name. After you've included all the files...

Installer CustomAction, Debugging the CustomAction, InstallState

Custom Action The Custom Action is added to the Setup Project, select the Project node and hit the Custom Action button. This allows you add an Action to a particular phase in the Installation. But first you must create the Custom Action. To Add a Custom Action you must first have a Custom Action created, this is usually in the form of a Installer Class, this should be created in a seperate project, the Installer Class is actually one of the File Templates in the C# Projects. So it's File->New Project and select Visual C# Projects. Then add a Class Library, this will prompt you for the Class Library Types , select "Installer Class". Walkthrough - Creating Custom Action (msdn). Also here's a more comprehensive document on Setup/Installer implementations, it delves into the Registry etc Getting Started with Setup Projects (SimpleTalk). Visual Studio Setup Projects and Custom Actions (Simple Talk). Create your Installer Class and then add it as a Custom Action to the ...

dotNET - Use app.config ApplicationSettings and UserSettings

When using Settings in an Assembly or .exe you can use the Settings Designer to generate a config file using Settings. The Settings Designer provides a wrapper class which allows you to provide defaults and access the config data using Properties. But what if you're not working inside that Assembly or .exe? this presents a problem. If your loading the Assembly externally and want to access that Assembly's .config file you'll probably wish to use something in the System.Configuration namespace... unfortunately it's not of much use if you've created the .config file from the Settings Designer in Visual Studio!! This is because the Designer creates Sections and ApplicationSettings and UserSettings, the System.Configuration namespace does not provide a method to access these (it has a method to access AppSettings which are a different thing. Below I've written a workaround which locates the app.config and accesses the ApplicationSettings and UserSettings using XML i...