com-interop

Avoiding disconnected context warning when shutting down a thread on which STA COM objects have been created

删除回忆录丶 提交于 2020-01-06 04:38:07
问题 I am working on a COM API written in C++ with ATL, which clients will be expected to use in C# via it's COM interop facilities. Currently all the COM objects are only written to support the single threaded apartment model. Some of the functions of this API cause a separate worker thread to be spawned, which listens for events from a server. In response to events from the server this worker thread creates some fairly simple COM objects, and then passes these objects to a COM event. There are

VB6 .NET Interop - Performance issue

不打扰是莪最后的温柔 提交于 2020-01-06 02:33:16
问题 I'm trying to use a VB6 app consumed in a C# app. The VB6 App is a Winform app. To do this, I have modified the VB6 App (EXE) to a DLL. Then I've referenced it in my C# app. In my VB App, I've add a new Class with some methods just to open VB forms. Everything works fine... except that if the form has many controls (30), the window is extremely slow to open (> 4s whereas < 1s in VB) 1/ Is this method good ? 2/ How to resolve this ? Regards, Florian EDIT : I know where is the problem but I don

How can I reliably check client identity whilst making DCOM calls to a C# .NET 3.5 Server?

a 夏天 提交于 2020-01-03 19:09:28
问题 I have an old Win32 C++ DCOM Server that I am rewriting to use C# .NET 3.5. The client applications sit on remote Windows XP machines and are also written in C++. These clients must remain unchanged, hence I must implement the interfaces on new .NET objects. This has been done, and is working successfully regarding the implementation of the interfaces, and all of the calls are correctly being made from the old clients to the new .NET objects. However, I'm having problems obtaining the

hresult from IMbnInterfaceManager::GetInterfaces when no MBN device exists

对着背影说爱祢 提交于 2020-01-03 15:57:39
问题 I have the following code working in Windows 7: MbnInterfaceManager mbnInfMgr = new MbnInterfaceManager(); IMbnInterfaceManager mbnInfMgrInterface = mbnInfMgr as IMbnInterfaceManager; if (mbnInfMgrInterface != null) { IMbnInterface[] mobileInterfaces = mbnInfMgrInterface.GetInterfaces() as IMbnInterface[]; } No problems when the MBN device exists but when an MBN device doesn't exist I get the following exception in the call to GetInterfaces(): {System.Runtime.InteropServices.COMException

How to Register a Type Library without RegAsm.exe

房东的猫 提交于 2020-01-03 15:16:18
问题 I want to know if it's possible to register a type library without using the RegAsm tool. Here is my situation, which will hopefully explain why I want to do this: I'm developing an assembly in .NET that will provide some modern functionality for our older VB6 applications. I have successfully registered the assembly and the type library on my development machine using RegAsm like so: regasm.exe MyAssembly.dll /tlb /codebase The above command generates the type library (MyAssembly.tlb) and

“The public struct contains one or more non-public fields that will be exported” - but there are no fields?

别说谁变了你拦得住时间么 提交于 2020-01-03 05:26:06
问题 I have the struct below which is being compiled for COM interop. I get the following build warning: warning : Type library exporter warning processing 'MyNamespace.MyStruct.k__BackingField, MyAssemblyName'. Warning: The public struct contains one or more non-public fields that will be exported . But I don't see what it is referring to - there are no non-public fields nor fields at all . Maybe the compiler is generating something I can't see? What does this warning mean, and what if anything

Can a managed ref-class directly implement a COM interface?

社会主义新天地 提交于 2020-01-03 02:54:17
问题 Is there a built-in way to allow a managed ref-class to implement and expose a COM inerface that is safely callable from native code? Looking at the C# side, this is easily done by decorating the target interface with the proper COM-interop attributes, for example: Native Interface interface ISampleGrabberCB: public IUnknown { virtual STDMETHODIMP SampleCB( double SampleTime, IMediaSample *pSample ) = 0; virtual STDMETHODIMP BufferCB( double SampleTime, BYTE *pBuffer, long BufferLen ) = 0; };

How should I declare a Microsoft.Office.Interop.Excel.Worksheet so I can close it in C#?

天涯浪子 提交于 2020-01-02 20:18:08
问题 I am having a hard time making sure my COM objects are closing so I am not leaving an EXCEL.EXE process running in the background. I have learned that the double dot and chaining of declarations is bad as this could leave COM objects hanging around. Does anyone know how to fix this line of code so I can properly close and release the worksheet COM object? worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Sheets[strName]; EDIT: I have tried using app.Quit() when I am done

How to import a tlb and a namespace in c++ at runtime when some condition meets?

爱⌒轻易说出口 提交于 2020-01-02 18:34:33
问题 Generally we import a tlb file at the starting of the program like #include < stdio.h > #import " sql.tlb " But i need to import a tlb file when certain condition meets in the middle of the program how can i do this. to load dll there is LoadLibrary() but to load tlb can i use LoadLibrary() . Since tlb is generated by using .dll? 回答1: You can load a type library at runtime using LoadTypeLib. ITypeLib *ptlib; LoadTypeLib("sql.tlb", &ptlib); What you do then with ptlib is kind of up in the air

What is the equivalent of _bstr_t in C#

寵の児 提交于 2020-01-02 12:20:49
问题 I am working on a project where I need to convert C++ code to C#. I came across _bstr_t in the code I would like to know how the equivalent in C#. 回答1: The _bstr_t class is a wrapper for the BSTR type. This is a string in OLE Automation that is standardized across languages. That said, the equivalent type in .NET is a System.String. The key is when interacting with it (or defining your interfaces for COM interop in .NET code), you'll want to use the MarshalAsAttribute with a value from the