interop

Native C++ to Managed C++ to C#

I am working on porting a large number of .h and .lib files from native C++ to Managed C++ for eventual use as a referenced .dll in C#. Please, I know it'd be a lot easier to port the whole thing to .NET, but if I could I would. It's 3rd party and all I have are .lib(no exports) and .h files to work with. Everything has been going smo...

Javascript and C# COM interaction

I am using C# COM Interop techniques to interact with some device from website using ActiveX. Right now I can call C# codes from javascript and pass only string values. But I intend to pass javascript structure into C# method and the reverse. How can I do that. Right now as an alternative I pass JSON formatted string from C# code and ge...

Get a MS GeoId from a 3 lettor ISO code (ISO 3166-1 alpha-3)

I have a 3 letter ISO code (e.g. DEU for germany, USA for America...) and would like to get the GeoID as listed in this table, also available here How can I do that using either straight .NET, P/Invoking or through the MapPoint PIA. e.g. given "SWE", I would like to retrieve 221. System.Globalisation.RegionInfo looks kinda promising - ...

How to debug "Wrong number of arguments or invalid property assignment" vbscript .NET interop

I have a .NET assembly, written in C#. It's marked ComVisible, has a guid, is signed, regasm'd (/codebase). I did not formally define an interface for the COM part. I use this assembly via VBscript. There's an overloaded method - one form takes a single string argument, and the second takes two strings. Both return another .NET type...

How to suppress compiler warnings from the use of COM references in a .NET project

We're using the Windows COM+ Services Type Library (located at C:\Windows\system32\COMSVCS.dll) to track COM+ processes on a remote machine using a service that is written in C# 3.0/.NET 3.5. The problem that I am encountering is that I am getting a whole slew of warnings from the compiler that look something like the following: At l...

Serializing COM Interop Object using C#

Hi guys! I'm working in a WCF project and we need to reuse some legacy components from vb6. In the service, we need to mantain state for each user as we need to store one COM Interop object (per user) which is costly to construct. The project can grow in the future so it's possible we may need to use StateServer/SqlServer-based sessio...

loading managed resources from c# and passing it to Native CPP code as a stream handle

I have a file that I have embedded as a resource in a managed C# assembly. I would like to pass the pointer to that resource and its size to some native code so it can extract it for me if needed. Are there C# api's that give me the intptr of that embedded resource? ...

How to load an Excel Addin using Interop

Hi, I have an addin which I want to invoke through Excel interop from a C# winforms application. I can't get the addin etc. to load unless I uninstall and resinstall it each time (this is apparantly something to do with Excel not loading addins when you use interop - btw, can't get their example to work in C#). Unfortunately this is s...

Compiling VB6 app w/ .NET interop, only runs if compiled on my machine

I recently developed an interop user control in .NET (Visual Studio 2008, project targetting .NET 2.0) to be used in a VB6 application. The assembly exposes 1 control, 1 class, and a few enums and structs. I developed it using C# translations of the Interop Forms Toolkit 2.0 project template found here. The assembly has a strong name and...

Excel Replace all found chars

I've been trying to replace all "#" in a Excel worksheet using a winform application... I tried with something like this Excel.WorksheetClass excelWorksheet = (Excel.WorksheetClass)application.Worksheets[1]; excelWorksheet.Cells.Replace(@"\", "", Excel.XlLookAt.xlWhole, Excel.XlSearchOrder.xlByColumns, false, Type.Missing, fals...

Using Reflection with COM Interop

After an interop call, I get back a COM object. I know this object will be one of three possible COM classes (Class1, Class2, Class3), but do not know which one in runtime. The reflection upon that object (interopObject.GetType()) returns the base RCW wrapper of System.__ComObject. What I need is to set some properties on the object - ...

what's wrong in my code related to COM??

*****BLOCK_1**** if( strcmpi(appName.c_str(),MSSQL)==0 ||strcmpi(appName.c_str(),MSSQL2005)==0 ) { if (FAILED(CoCreateInstance (CLSID_SQLDMOServer, NULL, CLSCTX_INPROC_SERVER, IID_ISQLDMOServer, (LPVOID*)&m_pSQLServer))) { DMOAvailable=false; IDiscoverPtr pICalc; HRESULT hRes=CoCreateInstance(Test::CLSID_SqlClass, NU...

unable to create TLB from the Com dll

Hi, I have WMI class in a COM dll. I was trying to create a RCW for it in C#.NET. I used tlbexp.exe to get the type library from the COM dll but it throws an error stating "unable to load one of the dependencies". I understood that it is trying to load one of the DLL it is referring internally, how can i come to know which dll it is t...

Marshaling from C# to C++

Hi, I am new to C# and visual studio. I have a C# GUI that passes parameters to functions exported from a C++ DLL. The platform in Visual Studio 2005. I have a function in the c++ DLL that take parameters of the following types: UINT8 UINT16 LPCWSTR someword (the following has been defined in the c+= dll : typedef void* someword..so ba...

A Simple C# DLL - how do I call it from Excel, Access, VBA, VB6 ?

Hi all, I have a simple class library written in c#. using System; namespace TestDll { public class Test { public string HelloWorld { get { return "Hello World"; } } } } My question is how can I call this HelloWorld function from Microsoft Office ...

Can I use DLL written in C++ in my C# project?

The problem is - I want to write a template class in C++, put it in a DLL, and then call it from my C# project. Is it possible? Can you please provide any references or articles on about how to do it? EDIT I want DLL to be written in unmanaged C++ ...

Marshalling a class intance's pointer between C++ and C#

I have an ActiveX control (written in C++) and reference it's RCW assemblies (created by aximp.exe) from a C# project. In the C++ code implementing the Ax control, I have a class implementing an interface which is exposed as a property of the Ax control. Looking at the generated RCW assemblies, I see the interface. And I can attempt t...

Automating Outlook and Word to create email message

I'm trying to create a Word email message that will be used as the body for an Outlook message. I've been looking at sample code from Microsoft here but this code falls over when trying to create the new word document at the wordApp.Documents.Add line: Word.Application wordApp = new Word.Application(); object template = Syste...

Word Interop Not Working In A Scheduled Task

I'm currently developing a script that takes a Word document, opens it up in Word, and then prints the Word file as a PDF. Everything works great when run manually either on my machine or the server. The problem comes in when I attempt to run it as a scheduled task. One of the requirements is that this should be done nightly without an...

Marshalling Issues

I have a C++ DLL that interacts with a card reader. It requires a pointer to a data struct, which isn't a problem to do. However, when trying to interact with the DLL in C# I'm getting all kinds of problems. Errors writing to protected memory, the application just shutting down after executing the getData command, etc. Here's what we...