Here's my quick cut at this - I've never actually used these attributes, though they should work, and we should have a sample to this effect in the F# distribution. Luckily when the hub goes live the search engines should find this post!

You may wonder if these will be members of a class (they would be in C#, and it's probably required). In F# they will be members of the class associated with the containing F# module, so that should be enough.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
open System.Runtime.InteropServices 
open System

[<ComRegisterFunction(); ComVisible(false)>]
let RegisterFunction(t : Type) = 
  let sKey = @"\CLSID\{" + t.GUID.ToString() + @"}\Implemented Categories" in
  let regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(sKey, true) in 
  match regKey with   
  | null -> () 
  | _ -> regKey.CreateSubKey("{B56A7C42-83D4-11D2-A2E9-080009B6F22B}") |> ignore

[<ComUnregisterFunction();ComVisible(false)>]
let UnregisterFunction(t : Type) =
  let sKey = @"\CLSID\{" + t.GUID.ToString() + @"}\Implemented Categories" in 
  let regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(sKey, true) in 
  match regKey with 
  | null -> ()
  | _ -> regKey.DeleteSubKey("{B56A7C42-83D4-11D2-A2E9-080009B6F22B}")
By on 4/5/2006 6:46 PM ()

In F# they will be members of the class associated with the containing F# module, so that should be enough

Is there any way to tell the class associated with the containing F# module that it is supposed to be implementing an interface? In what I am trying to do I need the same class that contains those methods to implement an ICommand interface which comes from the library ESRI.ArcObjects.Core. So in C# I have this as the class:

1
2
3
4
5
6
public class MyClass : ICommand
 {
    private IApplication m_app;
    private bool m_enabled;
    private System.Drawing.Bitmap m_bitmap;
    private IntPtr m_hBitmap;

and the COM register functions are a part of that class. If there is a way for that outer level class to declare that it is implementing an interface then I don't have to have those COM register methods in a class inside the module but if not then I do because that is the way ESRI allows you to use .Net with ArcObjects.

By on 4/6/2006 8:41 AM ()

In this case use a class, where the Install/Uninstall commands become static members of the class.

1
2
3
4
 
type C = class
  static member Foo() = ...
end

In the compiled code this will be a class nested inside the containing class for the F# module. If you want this to be part of an F# namespace just use

namespace MyNamespace

at the top of your file instead of "module MyModule" (if you have any module declaration at all). The use of 'namespace' suffers some limitations in the current release, which is one reason why it's not in the language specification, but we're in the process of fixing that.

Thanks!

Don

Visit the F# home page at [link:research.microsoft.com].

By on 4/7/2006 5:58 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper