views:

135

answers:

2

I try to call skype instance by COM on F#.
A aim is get mood message.

test.fs

// Import skype4com Api
open SKYPE4COMLib

type SKYPE4COM =
    new() = new SKYPE4COM()

let GetMood =
    let aSkype = new SKYPE4COM
    mood <- aSkype.CurrentUserProfile.MoodText
    mood

But when build(before too),error occur.

Incomplete structured construct at or before this point in expression

Thanks in advance.

this is next version what I think.

test01.fs

// Import skype4com Api
open SKYPE4COMLib

let GetMood =
    let aSkype = new SKYPE4COMLib()              // line 1
    mood <- aSkype.CurrentUserProfile.MoodText   // line 2
    mood                                         // line 3

error message(when building).
line in 1:error FS0039: The type 'SKYPE4COMLib' is not defined
line in 2:error FS0039: The value or constructor 'mood' is not defined
line in 3:error FS0039: The value or constructor 'mood' is not defined

also like that...

+2  A: 

Your code has several issues. First of all, your constructor for the SKYPE4COM class appears to be recursive (?!), which is going to cause a stack overflow if you try to create an instance. Secondly, the error that you're receiving is because you are using the new operator, but you haven't completed the call to the constructor (i.e. you need to apply the constructor using parentheses: let aSkype = new SKYPE4COM()). Even then, though, you've got another issue because your type doesn't expose a CurrentUserProfile property, so your code still won't work.

Try something like this:

open SKYPE4COMLib

let getMood() =
  SkypeClass().CurrentUserProfile.MoodText
kvb
thanks advice. But still I wonder that why need to expose CurrentUserProfile property. Because I think for example open System.Windows.Forms then let frm = new Form();frm.Text <- "foo". That works,even no define type and property... (at entry I did not add open SKYPE4COMLib) by the way I don't make that instance in recursive.
tknv
thank you very much. let getMood = SkypeClass().CurrentUserProfile.MoodText. then completely works as I want. appreciate!
tknv
+1  A: 

Consider using a Type Extension to add a member to an already existing type:

open SKYPE4COMLib

type SKYPE4COMLib with
    member this.GetMood() =
        aSkype.CurrentUserProfile.MoodText

This would allow you to access GetMood as if it were a member function defined on the SKYPE4COMLib type:

let x = new SKYPE4COMLib()
printfn "%A" (x.GetMood())
Ray Vernagus
thank you very much.But I used kvb solution in my case.
tknv