com_module_sample
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
com_module_sample [2018/01/22 12:42] – created wolfgangriedmann | com_module_sample [2022/10/11 12:02] (current) – wolfgangriedmann | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Create a COM module for a VO application ====== | + | ====== Create a COM module for a VO application |
* Create a prg file for the interface\\ | * Create a prg file for the interface\\ | ||
- | < | + | < |
using System.Runtime.InteropServices | using System.Runtime.InteropServices | ||
Line 20: | Line 20: | ||
The GUID needs to be created with the GuidGen.exe tool.\\ | The GUID needs to be created with the GuidGen.exe tool.\\ | ||
* Create a prg file for the functionality itself:\\ | * Create a prg file for the functionality itself:\\ | ||
- | < | + | < |
begin namespace COMTest | begin namespace COMTest | ||
Line 46: | Line 46: | ||
* build your application\\ | * build your application\\ | ||
* read the public key from the application: | * read the public key from the application: | ||
- | * create the TLB with administrative | + | * create the TLB with administrative (elevated) rights: |
- | * remove the registration again from the registry | + | |
* create the automation server in VO using the created TLB | * 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. |
+ | <code visualfoxpro> | ||
+ | |||
+ | self: | ||
+ | self:cClsID := " | ||
+ | self:cIID := " | ||
+ | SUPER: | ||
+ | SELF: | ||
+ | SELF: | ||
+ | |||
+ | RETURN SELF</ | ||
+ | * create the manifest for your COM assembly: mt.exe -managedassemblyname: | ||
+ | * fix this manifest by removing processorarchitecture " | ||
+ | * move this manifest in the resources subfolder of your application directory (XIDE) | ||
+ | * create there a file " | ||
+ | < | ||
+ | #define CREATEPROCESS_MANIFEST_RESOURCE_ID 1 | ||
+ | CREATEPROCESS_MANIFEST_RESOURCE_ID RC_RT_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: | ||
+ | <code xml> | ||
+ | < | ||
+ | < | ||
+ | type=" | ||
+ | name=" | ||
+ | version=" | ||
+ | publicKeyToken=" | ||
+ | > | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | 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 Parse -logfile: | ||
+ | notepad sxstrace.txt</ | ||
+ | * to display the manifest in an application you can use this manifest viewer: [[https:// | ||
+ | * 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|RT_MANIFEST constant]] | ||
com_module_sample.1516624954.txt.gz · Last modified: 2018/01/22 12:42 by wolfgangriedmann