csharp - Dave's Blog

Search
My timeline on Mastodon

JavaScript & .NET interop via WebBrowser Control

2011 Apr 5, 10:00

For my GeolocMock weekend project I intended to use the Bing Maps API to display a map in a WebBrowser control and allow the user to interact with that to select a location to be consumed by my application. Getting my .NET code to talk to the JavaScript in the WebBrowser control was surprisingly easy.

To have .NET execute JavaScript code you can use the InvokeScript method passing the name of the JavaScript function to execute and an object array of parameters to pass:

this.webBrowser2.Document.InvokeScript("onLocationStateChanged",
new object[] {
latitudeTextBoxText,
longitudeTextBoxText,
altitudeTextBoxText,
uncertaintyTextBoxText
});

The other direction, having JavaScript call into .NET is slightly more complicated but still pretty easy as far as language interop goes. The first step is to mark your assembly as ComVisible so that it can interact with JavaScript via COM. VS had already added a ComVisible declaration to my project I just had to change the value to true.

[assembly: ComVisible(true)]

Next set ObjectForScripting attribute to the object you want to expose to JavaScript.

this.webBrowser2.ObjectForScripting = this.locationState;

Now that object is exposed as window.external in JavaScript and you can call methods on it.

window.external.Set(lat, long, alt, gUncert);

However you don't seem to be able to test for the existence of methods off of it. For example the following JavaScript generates an exception for me even though I have a Set method:

if (window.external && window.external.Set) {
PermalinkCommentsjavascript webbrowser .net technical csharp

ILSpy - SharpDevelop Wiki

2011 Mar 28, 4:06"ILSpy is the open-source .NET assembly browser and decompiler. Development started after Red Gate announced that the free version of .NET Reflector would cease to exist by end of February 2011."PermalinkComments.net tools reflector c# development csharp dotnet technical tool

Tessnet2 a .NET 2.0 Open Source OCR assembly using Tesseract engine

2010 Dec 7, 12:10PermalinkCommentsopen-source opensource ocr library .net csharp programming technical

Windows 7 Accelerator Platform COM / C# Interop

2010 Aug 20, 11:20

For a new project I'm working on involving IE's installed Accelerators and OpenSearch search providers via the Windows 7 Accelerator Platform, I've created a C#/COM interop class for those APIs.

Download the osinterop.cs interop file here.

PermalinkCommentstechnical accelerator csharp com

pinvoke.net: ConsoleFunctions (kernel32)

2010 Aug 14, 5:34pInvoke.net is a wiki for the C# interop declarations for various Win32 functions.PermalinkCommentspinvoke c# csharp consle api windows reference wiki technical

ClickOnce Deployment Overview

2010 Mar 5, 12:33ClickOnce is a .NET app deployment technology that lets you easily install apps with minimal user interaction even from the web. This is what Google Chrome uses to install so easily.PermalinkCommentsmsdn technical development security windows .net csharp programming clickonce google chrome

Coding4Fun : Look at me! Windows Image Acquisition

2009 Jun 20, 9:43How to use the WIA APIs in C#. WIA is Windows API to get images from scanners and cameras. And, as I found out, if you want to use the API in PowerShell try '$deviceManager = new-object -ComObject WIA.DeviceManager'PermalinkCommentsvideo scanner api wia csharp howto programming camera image photo .net webcam technical

Paint.NET - Free Software for Digital Photo Editing

2008 May 5, 11:45Free OpenSource C# paint program replacement with many more features than paint.exe =)PermalinkCommentswindows photo art microsoft csharp .net opensource development free paint

Create a Windows Clipboard Monitor in C# using SetClipboardViewer API - Rad Software

2008 Apr 21, 2:58"This example shows you how to use the Win32 API function SetClipboardViewer to create a Clipboard Viewer application" and the example is in C# and VB.Net.PermalinkComments.net csharp clipboard programming windows setclipboardviewer dllimport

Encoding methods in C#

2008 Apr 12, 10:38

For Encode-O-Matic, my encoding tool written in C#, I had to figure out the appropriate DllImport declarations to use IDN Win32 functions which was a pain. To spare others that pain here's the two files CharacterSetEncoding.cs and NationalLanguageSupportUtilities.cs that declare the DllImports for IdnToUnicode, IdnToAscii, NormalizeString, MultiByteToWideChar, and WideCharToMultiByte.

PermalinkCommentsencodeomatic boring csharp widechartomultibyte idn tool dllimport

Visual Studio Express Downloads

2008 Feb 16, 11:53The free downloadable versions of Visual StudioPermalinkCommentsmicrosoft visual-studio csharp c c++ trial express free

Singularity IV: Return of the UI

2007 Oct 8, 3:15Microsoft Research is working on Singularity, a new managed microkernel OS.PermalinkCommentsmsdn microsoft channel9 video singularity os research csharp

C# Graph Layout Library

2007 Feb 22, 7:23A C# graph layout library for free from Microsoft Research.PermalinkComments.net free graph microsoft research visualization csharp library glee

Script Happens .NET

2006 Aug 17, 10:01PermalinkCommentsscript javascript programming .net csharp msdn

Introduction - VSA Scripting in .NET - Developer Fusion, the UK developer community - VB, ASP, C#, .NET, PHP and XML tutorials & source code

2006 Aug 17, 10:01PermalinkCommentsscript .net csharp javascript vbscript programming

Microsoft Research Home

2006 Jun 27, 3:12Home to papers and code from Microsoft ResearchPermalinkCommentsmicrosoft research free programming csharp

Microsoft Research Data Visualization Components

2006 Jun 27, 3:08The Data Visualization Components give you six .NET components for adding data visualization into your own programs: - Treemaps - Bubble Charts - Piano Rolls - Spire Charts - Thread Trees - Time Series ChartsPermalinkCommentscsharp programming free visualization microsoft

The Old New Thing : Why Daylight Savings Time is nonintuitive

2006 Apr 3, 7:04I dislike Daylight Savings Time. Also I'm not fond of timezones. Boo on timezones.PermalinkCommentsblog raymond-chen microsoft msdn timezone daylight-savings-time FileTimeToLocalFileTime LocalFileTimeToFileTime programming csharp c++ windows

NewOrder - news: JustUs Book Coder: An Unbreakable* Code Utility for the Masses

2006 Apr 3, 4:06PermalinkCommentssecurity cryptography tool programming privacy development csharp book-cypher

Random Number Generation

2006 Jan 16, 11:59A Better Random Number GeneratorPermalinkCommentsdevelopment math random-number java c csharp algorithm csc
Older Entries Creative Commons License Some rights reserved.