Google Answers Logo
View Question
 
Q: .Net LPArray : COM Client throws Exception ( No Answer,   1 Comment )
Question  
Subject: .Net LPArray : COM Client throws Exception
Category: Computers > Programming
Asked by: clearly-ga
List Price: $100.00
Posted: 18 Jun 2002 09:21 PDT
Expires: 25 Jun 2002 09:21 PDT
Question ID: 28516
I need to know how to properly marshal the data from my legacy app to
a /Net component. My legacy app uses the following IDL interface
definition:

interface IMyInterface2 : IUnknown
{
 HRESULT doit( [in, size_is(msgLength)]UCHAR* msg, [in] ULONG
msgLength );
};

When my legacy COM Client calls my .Net component that implements this
interface, an access violation (0xC0000005) exception is thrown. I've
tried everything and can not figure out why the exception is thrown in
the
COM Client.

Here is the COM Client:

#include "stdafx.h"
#include "IMyInterface2_h.h"
#include "IMyInterface2_i.c"

int _tmain(int argc, _TCHAR* argv[])
{
HRESULT hr = S_OK;
hr = ::CoInitialize( NULL );
CLSID rcid = { 0x5F850215, 0x7AC2, 0x48b8, { 0xA8, 0xCF, 0xA0, 0x08,
0xF7, 0x33, 0xD6, 0x61 } };

{
CComPtr<IMyInterface2> iMyInterface2;
hr = iMyInterface2.CoCreateInstance( rcid, NULL, CLSCTX_INPROC_SERVER
);
UCHAR* pBytes = (UCHAR*)::CoTaskMemAlloc( 20 );
::ZeroMemory( pBytes, 20 );
iMyInterface2->doit( pBytes, 20 );
}
::CoUninitialize();

return 0;
}

The exception is thrown on the statement:
iMyInterface2->doit( pBytes, 20 );
The call never gets to the .Net component's method

And here is the .Net service component. The .Net component must be
copied in the same directory as the COM client.

using System;
using System.Runtime.InteropServices;

namespace ComSrv
{
 [GuidAttribute("5F850215-7AC2-48b8-A8CF-A008F733D661")]
 public class MyClass : IMyInterface2
 {
  public void doit( byte[] msg, ulong msgLength )
  {
  }
 }

 [ComImport]
 [GuidAttribute("B55AFAEB-BC7D-4ca9-8065-F9A45FE378B6")]
 [InterfaceTypeAttribute 
ComInterfaceType.InterfaceIsIUnknown)]
 public interface IMyInterface2
 {
  void doit(
   [In, MarshalAs( UnmanagedType.LPArray, 
SizeParamIndex=1, ArraySubType=UnmanagedType.U1 )]byte[] 
msg, [In]ulong msgLength );
 }
}

Request for Question Clarification by studboy-ga on 18 Jun 2002 12:29 PDT
I am assuming you did perform the perform the following three steps 
on the .NET component/assemby before you made the call--am I correct?

tlbexp ...

regasm ...

gacutil ...

Clarification of Question by clearly-ga on 18 Jun 2002 14:08 PDT
tlbexp:no
Regasm:yes
GAC:no

As the message states, I don't need to put it in the GAC because I put
the .Net component in the same directory. The component loads fine:
the CoCreateInstance call returns S_OK. In fact, I can call other
methods with different IDL signatures. The problem I am having is
specifically with a method that uses LPArray.

Clarification of Question by clearly-ga on 18 Jun 2002 14:15 PDT
Let me clarify that $100 is the max "Google Answers" will allow. I
would be happy to pay $400 to the first person who has a satisfactory
solution that will work with my legacy application.

Clarification of Question by clearly-ga on 19 Jun 2002 19:43 PDT
The question has been answered by someone else outside of Google
Answers. At this point, I will not award the List Price to anyone.
Answer  
There is no answer at this time.

Comments  
Subject: Re: .Net LPArray : COM Client throws Exception
From: activescott-ga on 19 Jun 2002 21:34 PDT
 
Can you please post the solution so we know.  I'm curious as to if the
msgLength argument on the doit method (a c++ ULONG) should have ben
marshaled as a uint(System.UInt32) instead of a ulong (System.Int64).

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy