T
Thomas Lee3
Guest
Hi All,
I am trying to use a C++ unmanaged COM component (ATL). I am trying to call one method only and I get an exception.
The com interface is a simple one function interface.
interface IContactItems : IDispatch
{
[id(1)] HRESULT AddContact([in] IDispatch* pFolderDisp, [in] VARIANT_BOOL isBusiness,
[in] BSTR Firstname, [in] BSTR Lastname, [in] BSTR Email, [in] BSTR Company,
[in] BSTR JobTitle, [in] BSTR Department, [in] BSTR Street, [in] BSTR Street2,
[in] BSTR City, [in] BSTR State, [in] BSTR PostalCode, [in] BSTR Phone,
[in] BSTR Fax, [in] BSTR Country, [in] BSTR MobilePhone, [out, retval] VARIANT_BOOL* success);
};
At first I tried importing the reference and embedding the Interop types and I get the following error.
"error CS1752: Interop type 'ContactItemsClass' cannot be embedded. Use the applicable interface instead."
So I then set the "Embedded Interop Types" to false.
Then I tried instantiating the object from the reference and calling the method.
ContactItemsClass com = new ContactItemsClass();
com.AddContact(...);
Which gives me the following error, which may be the BSTR type, or I am missing some fundemental step.
System.AccessViolationException
HResult=0x80004003
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source=<Cannot evaluate the exception source>
StackTrace:
I am using Visual Studio 2019, I seem not to remember having these issues when I did this a long time ago in VS 2008/2010.
So my questions are:
1) what is the proper way to import this COM component?
2) What is the proper way to release this component once I am done using it?
Thanks,
Tom
Continue reading...
I am trying to use a C++ unmanaged COM component (ATL). I am trying to call one method only and I get an exception.
The com interface is a simple one function interface.
interface IContactItems : IDispatch
{
[id(1)] HRESULT AddContact([in] IDispatch* pFolderDisp, [in] VARIANT_BOOL isBusiness,
[in] BSTR Firstname, [in] BSTR Lastname, [in] BSTR Email, [in] BSTR Company,
[in] BSTR JobTitle, [in] BSTR Department, [in] BSTR Street, [in] BSTR Street2,
[in] BSTR City, [in] BSTR State, [in] BSTR PostalCode, [in] BSTR Phone,
[in] BSTR Fax, [in] BSTR Country, [in] BSTR MobilePhone, [out, retval] VARIANT_BOOL* success);
};
At first I tried importing the reference and embedding the Interop types and I get the following error.
"error CS1752: Interop type 'ContactItemsClass' cannot be embedded. Use the applicable interface instead."
So I then set the "Embedded Interop Types" to false.
Then I tried instantiating the object from the reference and calling the method.
ContactItemsClass com = new ContactItemsClass();
com.AddContact(...);
Which gives me the following error, which may be the BSTR type, or I am missing some fundemental step.
System.AccessViolationException
HResult=0x80004003
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source=<Cannot evaluate the exception source>
StackTrace:
I am using Visual Studio 2019, I seem not to remember having these issues when I did this a long time ago in VS 2008/2010.
So my questions are:
1) what is the proper way to import this COM component?
2) What is the proper way to release this component once I am done using it?
Thanks,
Tom
Continue reading...