Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
0 answers
53 views

Connect to Running Program via COM - Marshal.GetIUnknownForObject

I am using a software package that offers an "extension" package, largely undocumented, that allows for creation of extensions that allow automation within the program. It's a COM interface ...
GisMofx's user avatar
  • 1,004
0 votes
0 answers
80 views

Actual address of COM object in C#

I have a COM object for which I am trying to get the actual underlying address of, so I can get the address of the vtable. I need this to be a valid numerical address because I need to be able to add ...
Feem's user avatar
  • 386
1 vote
1 answer
61 views

Prevent the CLR from freeing memory of a marshalled double char pointer?

I am building a Visual Studio 2022 extension in C# and am currently playing around with the VS API. I am trying to call IVsObjectList2.GetText(), which is a COM interface. However, VS is crashing ...
Sedenion's user avatar
  • 6,103
0 votes
0 answers
99 views

Typesafe COM component with late binding in dotnet

I have some libraries in x32 that I need to call from x64 process. Googling around, I found the best way to do this is using COM components. I created 3 projects in c#: WinForms project that is X64 ...
Bojan Vukasovic's user avatar
0 votes
1 answer
81 views

Double hop marshaling in COM

Consider the following. Process A is a COM client. It creates an object in process B The object has a method that returns an interface pointer The implementation in B creates an object in process C ...
Seva Alekseyev's user avatar
0 votes
0 answers
222 views

Why do CoMarshalInterface and CoUnmarshalInterface need REFIID?

I am a noob regarding COM. In the project that I am currently working we use CoMarshalInterface and CoUnmarshalInterface with REFIID of IDispatch for all the COM object/proxy instances because they ...
Radu C's user avatar
  • 330
0 votes
1 answer
432 views

Marshalling a System.IO.Stream object in c# COM interface

I have a function in my c# COM interface which returns a System.IO.Stream object: Stream GetFile(); I intend to use this COM interface within unmanaged c++ code, and call this function from there, ...
Nautilus's user avatar
1 vote
1 answer
104 views

Does COM marshaling work with objects created using CComCoClass::CreateInstance?

Sorry if this is a dumb question, but I was wondering if the COM pointer-marshaling functions will work with objects created using ATL's CComCoClass::CreateInstance. According to the docs, that ...
user avatar
2 votes
1 answer
270 views

Passing a c# array of object to COM interface method

I should pass a pointer of object array to a COM interface with the following IDL and C++ definitions: C++ code: UpdateItem( LONG lID, LONG lNumOfFields, FieldIdEnum* pFields, VARIANT* pvValues ) IDL:...
droland's user avatar
  • 19
-1 votes
1 answer
478 views

How do I implement an interface from COM in C#

[NOT A DUPLICATE, I've searched for solutions for days and had performed a lot of tests only to find nothing really helps. That's why I registered stackoverflow and posted this.] [SITUATION] I am ...
Qiu's user avatar
  • 11
2 votes
1 answer
165 views

"Pure" dispinterface marshaling

Update 2021-04-20: The code presented here is for illustration purposes only. As pointed out by Simon Mourier, for marshaling in-process of such a simple class there is no need for all the TLB ...
Michael Bikovitsky's user avatar
1 vote
0 answers
170 views

How to marshal C# type to LPWSTR *

I have a native C++ project which has a struct that looks like this: struct COMStringArray { long lSize; LPWSTR * array; }; Which uses a com object written in C#, so I need ...
Norbert Forgacs's user avatar
2 votes
0 answers
148 views

How to avoid expensive array marshalling between VBA and C#?

I'm exporting this C# method through COM: public interface IMatrixMath { void AddScaledRange3D(ref double[,,] acc, [In] ref double[,,] vals, double scale); // ... } Then I call it with large ...
Sijmen Mulder's user avatar
0 votes
0 answers
248 views

How to solve: At least one of the arguments for '' cannot be marshaled by the runtime marshaler

I have a COM object written in C++ and a C# application using this ActiveX control. The C++ code is compiling fine, without any warnings. The C# application is generating several warnings like in the ...
Paul Meems's user avatar
  • 3,264
4 votes
3 answers
2k views

How to serialize a VARIANT or BSTR?

I am trying to figure out some COM marshalling features. Eventually, I want to persist a deeply nested variant array to file but I am trying first with a simple string. I realise these APIs are ...
S Meaden's user avatar
  • 8,220
0 votes
2 answers
471 views

How to access C++ COM Object in C# Background worker?

I am developing a common c# COM component (dll) which can be consumed by any COM client. As part of this I m exposing a outgoing interface called ICallback.The client which is using my dll will ...
srajeshnkl's user avatar
3 votes
1 answer
87 views

How to get structured list values from unmanaged c++ code to c#?

I'm writing "ICS/VCS" file parser in win32 c++. After deserialization from a file, I am storing event data inside a list of event struct. Now I want to access that structured list in c#. For that,...
Harsh Shah's user avatar
1 vote
1 answer
184 views

COM interface c# marshalling array of arrays

I have a COM server written in C++ that should interface with a client written in C#. The C++ COM server exports interface functions to a structure that holds an array of structures with an array ...
Jens Mose Pedersen's user avatar
3 votes
1 answer
206 views

Pass .NET SecureString to COM Interop

How do you manually marshal a BSTR from .NET to COM? I am trying to pass a secret stored in a SecureString from my .NET application to a method on a COM object. I want to avoid converting the ...
Daniel Schilling's user avatar
1 vote
1 answer
343 views

String Array property in COM Class and set it from VBA

I am recently working with one type library requirement. I have created a c# class that will be exposed to COM component. However, when I set a value to an array property I get a compiler error. All ...
Nitheen Rao's user avatar
1 vote
1 answer
736 views

Can not marshal interface from main thread into worker thread

INTRODUCTION I am buidling in-proc COM server to be consumed by VB6 client. COM server needs to use blocking function. This means that the VB6 GUI would be blocked until function retrieves the ...
AlwaysLearningNewStuff's user avatar
1 vote
1 answer
799 views

Use SHAssocEnumHandlers in C#

I am struggling to call the WinAPI SHAssocEnumHandlers in C#. using System; using System.Runtime.InteropServices; namespace AssocHandlerTest { [Flags] public enum ASSOC_FILTER { ...
Patrick's user avatar
  • 371
0 votes
1 answer
63 views

Can different threads reuse the same marshalled ActiveX interface?

when I marshal ActiveX interface through Global Interface Table (GIT), do I need to call GetInterfaceFromGlobal() from every thread that will use this interface? Alternatively, once one thread gets a ...
user3070144's user avatar
2 votes
0 answers
152 views

Why can I not mix Guid and string members in a ComVisible struct?

Consider the following interface (registered with regasm /tlb with a c# out of process server and client): [ComVisible(true)] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface ...
Mitch's user avatar
  • 22.2k
2 votes
0 answers
105 views

Accessing C++ arrays passed via COM in C#

I have a legacy COM class that passes C++ array pointers without using SAFEARRAY. (It was probably implemented before that existed.) I'd like to implement an interface in C# without change the COM ...
jsparkes's user avatar
  • 321
4 votes
1 answer
6k views

Returning a string from an unmanaged c++ dll to c# [duplicate]

I'm trying to call unmanaged c++ from c# but receiving an exception about the return value. The exception: System.Runtime.InteropServices.MarshalDirectiveException: 'Cannot marshal 'return value': ...
as2005's user avatar
  • 63
1 vote
1 answer
1k views

Marshal [in] reference without ref

Some functions, especially in COM interfaces, expose a REFIID parameter that is used to specify the type of the interface the methods should return. Here's such an example method: [DllImport("shell32....
IS4's user avatar
  • 13.1k
0 votes
1 answer
169 views

Unable to ReDim array from C# class in VB6

I have to use C# class in vb6 which contains arrays. I'm marshalling them as Safe Arrays but I can't redim them in VB6, although in watch I can see that they have correct types. When I was using the ...
Cirate's user avatar
  • 151
1 vote
1 answer
293 views

MSXMLl 6.0 XmlDOMNodeList fails when is invoked GetEnumerator

Our project uses MSXML 6.0 com object for working with XML through ComImport attribute. Below com Class which provides access to existing MSXML COM(I left only SelectNodes for clarify problem ). [...
Artsiom Che's user avatar
0 votes
0 answers
725 views

How to pass COM parameter of type SAFEARRAY** from C#

I'm trying to call a COM interface function from C# code. This is an aggregated COM interface where I load the implementing COM interface by ProgID and I have to declare the interface myself. The c++...
forother's user avatar
0 votes
0 answers
135 views

GetEnumerator throws ArgumentException on Windows with WinRT

I оbtain xmlCollection through com objects and try to use foreach with the obtained collection. That invokes this System.ArgumentException at System.Runtime.InteropServices.Marshal....
Artsiom Che's user avatar
4 votes
0 answers
961 views

Error 'Unable to cast COM object of type' when crossing thread apartments in C#

I've been working with a third party SDK as a referenced dll from within C# using .NET 4.5.2 on Windows 10. The IDE creates an Interop around the dll and I can see the appropriate namespaces, ...
Geo...'s user avatar
  • 307
1 vote
0 answers
2k views

Unable to get usable data from System.__COMObject

I am working with a third party SDK (Proprietary) which I have referenced in my console app, I been tasked to help build a solution which will facilitate many everyday tasks. However, as I been ...
EasyE's user avatar
  • 580
3 votes
1 answer
379 views

How to use IFont and IStrings in Delphi 2010?

I want to write a DCOM client/server in Delphi 2010 that uses IStrings to pass Memo1.Lines(as TStrings) as property in a test Server. The server has a TMemo component and I want to set or get its ...
Zonouzi's user avatar
  • 101
1 vote
1 answer
674 views

FreeThreadedDOMDocument, Neutral Apartments and Free-Threaded Marshaler

As MSDN states: If you are writing a single threaded application (or a multi-threaded application where only one thread accesses a DOM at one time), use the rental threaded model (Msxml2....
andrebroz's user avatar
  • 316
1 vote
1 answer
485 views

To Marshal or Not to Marshal

I could not find the definite answer to the following question: if a COM class is thread safe, that is it is marked with Both or Free, do I really need to marshal its object interface to pass it to ...
andrebroz's user avatar
  • 316
1 vote
0 answers
128 views

Passing ref object array from .net to COM server

I'm trying to convert from vb6 to vb.net and I face a picky problem. I have to pass a reference array object to COM server from vb.net, but variant type of passed array object has VT_DISPATCH, ...
Garam Han's user avatar
7 votes
1 answer
360 views

Pass C# object to COM by value

I'm trying to use a COM interface from C# that exposes the following interface as generated by tlbimp: [Guid("7DDCEDF4-3B78-460E-BB34-C7496FD3CD56")] [TypeLibType(TypeLibTypeFlags.FDual | ...
Bas Bossink's user avatar
  • 9,658
0 votes
1 answer
36 views

RCW does not convert integer when passing from .Net to COM

As per MSDN, regarding the conversion of types done by the RCW between .Net client to unmanaged objects, it is written: ...Other types require no conversion. For instance, a standard wrapper will ...
ehh's user avatar
  • 3,480
0 votes
1 answer
683 views

ReportAvOnComRelease Error with Marshal.Release()

I have seen similar errors here but can't quite determine what's causing it. I have an IntPtr which is referencing a GetForegroundWindow() object : IntPtr ptr = GetForegroundWindow(); This ...
Pogrindis's user avatar
  • 8,081
0 votes
0 answers
195 views

Unable to access values of array passed from managed to unmanaged code

What i am trying to do : i am trying to call a method written in a ATL COM server (a dll basically) from a c# client.i am trying to pass a c-style 1-dimensional array by reference to the method and ...
chandu's user avatar
  • 21
0 votes
1 answer
189 views

Passing an object in C# that inherits from a generic causes a cast exception with IDispatch

I have a COM call I would like to make [DispId(163)] [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] [return: MarshalAs(UnmanagedType.IDispatch)] object ...
bradgonesurfing's user avatar
0 votes
1 answer
354 views

Marshalling array of struct (that contains an array of struct) from C# to Delphi (managed to unmanaged)

The C# struct: public struct Table { [MarshalAs(UnmanagedType.LPArray)] public Parameters[] parameters; public string Name; etc... } public struct Parameters { public string ...
wolfrevo101's user avatar
2 votes
1 answer
670 views

COM and Services

I'm trying to create a service to communicate with a COM object that controls on BarCode Scanner (model Motorola Symbol LS9208). I created the TLB unit from ocx installed with scanner driver ...
alijunior's user avatar
  • 327
2 votes
0 answers
455 views

Marshalling Variable Length Array in C#

I am processing input data from a human interface device using GetRawInputData. There is a RAWINPUT structure which contains a RAWHID structure: typedef struct tagRAWHID { DWORD dwSizeHid; DWORD ...
Robert Luciano's user avatar
0 votes
1 answer
600 views

C# Marshalling to call C++ DLL. COM and threading issue

When I try to call a extern method from a non-main thread, I get COM CoInitialize error from the DLL written in C++ thread. Just for slight more details, I have define an alias to call the c++ method ...
GHB's user avatar
  • 1
0 votes
0 answers
145 views

C# program needs access to large dataset in C++ COM quickly

I have a C# program that wants to process some floating point data. The data comes from native C++ code that is 64 bits (a COM EXE) while the C# program is 32 bits. I can pass data back and forth ...
Rick Wirch's user avatar
0 votes
1 answer
933 views

Getting ref parameter from COM with InvokeMember call

I am trying to call a method of a COM server using InvokeMember. The method has the following signature: void InsUpdOpInstance( [in] long inIdOperDescr, ...
nnspu's user avatar
  • 11
0 votes
1 answer
938 views

COPYDATASTRUCT and Marshal.PtrToStructure throws AccessViolationException

My 64-bit C# 4.5.1 WinForms application, using the following code, correctly gets a COPYDATASTRUCT message from an external 32-bit C++ DLL (over which I have no control), as shown in a Memory Window ...
shipr's user avatar
  • 2,839
2 votes
0 answers
2k views

Error Creating an instance of the COM component with CLSID. WCF with COM

How can i solve the next problem that i have. Im using WCF and it reference a COM. Creating an instance of the COM component with CLSID {...} from the IClassFactory failed due to the following error: ...
Hernan Laqui Jimenez's user avatar