com

How could a member method delete the object?

柔情痞子 提交于 2019-12-05 08:51:44
I am currently studying COM and the following code confused me. STDMETHODIMP _(ULONG) ComCar::Release() { if(--m_refCount==0) delete this; // how could this "suicide" deletion be possible? return m_refCount; } I am wondering how could it be possible to delete an object instance within its member method? So I made the following experiment: class A { public: void Suicide(void); void Echo(void); char name; }; void A::Echo(void) { ::printf("echo = %c\n",name); } void A::Suicide(void) { delete this; } int main(void) { A a; a.name='a'; a.Suicide(); //failed } And the execution does failed at a

Programmatically determine if a COM library (.DLL) is installed

柔情痞子 提交于 2019-12-05 08:46:36
Is there a programmatic way in C# to determine whether a particular COM DLL has been installed? Or is this a matter of scanning the registry for the classId? What I usually did (and would do, if I needed this again) is try to create an object instance of a class you know is in the COM library - either by ProgID or GUID - and checking for failure. Try and create it, and handle the error if not. Under Win32 CoCreateInstance will return REGDB_E_CLASSNOTREG if not installed (including, IIRC, if registered but the dll/exe implementing it is then deleted). Under .NET the generated COM interop

How do you efficiently copy BSTR to wchar_t[]?

北城以北 提交于 2019-12-05 08:31:55
I have a BSTR object that I would like to convert to copy to a wchar__t object. The tricky thing is the length of the BSTR object could be anywhere from a few kilobytes to a few hundred kilobytes. Is there an efficient way of copying the data across? I know I could just declare a wchar_t array and alway allocate the maximum possible data it would ever need to hold. However, this would mean allocating hundreds of kilobytes of data for something that potentially might only require a few kilobytes. Any suggestions? Euro Micelli First, you might not actually have to do anything at all, if all you

Microsoft objects, the Release() functions return value?

怎甘沉沦 提交于 2019-12-05 08:29:51
I'm curious because I couldn't find out about this on MSDN. I've found the Release() function is present in various COM objects which I'm obviously supposed to use for deleting pointers. But I'm not sure what does it return exactly? I used to think it would return the number of references which still exist to the object remaining, therefore something like: while( pointer->Release() > 0 ); Would obviously release all references to that pointer? Or am I not seeing something? *note I'm talking about this from the concept of the IDirect3DTexture9::Release() function Your theory is true. COM memory

In what order should one release COM objects and garbage collect?

天涯浪子 提交于 2019-12-05 07:55:51
There are lots of questions on SO regarding the releasing COM objects and garbage collection but nothing I could find that address this question specifically. When releasing COM objects (specifically Excel Interop in this case), in what order should I be releasing the reference and calling garbage collection? In some places (such as here ) I have seen this: Marshall.FinalReleaseComObject(obj); GC.Collect(); GC.WaitForPendingFinalizers(); And in others (such as here ) this: GC.Collect(); GC.WaitForPendingFinalizers(); Marshall.FinalReleaseComObject(obj); Or doesn't it matter and I'm worrying

Determining the COM object blocking finalizer

 ̄綄美尐妖づ 提交于 2019-12-05 07:52:42
We have a .NET background processing application (console app) that executes some arbitrary workloads (basically internal users supply .NET DLLs implementing "Execute" interface). Background processing application then loads the dll via reflection and executes it. One of the supplied DLLs apparently has a COM object in it which is not properly disposed (likely). As the processing time is quite long, AND we have COM objects created on the main thread and not disposed properly, this causes a Finalizer Thread to be blocked, which subsequently causes the process to accumulate a significant amount

ASP.NET session and storing objects that use COM interop

泪湿孤枕 提交于 2019-12-05 07:41:26
问题 I'm working on an asp.net web site. We have to use com interop to interact with legacy vb6 activex components. The components in many cases rely on receiving a context object (which is itself a vb6 activex component) as a parameter. The context object is fairly costly to construct. Therefore one idea is that a context object is constructed once and stored in asp.net session. However, if this object is just a .net wrapper around an activex component, is it wise or advisible to persist such an

COMException in C# when hooking into event

拈花ヽ惹草 提交于 2019-12-05 07:32:51
I am receiving a COM Exception when trying to hook into an event on a COM Object. Here is the code I am trying to execute. COMClass a = IComClass as ComClass; a.SomeEvent += new SomeEvent_EventHandler(MethodNameHere); Line two throws an exception of type COMException with the following information: System.Runtime.InteropServices.COMException was caught Message="Exception from HRESULT: 0x80040202" Source="mscorlib" ErrorCode=-2147220990 StackTrace: at System.Runtime.InteropServices.ComTypes.IConnectionPoint.Advise(Object pUnkSink, Int32& pdwCookie) Does anyone have any ideas why I am unable to

COM Interop registration

大憨熊 提交于 2019-12-05 07:31:49
I have a .NET assembly which I am exposing to COM . The assembly has two public interfaces and one public class. When I build the assembly I get this warning: (assemblyName.dll) does not contain any types that can be registered for COM Interop. My assembly information includes the following line. [assembly: ComVisible(true)] Most people having this problem on the web, that I have found, fixed it with the above line in their assembly information. This has not helped for me. I also tried adding [ComVisible(true)] to the class and interface definitions, and it also did not help. ComVisible

How do I load a typelib to parse it in C#?

六月ゝ 毕业季﹏ 提交于 2019-12-05 07:14:35
In unmanaged code I can use LoadTypeLib() to obtain an ITypeLib* pointer and use that to look into the typelib to find what interfaces it contains. There is System.Runtime.InteropServices.ComTypes.ITypeLib interface in C# but I can't find an equivalent to LoadTypeLib() function. How do I load a typelib and obtain an ITypeLib reference in C#? Copied straight from System.Design.NativeMethods, Reflector is useful: [DllImport("oleaut32.dll", PreserveSig=false)] public static extern ITypeLib LoadTypeLib([In, MarshalAs(UnmanagedType.LPWStr)] string typelib); 来源: https://stackoverflow.com/questions