Re: Pass arguments with IDispatch.Invoke
- From: "Alexander Nickolov" <agnickolov@xxxxxxxx>
- Date: Fri, 1 Sep 2006 11:18:56 -0700
I'm not familiar with C# and COM Interop so can't comment...
The right group for this kind of questions is:
microsoft.public.dotnet.framework.interop
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@xxxxxxxx
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
<brosembob@xxxxxxxxx> wrote in message
news:1157122628.723159.14970@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thanks guys for your help.
Regarding the solution that I found previously; Is it Ok to do it this
way?
// Following is the C# method
[MethodImpl(MethodImplOptions.Synchronized)]
public int GetVersion(IntPtr LibraryVersion)
{
//LibraryVersion is the pointer in unmanaged memory
MY_VERSION v =
(MY_VERSION)Marshal.PtrToStructure(LibraryVersion,typeof (MY_VERSION));
v.major = 1;
v.minor = 2;
v.patchLevel = 3;
v.build = 4;
Marshal.StructureToPtr(v, LibraryVersion, true);
}
I'm getting pointer to the structure from C, and using Marshalling
populating it and send it back.
The structure seems fine/populated on the C side after.
Thanks,
Bob
Alexander Nickolov wrote:
Additionally, a struct cannot be returned as an [out, retval]
parameter. You must use [in, out], pass a struct at the caller
and modify it at the callee. The problem is a VARIANT does
_not_ own the struct it points to (it's like VT_BYREF in this
regard). Thus it cannot be properly disposed of at the marshaling
layer.
This is briefly mentioned at the FAQ article Igor already pointed
you to:
http://vcfaq.mvps.org/com/4.htm
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@xxxxxxxx
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
"Igor Tandetnik" <itandetnik@xxxxxxxx> wrote in message
news:OrNJ5mHzGHA.1292@xxxxxxxxxxxxxxxxxxxxxxx
brosembob@xxxxxxxxx wrote:
Thanks for your reply and help. I'm not quite sure I understand the
example.
long value; // the [out] value will end up here
VARIANT v;
V_VT(&v) = VT_I4 | VT_BYREF;
V_I4REF(&v) = &value;
// pack v into DISPPARAMS
What is the value? Is it pointer to my structute?
I gave an example for packing [in, out] long parameter. For UDT,
'value'
would be of that UDT type, and you would need to set up VT_RECORD |
VT_BYREF variant.
However, as Alexander pointed out, return values ([out, retval]
parameters) work completely differently. You just pass a pointer to an
empty VARIANT as varResult parameter to Invoke (comes right after
DISPPARAMS), and when Invoke returns the variant is filled with data.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
.
- References:
- Re: Pass arguments with IDispatch.Invoke
- From: brosembob
- Re: Pass arguments with IDispatch.Invoke
- Prev by Date: Re: Migration libraries from NT to 2000
- Next by Date: Re: VBA References DIalog
- Previous by thread: Re: Pass arguments with IDispatch.Invoke
- Next by thread: Re: Migration libraries from NT to 2000
- Index(es):
Relevant Pages
|