hubFS: THE place for F#

. . . are you on The Hub?
Welcome to hubFS: THE place for F# Sign in | Join | Help
in Search

unboxing obj provided from COM

Last post 08-05-2008, 19:10 by leonidr. 2 replies.
Sort Posts: Previous Next
  •  08-05-2008, 11:35 6518

    unboxing obj provided from COM

    Hello F# users!

    Following the automation examples in the F# source, i created a wrapper for the Bloomberg COM interface (tlbimp.exe). I managed to figure out how to call the appropriate function call but i am having a hard time figuring out how to extract the data into a suitable generic structure for manipulation. Here is a simple example:

    > #r "BLP_DATA_CTRLLib.dll";;                                                                                                                                            

    --> Referenced 'm:\research\fs_src\bi\BLP_DATA_CTRLLib.dll'

    > open BLP_DATA_CTRLLib ;;                                                                                                                                               

    > let blp = new BlpDataClass() ;;                                                                                                                                        

    val blp : BlpDataClass

    Binding session to 'm:\research\fs_src\bi\BLP_DATA_CTRLLib.dll'...

    > blp.BLPSubscribe ;;                                                                                                                                                    

    val it : ('a * 'b -> obj) = <fun:it@4>

    > let p = blp.BLPSubscribe("IBM US Equity", "PX_LAST") ;;                                                                                                                

    val p : obj

    >p;;                                                                                                                                                                   

    val it : obj = [|[|127.98|]|]

    > let price : float array array = (unbox p) ;;                                                                                                                           

    val price : float array array

    System.InvalidCastException: Unable to cast object of type 'System.Object[,]' to type 'System.Double[][]'.

       at <StartupCode$FSI_0007>.$FSI_0007._main()

    stopped due to error

    i have tried various forms of unbox, but none seems to do the trick. What am i missing?
    thanks for your help.

  •  08-05-2008, 12:23 6519 in reply to 6518

    Re: unboxing obj provided from COM

    Based on the error message, I think you have an object with type similar to 'o' below.

    So code after that may suggest solution.

    [code]

    #light

    let objArr = Array2.create 1 1 (new obj())

    objArr.[0,0] <- (12.34 :> obj)

    let o = objArr :> obj

    printfn "%A" o

    let oa : obj[,] = unbox o

    let f : float = unbox (oa.[0,0])

    printfn "%f" f

    [/code]

  •  08-05-2008, 19:10 6525 in reply to 6519

    Re: unboxing obj provided from COM

    ok, great! that method works. careful analysis of the types is useful...
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems