safearray

How to call a .NET COM method with an array from delphi using PSafeArray?

烈酒焚心 提交于 2019-12-14 03:23:04
问题 I have an .NET (4.0) interface which is implemented with a ServicedComponent COM+ class: interface DotNetIface { void MethodRef(var System.Guid guid); void MethodArray(System.Guid[] guids, params object[] parameters); void MethodCStyle([MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.Struct, SizeConst=5)]System.Guid[] guids); } Now I used the Delphi 2007 import wizard to import the type library, and as expected I get the following signatures: procedure MethodRef(var guid : TGuid);

Pointers to arrays stored as collection/dictionary items VBA

早过忘川 提交于 2019-12-12 13:26:22
问题 With variant arrays where each element is a double array I am able to do the following: Public Declare PtrSafe Sub CopyMemoryArray Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination() As Any, ByRef Source As Any, ByVal Length As Long) Sub test() Dim vntArr() as Variant Dim A() as Double Dim B() as Double Redim vntArr(1 to 10) Redim A(1 to 100, 1 to 200) vntArr(1) = A CopyMemoryArray B, ByVal VarPtr(vntArr(1)) + 8, PTR_LENGTH '4 or 8 'Do something ZeroMemoryArray B, PTR_LENGTH End Sub A

Sending and receiving arrays over COM

≯℡__Kan透↙ 提交于 2019-12-12 09:52:37
问题 What is the right way to receive and send arrays over COM? Here's my attempt so far: a safearray of doubles wrapped in a variant. //takes variant holding safearray of doubles //returns a similar variant having multipled every element by 2 STDMETHODIMP MyComClass::safearraytimestwo(VARIANT in, VARIANT* out) { CComSafeArray<double> sa_in; sa_in.Attach(*in.pparray); ULONG size = sa_in.GetCount(); CComSafeArray<double> *out_sa = new CComSafeArray<double>(size); for (long i=0;i<size;i++) out_sa-

SafeArrayPutElement method throws System.AccessViolationException

吃可爱长大的小学妹 提交于 2019-12-11 14:22:10
问题 I am trying to pass an array of ints from C# to C++/CLI. Here's my code: // SafeArrayTesting_PlusPlus.cpp #include "stdafx.h" #include <comdef.h> using namespace System; namespace SafeArrayTesting_PlusPlus { public ref class MyCppClass { public: MyCppClass(); ~MyCppClass(); void SetMyInts(array<int>^ myInts); }; MyCppClass::MyCppClass(){} MyCppClass::~MyCppClass(){} void MyCppClass::SetMyInts(array<int>^ myInts) { // Create safearray SAFEARRAY *safeArrayPointer; SAFEARRAYBOUND arrayDim[1]; //

Responsibility for memory deallocation in COM Interop

匆匆过客 提交于 2019-12-11 08:14:49
问题 I'm working on a C++ code consuming services provided by a .NET dll, which I'm accessing via COM Interop. I'm writing both the C++ and C# side. One of the methods that is exposed by the dll and is called from the C++, asks the dll to return an allocated byte array containing some information. After creating that method in my C# code, the .tlb generator exposed it as follows: HRESULT _stdcall DownloadData( [out] SAFEARRAY(unsigned char)* outputBuf); Testing has shown that when I send the

How can I marshall between XLOPER and VARIANT? [closed]

坚强是说给别人听的谎言 提交于 2019-12-06 07:01:59
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I'm working on an Excel plugin (XLL), which communicates with COM objects. So, I have to marshall between XLOPER and VARIANT. I've got most of this working, but arrays are definitely a pain. I need to support 1- and 2D arrays. I imagine someone has already had to deal with this before. What's the best way to

Sending and receiving arrays over COM

霸气de小男生 提交于 2019-12-05 23:22:07
What is the right way to receive and send arrays over COM? Here's my attempt so far: a safearray of doubles wrapped in a variant. //takes variant holding safearray of doubles //returns a similar variant having multipled every element by 2 STDMETHODIMP MyComClass::safearraytimestwo(VARIANT in, VARIANT* out) { CComSafeArray<double> sa_in; sa_in.Attach(*in.pparray); ULONG size = sa_in.GetCount(); CComSafeArray<double> *out_sa = new CComSafeArray<double>(size); for (long i=0;i<size;i++) out_sa->SetAt(i,sa_in[i]*2); out = new CComVariant(out_sa); return S_OK; } Problems: - currently compilation

How does one return a local CComSafeArray to a LPSAFEARRAY output parameter?

本秂侑毒 提交于 2019-12-05 16:07:55
问题 I have a COM function that should return a SafeArray via a LPSAFEARRAY* out parameter. The function creates the SafeArray using ATL's CComSafeArray template class. My naive implementation uses CComSafeArray<T>::Detach() in order to move ownership from the local variable to the output parameter: void foo(LPSAFEARRAY* psa) { CComSafeArray<VARIANT> ret; ret.Add(CComVariant(42)); *psa = ret.Detach(); } int main() { CComSafeArray<VARIANT> sa; foo(sa.GetSafeArrayPtr()); std::cout << sa[0].lVal <<

How can I marshall between XLOPER and VARIANT? [closed]

北战南征 提交于 2019-12-04 14:50:50
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I'm working on an Excel plugin (XLL), which communicates with COM objects. So, I have to marshall between XLOPER and VARIANT. I've got most of this working, but arrays are definitely a pain. I need to support 1- and 2D arrays. I imagine someone has already had to deal with this before. What's the best way to simplify dealing with VARIANT, SAFEARRAY, and XLOPER (and XLOPER12)? I had to hand-roll my own

How does one return a local CComSafeArray to a LPSAFEARRAY output parameter?

a 夏天 提交于 2019-12-04 02:31:59
I have a COM function that should return a SafeArray via a LPSAFEARRAY* out parameter. The function creates the SafeArray using ATL's CComSafeArray template class. My naive implementation uses CComSafeArray<T>::Detach() in order to move ownership from the local variable to the output parameter: void foo(LPSAFEARRAY* psa) { CComSafeArray<VARIANT> ret; ret.Add(CComVariant(42)); *psa = ret.Detach(); } int main() { CComSafeArray<VARIANT> sa; foo(sa.GetSafeArrayPtr()); std::cout << sa[0].lVal << std::endl; } The problem is that CComSafeArray::Detach() performs an Unlock operation so that when the