Re: Problem Sending VB6 Byte Array to C#...help?
- From: intrepid_dw@xxxxxxxxxxx
- Date: 6 Oct 2005 17:34:52 -0700
Kevin:
Thanks again. I greatly appreciate the effort.
Please know that I understand the difference between pointers to arrays
and arrays and the like...I've been hacking around in all these things
for longer than I care to mention, from C to C++ and VB6 and .NET and
too many others, and have tried to mentor many a coworker on them over
the years :). This is just a very narrow problem tied to this
particular interop situation that made me wonder about typelib
generation for COM Interop DLL's.
I'm pretty sure that, based on your response, that I'm just doing a
lousy job of explaining my problem - and that's entirely my fault. I'm
more than a bit embarrassed to think how dense you must think I am to
have had to explain pointers...<gulp>....
Let me reset things a bit, along with some updated info. First, let me
offer that I fixed the original problem of VB6 complaining about the
"automation type unsupported by Visual Basic." In fixing *that*
problem, it ALSO fixed the way .NET generated the type library for the
Interop assembly. Those issues dovetail in a way that probably explains
the whole problem better than I have so far.
Here's how I got there. In thinking about the typelib for the COM
interop method, I realized what VB was complaining about; it
essentially saw a declaration requesting that a SafeArray be passed
ByVal, which almost certainly scrambled VB's brain. It can only pass
them by reference. That implies that the method signature needed to be
SAFEARRAY(unsigned char)*. I needed a "control" to verify the theory,
and that led me to building the throwaway VB dll that expected a byte
array parameter so I could inspect *its* type library...Sure enough,
the type library for a VB6 DLL expecting a byte array parameter ends up
looking like
HRESULT MyFunction([in, out] SAFEARRAY(unsigned char)* MyArray);
WIth that in hand, that led me to the fix on the .NET side.......
The fix was to change the method parameter signature in the C# Interop
DLL from "byte[]" to "ref byte[]". This had the downstream effect of
changing the method signature in the COM type library to
SAFEARRAY(unsigned char)*, which is *precisely* what I expected/needed.
When I call the function from VB, it now works perfectly.
A different way of seeing my problem can be illustrated in the
following C# example:
void SomeMethod(System.Byte[] lotsabytes, ref byte[] morebytes);
If marked for COM Interop, the type library for SomeMethod will look
something like:
HRESULT SomeMethod([in] SAFEARRAY(unsigned char) lotsabytes, [in]
SAFEARRAY(unsigned char)* morebytes)
VB can't pass an array by value, as implied by the first declaration,
but it can pass the array by reference. The latter declaration is
consistent with how .NET writes the COM Interop type library for a
function *returning* a byte array, but not for a *parameter*. That's
what had me puzzled; declarations for the same type were being written
two different ways. Changing the declaration of the array to "ref"
resolved the problem, and everything now works the way I
intended/expected.
I realize you're probably tired of my rambling explanations, but
hopefully THIS version of the explanation was an approach from a
different angle that clarified what I was trying to do. I appreciate
your patient and polite help nonetheless, and I hope you don't think
I'm a *complete* idiot. :)
David
.
- Prev by Date: Re: What is manage?
- Next by Date: Re: Problem Sending VB6 Byte Array to C#...help?
- Previous by thread: Windows service operation throws error: Operation is not valid due to the current state of the object.
- Next by thread: Re: Problem Sending VB6 Byte Array to C#...help?
- Index(es):
Relevant Pages
|
Loading