interop

AccessViolationException on calling the most basic c++ function I can think of from managed code

Hi all, I'm trying to learn how to use managed/unmanaged code interop, but I've hit a wall that 4 hours of googling wasn't able to get over. I put together 2 projects in visual studio, one creating a win32 exe, and one creating a windows forms .NET application. After a bunch of mucking around I got the C# code to call into the c++...

aspcompat performance issue

I am using aspcompat page attribute in ASP.NET so the com components I call can get at ASP intrinsic objects (Request, Response, Application, etc) I have quickly created a new test project, one asp.net page and a vb6 com component. The page does this: for (int i = 0; i < 1000; i++) Application["string" + i] = i.ToString(); Debug....

GetPhysicalMonitorsFromHMONITOR returned handle is always null.

Hi, On the Media Foundation SDK there is the GetPhysicalMonitorsFromHMONITOR function that I am trying to implement using C# but with no luck ... In the returned PHYSICAL_MONITOR[], the function returns the string description of the monitor but for some mysterious reasons, the hPhysicalMonitor handle remains at 0. I have generated the...

Using a .net compiled dll inside native c++

Hi, as i understand that any .NET program gets compiled to MSIL which is fed to the CLR which compiles it to the assembly code and along with the help of JIT it executes it. I was wondering, as .NET is a wrapper around the win32 api and the CLR ultimately converts the MSIL to assembly program. Isn't it possible for me to write some func...

What is required to enable marshaling for a COM interface?

I have a 32-bit ATL COM component without a type library. It has a class factory for one given class that implements several interfaces. When I use it as an in-proc server, everything works fine - the client side invokes CoCreateInstance(), the object is instantiated and QueryInterface() retrieves a pointer to a requested interface. But...

Printing Excel using Interop

Does anybody have any idea how to print an excel file programatically using C# and the Excel Interop? If so, can you please provide code? ...

WCHAR array not properly marshalled

I have a COM interface with a following method definition (IDL notation): SCODE GetText( [in, out] ULONG* pcwcBuffer, [out, size_is(*pcwcBuffer)] WCHAR* awcBuffer ); Typelib marshaling is used for COM+, the type library is registered, other methods of the interface work allright when called through COM+, but not this met...

How to get minimized window's RESTORED bounds?

It's easy to get the bounding rectangle for all the visible windows on a screen. It's also easy to tell if any window is iconic or not. But for minimized windows, the Top and Left is reported as -32000 from User32.GetWindowInfo.rcWindow. I've looked all through the API and can't find a call to return the bounds the window would restore...

Using Excel Interop and getting a print dialog

Hello All! I have the following code: [Thank you Mike Rosenblum!] using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Office.Interop.Excel; using System.Runtime.InteropServices; namespace ConsoleApplication17 { class Program { static void Main(string[] args) { //pu...

GetLastError() and calling unmanaged code in a static library from C++ .NET

I made a static library in Visual C++ 2008 Express Edition. It compiles to Win32 code in a file called static.lib. The functions in this library call SetLastError() to indicate errors or success. I have already succeeded in including this static.lib in a C++ Win32 DLL, and calling the DLL from C# using p/invoke and DllImport and SetLa...

Do I need a job queue in my COM server?

I have a COM EXE out-of-proc server exposing an API from one of its interfaces. The functionality of this API is to post URLs. My client will be creating the instance of the COM server and calling this API with new URLs. Every time client needs to post a URL it will create an instance of this COM server. Do I need to implement a queue...

How do the threads get created inside a COM component?

I have one COM component which is instantiated inside a COM service (this .exe is running). I have ten clients. Each client is getting an interface (IXyz) pointer from ROT and calling a method IXyz::abc() at the same time. From my traces I see that IXyz::abc() is gettting called 10 times at the same time, but in 10 different threads. ...

Why does COM+ ignore the apartment threading model?

I have an STA COM component which is put into a COM+ application. The client creates several instances of the class in that component and calls their methods in parallel. The class is registered properly - the "ThreadingModel" for the corresponding class id is "Apartment". I see several calls of the same method of the same class being e...

Why does an 8-bit field have endianness?

See the definition of TCP header in /netinet/tcp.h: struct tcphdr { u_int16_t th_sport; /* source port */ u_int16_t th_dport; /* destination port */ tcp_seq th_seq; /* sequence number */ tcp_seq th_ack; /* acknowledgement number */ # if __BYTE_ORDER == __LITTLE_ENDIAN u_int8...

Does WCF FaultException<T> support interop with a Java web service Fault

I have written a java axis2 1.4.1 web service and .net 3.5 WCF client and I am trying to catch the wsdl faults thrown. Unlike .net 2.0 the .net 3.5 claims to support wsdl:fault and the service reference wizard does generate all the correct fault classes in the client proxy. But when I try to catch a fault it doesn't seem to correctly s...

How to implement Dispose in a COM object

I have written a COM component in unmanaged C++ to provide customers access to our database. When using it from an unmanaged language the database connections are correctly cleaned up as the objects go out of scope. I recently tried using it from VB.NET and discovered that the COM objects are not being destroyed. Scattering calls to S...

How to export a struct definition from a native C .dll for use in C#

I know how to extern methods in the .dll, how do I extern structs? I want to create a C method such as extern __declspec(dllexport) myStructure getStruct(); where myStructure is something like typedef struct { int A; int B; char C; } myStructure; How can I call getStruct() from a piece of C# code without first defining th...

64 to 32 bit Interop - how?

I need to integrate some legacy 32-bit code - for which I don't have the source code, into a project in such a way that it can be called from a 64-bit .NET assembly. The original code is implemented as a 32-bit COM object in a DLL. Windows doesn't allow direct calls from 64 to 32-bit objects, so I'm looking for inspiration on how to deal...

Printing using Word Interop with Print Dialog

Hey All! I'm trying to print a word doc from my C# code. I used the 12.0.0.0 Word Interop and what i'm trying to do is to get a Print Dialogue pop up before the document prints. I'm not 100% sure of the syntax of all of this as I can't get my code to work :( Any ideas? Thanks in advance! ...

Need help with connecting c++ and c# code with a c++/cli bridge

I have a client application in native c++ code which is using native c++ dlls. I am investigating the possibility of connecting this code with c# dlls as they would be much easier to write. I decided to write a c++/cli bridge dll which can be loaded with LoadLibrary and which would pass the calls to c# dll. The communication between the...