开发者

How can call instance by COM?

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

l开发者_运维百科et 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...


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


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())
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜