This is a preview version of Cyotek's blog and may be missing functionality and/or unstable. Please visit https://www.cyotek.com/blog for the current version of the blog.
If you encounter any problems using this preview site, please contact us with the details.

Posts tagged with 'interop'

Resolving compile error "Interop type cannot be embedded. Use the applicable interface instead"

interop com 1 Comments

Recently I've been experimenting with the Microsoft Windows Image Acquisition Library (WIA), a COM library that therefore requires the use of interop in .NET. In the course of testing some of the different features of this library I triggered a compile error I haven't come across for a long time. As it isn't often I work with COM interop I thought I'd write a quick post detailing how to resolve or work around the compile errors to more firmly cement it in my head for the next time.

In older versions of .NET (or Visual Studio), when you referenced a COM library an interop DLL was generated - you could always tell these from their filenames as they would start with Interop.. I also seem to remember that back in the days of .NET 1.1 I would manually run a utility program to generate the interop DLL's, to avoid some form of naming prefix.

Read More

Reading cookies from Internet Explorer

c# interop webbrowser InternetGetCookieEx cookie 0 Comments Downloads

In order to work around cases where it wasn't possible automatically authenticate with a website, I wanted the ability to use an embedded Internet Explorer window for manual authentication and then reuse the cookies. This article describes how to read cookies indirectly using InternetGetCookieEx or directly from a WebBrowser control.

The InternetGetCookieEx Win32 API can be used to read cookie name value pairs for a given URI. You can use it to read all cookies or a named cookie. You can also specify which type of cookies to include.

Read More

Retrieving font and text metrics using C#

c# interop api GetTextMetrics TEXTMETRIC 0 Comments Downloads

In several of my applications, I need to be able to line up text, be it blocks of text using different fonts, or text containers of differing heights. As far as I'm aware, there isn't a way of doing this natively in .NET, however with a little platform invoke we can get the information we need to do it ourselves.

The GetTextMetrics metrics function is used to obtain metrics based on a font and a device context by populating a TEXTMETRICW structure.

Read More

Working around System.ArgumentException: Only TrueType fonts are supported. This is not a TrueType font

c# interop fontdialog 0 Comments Downloads

One of the exceptions I see with a reasonable frequency (usually in Gif Animator) is Only TrueType fonts are supported. This is not a TrueType font.

System.ArgumentException: Only TrueType fonts are supported. This is not a TrueType font.
  at System.Drawing.Font.FromLogFont(Object lf, IntPtr hdc)
  at System.Windows.Forms.FontDialog.UpdateFont(LOGFONT lf)
  at System.Windows.Forms.FontDialog.RunDialog(IntPtr hWndOwner)
  at System.Windows.Forms.CommonDialog.ShowDialog(IWin32Window owner)
Read More

Adding Double Click support to the ComboBox control

c# winforms interop combobox GetComboBoxInfo COMBOBOXINFO NativeWindow WM_LBUTTONUP WM_LBUTTONDBLCLK 0 Comments Downloads

I was recently using a ComboBox control with the DropDownStyle set to Simple, effectively turning into a combined text box and list box.

However, when I wanted an action to occur on double clicking an item in the list I found that the control doesn't actually offer double click support. I suppose I should have just ripped out the combo box at that point and went with dedicated controls but instead I decided to extend ComboBox to support double clicks.

Read More

How to be notified when your application is activated and deactivated

c# winforms interop pinvoke WM_ACTIVATEAPP 2 Comments Downloads

I recently had a requirement where a user was able to perform an action externally to my application, and my application then had to detect this for processing.

I could of course just had a poller running away in the background to check, but as the requirement also needed user input, why not just wait until the user switched back to my application, then check and deal with accordingly?

Read More

Extracting email addresses from Outlook

c# interop com outlook email office 0 Comments Downloads

The cyotek.com receives an awful lot of spam and a lot of this is sent to email addresses that don't exist. However, as we currently have catch all's enabled, it means we receive it regardless. This is compounded by the fact that I tend to create a unique email address for each website or service I interact with. And it's impossible to remember them all!

As a first step to deleting the catch alls, I wanted to see how many unique @cyotek.com addresses were in use. The simplest way of picking up these would be scanning PST files - we have email going back to 2002 in these files, and there's the odd backup elsewhere going back even further. Last time I used OLE Automation with Outlook was back in the days of VB6 and I recall well getting plagued with permission dialogs each time I dreamed of trying to access the API. Still, I thought I'd take a look.

Read More

Error 80040154 when trying to use SourceSafe via interop on 64bit Windows

win64 80040154 {783cd4e4-9d54-11cf-b8ee-00608cc9a71f} interop com sourcesafe 9 Comments

We recently moved to Windows 7, and I decided to go with the 64bit version for my machine. One of the utilities we use is a small tool for adding folders to Visual SourceSafe (why we haven't moved to another SCC provider yet is another question!) via the SourceSafeTypeLib interop dll. However, I was most annoyed when it wouldn't work on my machine, the following exception message would be displayed:

Retrieving the COM class factory for component with CLSID {783CD4E4-9D54-11CF-B8EE-00608CC9A71F} failed due to the following error: 80040154.

Read More