0

Hi I want to make an app that uses the camera's LED constantly. I have seen a few examples that do this but I cannot get them to work as I need them in VB. I am open to C# code that I will convert myself. Also I know you need the windows.phone.media.extended.dll assembly. I have managed to dump the emulater image but I am not sure if the assembly will work. How can I use reflection instead?


How can I convert the following codes to vb?

private void VideoCamera_Initialized(object sender, object eventArgs)
{
    if (Initialized != null)
    {
        Initialized.Invoke(this, new EventArgs());
    }
}

public bool LampEnabled
{
    get { return (bool)_videoCameraLampEnabledPropertyInfo.GetGetMethod().Invoke(_videoCamera, new object[0]); }
    set { _videoCameraLampEnabledPropertyInfo.GetSetMethod().Invoke(_videoCamera, new object[] { value }); }
}
MAXE
  • 4,978
  • 2
  • 45
  • 61
M9A
  • 3,168
  • 14
  • 51
  • 79
  • Its part of a learning project – M9A Mar 18 '12 at 00:24
  • Ok, have you seen that post? What's wrong with the samples that you have already found? – Shawn Kendrot Mar 18 '12 at 00:28
  • 1
    Well I downloaded the source code from this tutorial - http://www.locked.nl/wp7-flashlight-getting-started - and I tried writing it in VB but there were some errors orginally, but now its error free but it doesnt work. Its obvious something went wrong when trying to convert. Which I why I am looking for something tailored towards vb – M9A Mar 18 '12 at 00:32
  • This sample seems a little simpler http://www.daveamenta.com/2011-01/led-flashlight-for-windows-phone-7/, and you can convert to vb on a site like this: http://www.developerfusion.com/tools/convert/csharp-to-vb/ – Shawn Kendrot Mar 18 '12 at 00:51
  • Im having errors related to the microsoft.phone.media.extended reference even though I have the reference (dumped from emulator) – M9A Mar 18 '12 at 09:45
  • Did you look at that forum post? in it the guy has problems loading the assembly – Shawn Kendrot Mar 18 '12 at 15:25
  • Im using another code, How would I convert this line? (See below answer) – M9A Mar 18 '12 at 20:43
  • Why are you so obsessed about converting the code to VB? – tomfanning Sep 28 '12 at 06:59
  • Does anybody feel like, when you hear somebody is learning in VB that's it's like hearing they've picked up smoking? – GONeale Jan 09 '13 at 09:14

1 Answers1

0

Here is the code you pasted converted to VB, not sure it's 100% correct

Private Sub VideoCamera_Initialized(sender As Object, eventArgs As Object)
If Initialized IsNot Nothing Then
    Initialized.Invoke(Me, New EventArgs())
End If
End Sub

Public Property LampEnabled() As Boolean
Get
    Return CBool(_videoCameraLampEnabledPropertyInfo.GetGetMethod().Invoke(_videoCamera, New Object(-1) {}))
End Get
Set
    _videoCameraLampEnabledPropertyInfo.GetSetMethod().Invoke(_videoCamera, New Object() {value})
End Set
End Property

here is some code I got from a sample and converted it

Dim cam As VideoCamera = Nothing
cam = New VideoCamera()
cam.Initialized += Function(s,e)
    cam.LampEnabled = True
    cam.StartRecording()
End Function

vCam.SetSource(cam)

New Thread(Function() 
    Try
    Dim isf = IsolatedStorageFile.GetUserStoreForApplication()
    Dim files = isf.GetFileNames()
    For Each file As var In files
    Debug.WriteLine("Deleting... " & Convert.ToString(file))
    isf.DeleteFile(file)
    Next
    Catch ex As Exception
    Debug.WriteLine("Error cleaning up isolated storage: " & ex)
    End Try
End Function).Start()

cam.StartRecording()

vCam is defined in xaml, not sure if you need it.

Shawn Kendrot
  • 12,425
  • 1
  • 25
  • 41