User Tools

Site Tools


com_module_sample

Create a COM module for a VO application using XIDE

  • Create a prg file for the interface
begin namespace COMTest
 
using System.Runtime.InteropServices
 
[ComVisible(true)];
[Guid("750E557E-9DA6-4508-A36E-C4141D27B5D4")];
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)];
interface ICOMTester
 
[DispId(1)];
method Output() as string
 
end interface          
 
end namespace

The GUID needs to be created with the GuidGen.exe tool.

  • Create a prg file for the functionality itself:
using System.Runtime.InteropServices
 
begin namespace COMTest
 
[ComVisible(true)];
[Guid("7D1DF22E-3A3D-431C-8BEE-A2F40C53A249")];
[ClassInterface(ClassInterfaceType.None)];
[ProgId("COMTest.COMTester")];
class COMTester implements ICOMTester
 
public constructor()
 
	return
 
public virtual method Output() as string
 
	return "Hi from my component"
 
end class	
 
end namespace
  • Build the application (i.e. the DLL)
  • create a snk file: sn - k COMTest.snk
  • add this snk file as signature to your DLL (Application Properties - Advanced - Assembly signing in XIDE)
  • build your application
  • read the public key from the application: sn -T COMTest.dll (upper case “T”) and write it somewhere
  • create the TLB with administrative (elevated) rights: tlbexp COMTest.dll
  • create the automation server in VO using the created TLB
  • edit the Init() method of the created VO class adding the cProgId and the cClsId using the GUIDs from your library. The cClsId uses the GUID from your class, the cIID the one from your interface.
METHOD Init(ObjID, fROTCHECK) CLASS ICOMTester
 
self:cProgID := "COMTest.COMTester"
self:cClsID := "{7D1DF22E-3A3D-431C-8BEE-A2F40C53A249}" 
self:cIID := "{750E557E-9DA6-4508-A36E-C4141D27B5D4}"
SUPER:Init(ObjID, 0, .T., fRotCheck)
SELF:_dwFuncs := 1
SELF:_dwVars := 0
 
RETURN SELF
  • create the manifest for your COM assembly: mt.exe -managedassemblyname:COMTest.dll -nodependency -out:COMTest.dll.manifest
  • fix this manifest by removing processorarchitecture “msil” and adding Type=“win32” in the assemblyIdentity section (and maybe beautify the file…)
  • move this manifest in the resources subfolder of your application directory (XIDE)
  • create there a file “Manifest.CREATEPROCESS_MANIFEST_RESOURCE_ID.rc” with the content
CREATEPROCESS_MANIFEST_RESOURCE_ID RC_RT_MANIFEST "COMTest.dll.manifest"
  • add this file to XIDE with Add Existing - Add Native Resources
  • build your DLL and check with a manifest viewer if your binary contains that manifest
  • hopefully your VO application has a manifest. Add a reference to your COM dll:
  <dependency>
  	<dependentAssembly>
  		<assemblyIdentity
  			type="win32"
  			name="COMTest"
  			version="1.0.0.0"
  			publicKeyToken="ff428fdf619029ef"
  			>
  		</assemblyIdentity>
  	</dependentAssembly>
  </dependency>

using the public key token you created with “sn -T”. Pleasy pay attention that the version information must be exactly the same between your manifests and the COM DLL! And to be sure that an export of your application takes care of the .snk file and the manifest file, you should add them to your project.

Possible problems:

  • you can encounter error 0x80131044 when trying to create the TLB from a already strong named DLL if the dependencies of your COM dll are not strong named. The only solution is to strong sign the dependencies. This should be possible even without the sources
  • you should set the namespace also in the project properties
  • the exported class cannot have the same name as the COM DLL itself
  • to debug your SideBySide issues in your VO application (that may not start after changing the manifest):
sxstrace Trace -logfile:systrace.out
sxstrace Parse -logfile:systrace.out -outfile:sxstrace.txt
notepad sxstrace.txt
  • to display the manifest in an application you can use this manifest viewer: weblogs.asp.net/kennykerr/manifest-view-1-0
  • Using the DispId attribute in the interface for every method makes sure that every version of your COM dll has the same DispId in the COM interface and you don't need to recreate the TLB file and the automation server in VO after every change. In fact, most of the time you should be able to adjust the automation server in VO manually if you change the interface of the COM library
  • in many cases, the definition of the RT_MANIFEST constant in VO inhibits the correct loading of the COM assembly. In these cases, simply add the definition of the constant in your own program. Please see here: RT_MANIFEST constant
com_module_sample.txt · Last modified: 2018/09/04 05:52 by wolfgangriedmann