Author Topic: Making a Phone Call in VB.NET  (Read 1023 times)

thiruvasagamani

  • Old Members
  • Hero Member
  • *
  • Posts: 6887
    • View Profile
Making a Phone Call in VB.NET
« on: May 23, 2009, 07:40:05 pm »
Making a Phone Call in VB.NET

Our code for MakeCall in VB.NET ports with few major modifications from the C# code detailed above. We use IntPtr variables to hold value for most of our functionality. One difference is that in the forward declaration of MakeCall, we specify that the PhoneMakeCallInfo structure instance will be passed in as a reference.
Copy Code

Code: [Select]
    <System.Runtime.InteropServices.DllImport("phone.dll")> _
    Private Shared Function PhoneMakeCall(ByRef ppmci As
      PhoneMakeCallInfo) As IntPtr
    End Function

We process the PhoneMakeCallInfo structure almost identically to as before. We break the PhoneNumber string into a character array then write to memory using iPhoneNumber as a memory alignment pointer.
Copy Code

Code: [Select]
PhoneNumber.Insert(PhoneNumber.Length, " ")
Dim cPhoneNumber() As Char = PhoneNumber.ToCharArray()
Dim pAddr() As Char = cPhoneNumber

Dim info As PhoneMakeCallInfo = New PhoneMakeCallInfo
info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info)
Dim iPhoneNumber As IntPtr = Marshal.AllocHLocal(cPhoneNumber.Length)
        System.Runtime.InteropServices.Marshal.Copy(cPhoneNumber, 0,
          iPhoneNumber, cPhoneNumber.Length)
info.pszDestAddress = iPhoneNumber

After we point the pszDestAddress member to this memory space and set the confirm before dial option, we pass the structure instance into PhoneMakeCall.
Copy Code

Code: [Select]
If PromptBeforeCall Then
   info.dwFlags = PMCF_PROMPTBEFORECALLING
Else
   info.dwFlags = PMCF_DEFAULT
End If
   res = PhoneMakeCall(info)

Source : MSDN
Thiruvasakamani Karnan


Tags: