Error running WPF application using ChromiumWebBrowser from CefSharp.Wpf on Windows 8.0 SP1 - windows-8

I need to use WPF aplication on Win 8.0 with .net 4.6.2
I want to use ChromiumWebBrowser on it.
Unfortunately, when I start the window with that ChromiumWebBrowser component, the application closes with an error in the eventlog.
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
at CefSharp.CefSettingsBase..ctor()
at CefSharp.Wpf.Example.App.OnStartup(System.Windows.StartupEventArgs)
at System.Windows.Application.<.ctor>b__1_0(System.Object)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
at System.Windows.Application.RunDispatcher(System.Object)
at System.Windows.Application.RunInternal(System.Windows.Window)
at System.Windows.Application.Run(System.Windows.Window)
at CefSharp.Wpf.Example.Program.Main(System.String[])
....
Is posible to run application with CefSharp.Wpf on Windows 8.0 SP1?
Thanks for the help

Related

Can I embed another running exe inside my visual basic form?

I started experimenting with embeding another .exe in my form. I managed to run another program and use it inside a forms panel. Is there a way to put inside this panel an already running exe?
Public Class Form1
Declare Auto Function SetParent Lib "user32.dll" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Dim proc As Process
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
proc = Process.Start("C:\WINDOWS\notepad.exe")
proc.WaitForInputIdle()
SetParent(proc.MainWindowHandle, Panel1.Handle)
End Sub
End Class
The code becomes like this. The notepad.exe needs to be running , on startup it embeds the notepad.exe on the main form. Thanks a lot.
Public Class Form1
Declare Auto Function SetParent Lib "user32.dll" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim proc = Process.GetProcessesByName("notepad").FirstOrDefault()
If proc IsNot Nothing Then
SetParent(proc.MainWindowHandle, Panel1.Handle)
End If
End Sub
End Class

Implementing a Cue Banner to a textbox

I have found the following code on the internet:
Imports System.Runtime.InteropServices
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SetCueText(TextBox1, "Enter Name here")
End Sub
End Class
Module CueBannerText
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, <MarshalAs(UnmanagedType.LPWStr)> ByVal lParam As String) As Int32
End Function
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As IntPtr, ByVal hWnd2 As IntPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As IntPtr
Private Const EM_SETCUEBANNER As Integer = &H1501
Public Sub SetCueText(ByVal control As Control, ByVal text As String)
If TypeOf control Is ComboBox Then
Dim Edit_hWnd As IntPtr = FindWindowEx(control.Handle, IntPtr.Zero, "Edit", Nothing)
If Not Edit_hWnd = IntPtr.Zero Then
SendMessage(Edit_hWnd, EM_SETCUEBANNER, 0, text)
End If
ElseIf TypeOf control Is TextBox Then
SendMessage(control.Handle, EM_SETCUEBANNER, 0, text)
End If
End Sub
End Module
However it gives me the following error:
'Handles' in modules must specify a 'WithEvents' variable qualified with a single identifier.
Does anybody know how to implement a working cue banner, or how to fix this error?
I have just pasted your code into VS and it works, there are 2 things you should be aware of though. VB.net does not care about the case of your variables since it is case insensitive therefore control is the same as Control and the other thing is that according to the MSDN Page on EM_SETCUEBANNER .
From Link:
Sets the textual cue, or tip, that is displayed by the edit control to prompt the user for information.
Parameters
wParam [in]
TRUE if the cue banner should show even when the edit control has focus; otherwise, FALSE.
FALSE is the default behavior—the cue banner disappears when the user clicks in the control.
lParam [in]
A pointer to a Unicode string that contains the text to display as the textual cue.
if you note the part that I put in bold it states that it will disappear when the user clicks in the control, i.e. the control has focus. There for if you just have one item on your test program that can receive focus you will never see the cue.
My Working Code:
Imports System.Runtime.InteropServices
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
SetCueText(TextBox1, "Enter Name here")
End Sub
End Class
Public Module CueBannerText
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, <MarshalAs(UnmanagedType.LPWStr)> ByVal lParam As String) As Int32
End Function
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As IntPtr, ByVal hWnd2 As IntPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As IntPtr
Private Const EM_SETCUEBANNER As Integer = &H1501
Public Sub SetCueText(cntrl As Control, text As String)
If TypeOf cntrl Is ComboBox Then
Dim Edit_hWnd As IntPtr = FindWindowEx(cntrl.Handle, IntPtr.Zero, "Edit", Nothing)
If Not Edit_hWnd = IntPtr.Zero Then
SendMessage(Edit_hWnd, EM_SETCUEBANNER, 0, text)
End If
ElseIf TypeOf cntrl Is TextBox Then
SendMessage(cntrl.Handle, EM_SETCUEBANNER, 0, text)
End If
End Sub
End Module
You have:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SetCueText(TextBox1, "Enter Name here")
End Sub
End Class
...Which should be fine, however, you then have:
Module CueBannerText
...
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SetCueText(TextBox1, "Enter Name here")
End Sub
End Module
Your error is most likely due to the Private Sub Form1_Load... in Module CueBannerText. Since you have that in your Class Form1, it isn't needed in the module, so delete it.
EDIT:
Also, you have
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, <MarshalAs(UnmanagedType.LPWStr)> ByVal lParam As String) As Int32
End Function
...which doesn't need the End Function

Error Getting Form Handler (Vb.net)

I have the current code:
Public Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As HandleRef, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As String) As IntPtr
End Function
Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
Public Function WindowHandle(ByVal sTitle As String) As Long
WindowHandle = FindWindow(vbNullString, sTitle)
End Function
Dim CurrentProcess As Process
Dim CurrentHandle As IntPtr
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
SendMessage(CurrentHandle, 256, Keys.A, 0)
SendMessage(CurrentHandle, 257, Keys.A, 65539)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
CurrentProcess = Process.GetProcessesByName(ListBox1.SelectedItem.ToString.Remove(0, ListBox1.SelectedItem.ToString.IndexOf("{") + 1).Replace("}", ""))(0)
CurrentHandle = New IntPtr(WindowHandle(CurrentProcess.MainWindowTitle))
Timer1.Start()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
If you take a look at the button sub, every time it runs, it errors with "Arithmetic overflow error!"
What is wrong here? This should work... right?
Sorry, this is a bit vague but it's as much as I know.
Your Declare statements are correct but the way you call them is not. The loose typing allowed by VB.NET is getting you in trouble, the kind you can't diagnose. The cure for that is letting the compiler tell you that you did it wrong. Put this at the top of your source code file:
Option Strict On

Message-Only window not receiving PostMessage

I have an Vb.net application made by a third party , that I need to control using outside resources from a simulated environment and must not interact with the desktop. To simulate inputs that a user would normally input from a special screen with specific keys around it, I've built a test control library to control it and send the form image to a .bmp. The form cannot be visible and showed in taskbar , the bmp output will be displayed by the simulated environment.
Using PostMessage and sendKeys work well as long as I don't but ShowInTaskbar = False for the main form. After many read & testing, I have learned enough to try what seems to be the only thing that would work. I've created a form that I setparent using HWND_MESSAGE parameter, this should create a Message-Only Windows, that are supposed to received postMessage, and subclass it's events.msdn.
StackOverflow already about this
Unfortunately , I can't seem to get it to work, and I was hoping someone could tell me what I'm doing wrong.I have been testing several different ways found through out the web about .net , and short of going into message thread peek and feed(maybe(may be)my last hope), they all seem to work until I take the forms out of the taskbar.
Ok, here are the code:
The MsgOnly.vb
Public Class MsgHandling
DllImport("user32.dll", SetLastError:=True,CharSet:=CharSet.Auto)> _
Public Shared Function SetParent(ByVal hWndChild As IntPtr,
ByVal hWndNewParent As IntPtr) As
IntPtr
End Function
Private Shared HWND_MESSAGE As IntPtr = New IntPtr(-3)
Public Event CallBackProc(ByRef m As Message)
Public Sub setParent()
SetParent(Me.Handle, HWND_MESSAGE)
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
RaiseEvent CallBackProc(m) 'then RaiseEvent
MyBase.WndProc(m)
End Sub
End Class
Part subclassing in the form(Can't show more than what handles the sub classing, privacy issues. Hopefully this will suffice )
Public WithEvents Msg As New MsgHandling
Private Sub XXXXX_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'----snips
Msg.setParent()
'----snips
end sub
Private Sub CallBackProc(ByRef m As System.Windows.Forms.Message) Handles Msg.CallBackProc
Me.Text = "Rx events " & m.LParam.ToString() & " " & m.WParam.ToString()
WndProc(m)
End Sub
Test form
Public Class Form1
<DllImport("user32.dll")> _
Private Shared Function SetForegroundWindow(ByVal hWnd As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
Private Shared Function FindWindow( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr
End Function
Public Shared Function SetWindowPos( _
ByVal hWnd As IntPtr, _
ByVal hWndInsertAfter As IntPtr, _
ByVal X As Int32, _
ByVal Y As Int32, _
ByVal cy As Int32, _
ByVal uFlags As Int32) _
As Boolean
End Function
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Declare Function AllowSetForegroundWindow Lib "user32" Alias "AllowSetForegroundWindow" (ByVal dwProcessId As Integer) As Boolean
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
Public myProcess As Process = New Process()
Private Const WM_KEYDOWN As Long = 100
Private Const WM_RBUTTONDOWN As Long = 204
Public Shared HWND_MESSAGE As IntPtr = New IntPtr(-3)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myProcess.StartInfo.FileName = "...\XXXXXX.exe" 'Not real name
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
myProcess.EnableRaisingEvents = True
AddHandler myProcess.Exited, AddressOf Me.SendKeysTestExited
myProcess.Start()
End Sub
Friend Sub SendKeysTestExited(ByVal sender As Object, _
ByVal e As System.EventArgs)
Dim myRxProcess As Process = DirectCast(sender, Process)
myRxProcess.Close()
End Sub
Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Dim tHwnd As Long
Dim rslt As Boolean
If myProcess.Responding Then
tHwnd = FindWindowEx(HWND_MESSAGE, 0, 0, 0)
PostMessage(HWND_MESSAGE, WM_RBUTTONDOWN, 0, "TEXT TO SEND")
Else
myProcess.Kill()
End If
End Sub
Private Sub Form1_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
myProcess.Close()
End Sub
End Class
Not really sure what other details I can provide for now. Anyone as any idea or ways I haven't found?
Thanks for any input
I've found a work around. It seems like the problem comes from the fact that the windows handle is not find with the search functions. I have tried several ways, but since message-only are not enumerated, I can't loop, or at least I wasn't successful.
So I create a file with the handle, that the external program reads and the use that handle to make the PostMessage. This works well for now. I wish I could find a better way, but at least I have something to propose as a solution.
I'm still open to suggestion or other possible workaround:).

vb.net listbox exception

I am getting an exception when trying to run the below code in vb.net 2005
Public Class Form1
Public Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hWnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As String) As Long
Public Const LB_FINDSTRING = &H18F
Dim listBoxHandle As IntPtr
Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
listBoxHandle = ListBox1.Handle
ListBox1.SelectedIndex = SendMessage(listBoxHandle, LB_FINDSTRING, -1, Int(TextBox1.Text))
End Sub
End Class
Your P/Invoke declaration is wrong, it dates back to the VB6 era. Use pinvoke.net to find the VB.NET equivalents. But first take a look at the MSDN Library, .NET has vastly improved beyond what VB6 provided. You don't have to resort to these kind of tricks anymore:
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
ListBox1.SelectedIndex = ListBox1.FindString(TextBox1.Text)
End Sub
You are sending this to an ANSI function. A .NET String is unicode.
You need to update the referenced P/Invoke.
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger,_
ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function
And at the top of your code file
Import System.Runtime.InteropServices
Here is some more information on SendMessage - http://www.pinvoke.net/default.aspx/user32.SendMessage
Assuming your ListBox has only String objects you can use this for the KeyUp() function
Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
ListBox1.SelectedItem = TextBox1.Text
End Sub
It will only work if the entire text is found in the ListBox, though. If you want to get partial matches you'll have to write your own function and handle duplicates.
Also, as a rule, P/Invoke should be used as a last resort. If you find yourself using the DllImport or DECLARE syntax you should stop right there. There are definitely times for using it, but 99.999% of the time you can get away without.