Hello, i can't see your attachment. Server says "Error 404", so is you able to rename it?
Can you show what says .net disasm for your dll?

By on 3/1/2009 8:26 AM ()

Hi,

sorry for that this was my fault using a '#' in the file name. I changed the name in the original post to FSharp_and_COM.gif and post the code I used.
I attach to this reply a screenshot of the ildasm of the used DLL.

By on 3/1/2009 10:19 PM ()

Hello,

CreateScriptObject() method returns "object" type, so you must cast it to needed interface.

By on 3/1/2009 11:08 PM ()

So in this case you want

1
let s = l.GetStriptObject() :?> Foo

where "Foo" is the name of the type or interface that has the "AxisSystem" method on it.

By on 3/2/2009 7:26 AM ()

Hi,

I thought this was the right way particularly I read about the

downcast operator in the Expert F# book on page 115. So I tried this this morning

1
let s = l.GetScriptObject() :?> LUCIDSTUDIOLib.LucidShapeClass

and get following result in fsi

1
2
3
4
5
6
7
8
9
10
11
System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to class 
type 'LUCIDSTUDIOLib.LucidShapeClass'. COM components that enter the CLR and do not support 
IProvideClassInfo or that do not have any interop assembly registered will be wrapped in the 
__ComObject type. Instances of this type cannot be cast to any other class; however they can
be cast to interfaces as long as the underlying COM component supports QueryInterface calls 
for the IID of the interface.
   at <StartupCode$FSI_0013>.$FSI_0013._main() in 
C:\Daten\olbrich\Visual Studio 2008\Projects\ConsoleApplication1\ConsoleApplication1\Program.fs:line 9
stopped due to error

val s : LUCIDSTUDIOLib.LucidShapeClass

So, I am loss what to do next ...

By on 3/3/2009 12:29 AM ()

You might need to use Type Library Importer

TlbImp yourcom.dll /verbose /out:Interop.yourcom.dll

You can find this tool in the .NET SDK

After that you can use the generated dll as a reference and do the same with the interop dll

By on 3/3/2009 2:51 PM ()

Hello ssp,

could you please give me an example of the correct cast. I am a complete newbie in F#.
Thanks a lot in advance.

By on 3/1/2009 11:56 PM ()

Hello,
you can use ":?>" or ":>" operators.
Here is snippet from my code:

1
2
3
4
5
let vId = app.NewObject("...", "...", id, 0, rc, rse)
let vIdType = vId.GetType ()
do printf "created object %A type: %A r:%A rc: %A res: %A\n" id vIdType vId rc rse
let vIdCode = vId :?> Int32
let co = app.AddToCheckOut (vIdCode, false, rc, rse)
By on 3/2/2009 4:21 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