interop

Why Microsoft not provide for C# a static Win32 class with the most native functions and structures inside like windows.h?

Everybody who used P/Invoke of Windows API knows a long list of declarations of static functions with attributes like [DllImport ("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] The declaration of structures copied from Windows headers like WinNT.h or from web sites like www.pinvoke.net take also a lot of place in our p...

Static nested class visibility issue with Scala / Java interop

Suppose I have the following Java file in a library: package test; public abstract class AbstractFoo { protected static class FooHelper { public FooHelper() {} } } I would like to extend it from Scala: package test2 import test.AbstractFoo class Foo extends AbstractFoo { new AbstractFoo.FooHelper() } I get an error, "...

hidden forms and thr handles

i am hiding the form using SetVisibleCore to false, but now i cant get the handle of this form in other application which i am retrieving using EnumWindow its giving me exception "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." an ACCESS VIOLATION EXCEPTION. so i am searching on 2 ...

Interop c# using a "long" from c++

On my System: sizeof(long) in c++ is 4 aka 32bits sizeof(long) in c# is 8 aka 64 bits So in my Interop method declarations I've been substituting c++ longs with c# int's however I get the feeling this isn't safe? Why is a long the same size as an int in c++? And long long is 64bits? What's next a long long long long?? ...

Problem referencing directshow filter from C#

Hi, I have a custom DirectShow filter created by extending the ezrgb24 filter from the DirectShow sample documentation. I am using this filter (indirectly) in C# through a 3rd party multimedia SDK (LeadTools). Now I need to add a reference to the filter's DLL to the project so that I can cast an IUnknown interface retrieved by the SDK...

Have a problem importing to MapPoint through a C# DLL

We're trying to import a file from a C# dll into MapPoint, and can get it to read the data just fine, but we are having trouble with MapPoint not recognizing all of the addresses. Currently, our file contains not only address information, but latitude and longitude as well (under the headers of Lat and Lon). Is there any options we can...

Working with the IE cache

I'm writing a program in C# using the WPF framework. I need to display images, and I'd like to cache them to avoid downloading them constantly. I can code my own cache, however, IE already has a caching system. I can find code to read entries out of the IE cache, however I've found nothing dealing with the issue of adding items to the c...

How to eliminate Server 2008/Vista/Win7 Task Scheduler Interop warning?

I am using Interop.TaskScheduler.dll in a C# Windows Application. - NOTE: This is the evolved task scheduler from Server 2008/Vista/Win7 not the one from before. I've managed to set it up and it works fine. However, the following warning remains and I could not figure out why. Has any of you seen this before? Is there a way to get rid...

Getting the colour of Excel cells using interop

Hi, I have a range of cells the I retrieve from excel and I want to know how to get the colour of the cells in a column (all the cells are different colours). So far I have: Range range = sheet.get_Range( "A1", "D10" ); Which gets me the data I need into an object array but I want to be able to iterate through the rows and get the ce...

What is this exception ?

I am getting this exception while reading the shapes in excel sheet in c#: on code line of if (worksheet.Shapes.Count >= iCurrentRowIndex) { } Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Excel._Worksheet'. This operation failed because the QueryInterface call on the COM...

Is there any reason against directly calling AddRef() inside QueryInterface() implementation?

When implementing IUnknown::QueryInterface() in C++ there're several caveats with pointers manipulation. For example, when the class implements several interfaces (multiple inheritance) explicit upcasts are necessary: class CMyClass : public IInterface1, public IInterface2 { }; //inside CMyClass::QueryInterface(): if( iid == __uuidof...

How to detect the language of MS Excel from C#

If i try to use Excel from C# (interop) i receive error (HRESULT: 0x80028018) when current thread language is different from Excel language: so i need to set thread language, they must be the same. Which is the best method to understand the language of Excel/Office? 1) registry (HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Common\L...

How to access COM vtable and acess its entries from TLB(Type Library) in C#?

Hello, I need to access COM vtable which have entries of those functions which are exposed to outside world under some specific interface in C#. I've accessed and iterate over the types enclosed in the TLB with LoadTypeLib and playing with ITypeInfo. Now only thing I need to access one by one those methods inside vtable of COM Interfac...

Why Exception occured getting address of COM function ?

I am getting address of COM function by loading type library (TLB) and iterating over types using ITypeLib and ITypeInfo. After calling AddressOfMember function of ITypeInfo I am facing the following exception: System.Runtime.InteropServices.COMException (0x800288BD): Wrong module kind for the operation. (Exception from HRESULT: 0x80...

Some basic COM question...

I have just finished my first COM server DLL. And it runs smoothly. So I'd like to show my understanding for now and hear your critics. 1- How COM simply works? COM - "The Call Chain" COM Lib methods -> Traditional DLL exports -> Classes encapsulated in the COM DLL 2- With C++, the benefits like "interface" in OOP can only be taken ad...

How to protect an imported Win32 DLL into a .NET application from memory issues

I have a C# application that needs to use a legacy Win32 DLL. The DLL is almost its own application, it has dialogs, operations with hardware, etc. When this DLL is imported and used, there are a couple of problems that occur: Dragging a dialog (not a Windows system dialog, but one created by the DLL) across the managed code applicat...

WPF HwndHost keyboard focus

The chart area in the screenshot is a HwndHost control which hosts a native Win32 window (with it's own registered WNDCLASS) implemented in C++/CLI and drawn with Direct2D. The HwndHost is hosted in a WPF Border control. The problem I have is that I can't set the keyboard focus to the hosted Win32 window. I want the focus to move to the...

Is it possible to interop with Thunderbird using C#?

Here's the latest hurdle in my ongoing quest to automate my job: All email in the company goes through 4 different email adresses, switching randomly back and forth (with a note attached in the global share: please set "keep email on server") All logic related to email is contained in a nice big Thunderbird profile, which gets copied b...

IntPtr in 32 Bit OS, UInt64 in 64 bit OS

I'm trying to do an interop to a C++ structure from C#. The structure ( in C# wrapper) is something like this [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct SENSE4_CONTEXT { public System.IntPtr dwIndex; //or UInt64, depending on platform. } The underlying C++ structure is a bit abnormal. In 32 bit OS, d...

Outlook Interop Send Message from Account

Okay, the specs have changed on this one somewhat. Maybe someone can help me with this new problem. Manually, what the user is doing is opening an new message in Outlook (2007 now) which has the "From..." field exposed. They open this up, select a certain account from the Global Address List, and send the message on behalf of that accou...