com

How to best convert CString to BSTR to pass it as an “in” parameter into a COM method?

六眼飞鱼酱① 提交于 2019-12-01 03:41:04
I need to convert a CString instance into a properly allocated BSTR and pass that BSTR into a COM method. To have code that compiles and works indentically for both ANSI and Unicode I use CString::AllocSysString() to convert whatever format CString to a Unicode BSTR. Since noone owns the returned BSTR I need to take care of it and release it after the call is done in the most exception-safe manner posible and with as little code as possible. Currently I use ATL::CComBSTR for lifetime management: ATL::CComBSTR converted; converted.Attach( sourceString.AllocSysString() ); //simply attaches to

Convention for passing BSTRs into COM functions from C# (COM interop)

﹥>﹥吖頭↗ 提交于 2019-12-01 03:33:22
I am writing writing an API in COM in C++, and also writing a program which consumes this API in C#. My question is about BSTR memory management semantics when passing BSTRs into COM functions. Say my IDL looks like: HRESULT SomeFunction([in] BSTR input); Currently this function is implemented like this: HRESULT SomeFunction(BSTR input) { // Do stuff ..., then: SysFreeString(input); } When I call it from C# with something like SomeFunction(myString) , will C# generate something like this (pseudocode): myString = SysAllocString("string"); SomeFunction(myString); Or rather like this: myString =

IntelliSense in custom COM classes in VBA

喜欢而已 提交于 2019-12-01 03:27:01
Is there a way to get IntelliSense in own built COM classes in VBA? E.g. in the example below I would like to get "Number" showing up, whenever I press on the dot (or ctrl+space for shortcut): I suppose, if this is somehow resolved, I would also get some info concerning the public functions of the objects here: Thus, what are the suggestions? Suggestion 1 : Simple example could look like this. c# class library named IntellisenseDemo code using System; using System.Runtime.InteropServices; namespace IntellisenseDemo { [ComVisible(true)] [Guid("41B3F5BC-A52B-4AED-90A0-F48BC8A391F1")]

Calling Shell32.dll from .NET Windows Service

百般思念 提交于 2019-12-01 03:23:51
I have a .NET 4.0 library that uses Shell32 and Folder.GetDetailsOf() to get metadata from WTV files. I have used it successfully with Console and Windows Forms apps without issue. But for some reason, when calling the component from a .NET 4.0 Windows Service, the call to initiate the Shell class causes a COM error. The code that fails inside the library: Shell32.Shell shell = new Shell(); The error: Unable to cast COM object of type 'System.__ComObject' to interface type 'Shell32.Shell'. This operation failed because the QueryInterface call on the COM component for the interface with IID '

Read Outlook .msg File

六眼飞鱼酱① 提交于 2019-12-01 03:18:56
I believe that the only way to read an Outlook .msg file (in order to extra metadata like subject, attachments etc), is to use the Outlook API - the Application.Session.OpenSharedItem() method. If this is the case, then I am looking for way to run this code on our application server, which doesn't have MS OFfice or MS Outlook installed. I'm getting the error System.ArgumentException: progId not found. Outlook.Application Which of course is due to the absence of the Outlook application. Is there any way to install just a DLL or something in order to get the OpenSharedItem method to work? I don

How to iterate through SAFEARRAY **

六眼飞鱼酱① 提交于 2019-12-01 03:16:21
how to iterate through C++ safearray pointer to pointer and access its elements. I tried to replicate the solution posted by Lim Bio Liong http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/022dba14-9abf-4872-9f43-f4fc05bd2602 but the strangest thing is that the IDL method signature comes out to be HRESULT __stdcall GetTestStructArray([out] SAFEARRAY ** test_struct_array); instead of HRESULT __stdcall GetTestStructArray([out] SAFEARRAY(TestStruct)* test_struct_array); Any ideas? thanks in advance Safearrays are created with SafeArrayCreate or SafeArrayCreateVector , but as you ask

How to Extract TypeLib from a COM exe on Command Line

旧巷老猫 提交于 2019-12-01 03:14:41
问题 I've recently had need to produce an interop assembly. After some googling I discovered tlbimp.exe . My next problem was that my COM library did not come with a .tlb file. Further googling revealed that the type lib is often included as a resource in an exe/dll. Sure enough, opening the exe in VS2010 revealed it's type lib and a right-click later I had a tlb file to use with tlbimp . Awesome. However this is not a very nice process. Should I need to do this in the future, is there a way of

ATL simple object wizard - “Object Xxx already exists” error

对着背影说爱祢 提交于 2019-12-01 03:14:39
问题 I am attempting to create a new COM object in my DLL using the ATL Simple Object Wizard in Visual Studio 2005. I enter the short name for the object, and all of the other fields are derived. However, when I click Next in the wizard, the following error message comes up: Object 'IXxxInterfaceName' already exists I have searched my entire solution for all references to IXxxInterfaceName and can't see it defined anywhere. How is the wizard determining that it exists already? 回答1: I never found

Retrieving the COM class factory for component with CLSID {XXXX} failed due to the following error: 80080005

…衆ロ難τιáo~ 提交于 2019-12-01 03:13:17
What is the troubleshooting process for the "Retrieving the COM class factory for component with CLSID {XXXX} failed due to the following error: 80080005" errors in .Net? To clarify: I am getting this at runtime, on my XP machine, with client being .net code running under admin account. {XXXX} refers to one of our in-house COM components. From what I understand, 0x80080005 refers to "permission denied", but where do I go to check/change the permissions? Or am I completely wrong here, and the error is coming from the component itself, and not out of Windows COM subsystem? Seems to be a rather

Active tab ignored by InternetExplorer COM object for IE 8

99封情书 提交于 2019-12-01 03:10:38
问题 This is web single sign on code that runs on a .net 3.5 winform. The code runs fine for ie6 or ie8 as long as ie8 only has one tab open. The problem is that if the user opens a new tab (tab 2,3,etc.) and navigates to a web site (web form internal in the organization) the below code will be executed but the ie COM automation object will return the HTMLDocument for the first tab (Tab 1) even though tab 2 is the active tab. I can't find any IE tab references in the InternetExplorer or