To answer your last question, interop via F# is quite similar to interop via other .NET languages. If you're importing COM interfaces, you can use exactly the same attributes you would use in C#.

1
2
3
4
[<ComImport; Guid(...); InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>]
type MyComInterface =
  abstract MyMethod : string -> unit
  ...

If you want to do PInvoke, you use "external functions", which unfortunately don't appear to be well documented anywhere. However, the basic idea is that you define external functions within a module using syntax like C/C++ (see [link:msdn.microsoft.com] for slightly more info, along with an example).
By on 9/13/2010 2:30 PM ()
Thanks! While I knew about decorating with COM types, I had forgotten about PInvoke. Even so, looks like a hard row to hoe. Does anybody know if there are any good books/resources on low-level F# integration like this? Things like writing a shell extension, or using a third-party dll. I used to do a bit of this in C++, but the data structure translation alone sounds painful, not to mention all the GUID management.

Thanks again for the quick answer.
By on 9/13/2010 4:46 PM ()
UPDATE: I got my problem fixed.

The "real" problem was that F# is by default MTA threaded and the C# control was STA. I think this is because of the way the webkit.dll is coded but I don't have time to dive down further. It could just be the way the C# wrapper was done.

The error -- can't load library or can't cast x to y -- looked like a COM error, since it was the COM libraries that were being called by the wrapper.

Adding a STAThread attribute to the main loop fixed the problem. Although since I'm writing a highly-threaded app, it probably caused all sorts of other problems, but for now the error is gone and the control is working correctly

The issue here is somewhat related to this thread: [link:cs.hubfs.net]
By on 9/14/2010 8:22 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us
Built with WebSharper