Need help translating COM library

G

Gabe Covert

I'm a new C# developer, and am developing an application which will utilize
a COM library from a third party. I have two following SDK calls from the
3rd-party SDK which I can't get to work under C#:

SDK declaration:

VARIANT_BOOL ReadMemory(unsigned char* Data, long DataSize);

tlbimp result:

public abstract new System.Boolean ReadMemory (System.Byte Data,
System.Int32 DataSize )

il result:
..method public hidebysig newslot virtual
instance bool ReadMemory([in] unsigned int8& Data,
[in] int32 DataSize) runtime managed
internalcall
{
.override XXX::ReadMemory
} // end of method XXX::ReadMemory

Errors:code.cs(132): The best overloaded method match for
'XXX.ReadMemory(ref byte, int)' has some invalid argumentscode.cs(132):
Argument '1': cannot convert from 'byte[]' to 'ref byte'
SDK Declaration:

VARIANT_BOOL CreateAllTemplates(IUnknown* pIDibImage, IUnknown*
pIFacePosition, VARIANT* FullTemplate, VARIANT* StoredNormalizer, VARIANT*
VectorTemplate, double *dGenderScore)

tlbimp result:
public abstract new System.Boolean CreateAllTemplates (System.Object
pIDibImage, System.Object pIFacePosition, System.Object FullTemplate,
System.Object StoredNormalizer, System.Object VectorTemplate, System.Double
fGenderScore)

il result:
..method public hidebysig newslot virtual
instance bool CreateAllTemplates([in] object marshal(
iunknown) pIDibImage,
[in] object marshal(
iunknown) pIFacePosition,
[out] object& marshal(
struct) FullTemplate,
[out] object& marshal(
struct) StoredNormalizer,
[out] object& marshal(
struct) VectorTemplate,
[out] float64& fGenderScore)
runtime managed internalcall
{
.override XXX::CreateAllTemplates
} // end of method XXX::CreateAllTemplatesErrors:Code.cs(140): The best
overloaded method match for 'XXX.CreateAllTemplates(object, object, out
object, out object, out object, out double)' has some invalid
argumentsCode.cs(140): Argument '3': cannot convert from
'System.Collections.ArrayList' to 'out object'Code.cs(140): Argument '4':
cannot convert from 'System.Collections.ArrayList' to 'out
object'Code.cs(140): Argument '5': cannot convert from
'System.Collections.ArrayList' to 'out object'Code.cs(140): A property or
indexer may not be passed as an out or ref parameter Any hints as to how I
can get these calls to work?Thanks!Gabe
 
G

Gabe Covert

I did the conversion, with tlbimp, but the parameters translated into
types that I'm not sure how I can use...

For example, the CreateAllTemplates has the followinf declaration in the
C++-based SDK:

VARIANT_BOOL CreateAllTemplates(IUnknown* pIDibImage, IUnknown*
pIFacePosition, VARIANT* FullTemplate, VARIANT* StoredNormalizer,
VARIANT* VectorTemplate, double *dGenderScore)

The tlbimp interop is:
public abstract new System.Boolean CreateAllTemplates (System.Object
pIDibImage, System.Object pIFacePosition, System.Object FullTemplate,
System.Object StoredNormalizer, System.Object VectorTemplate,
System.Double fGenderScore)

How do I represent the FullTemplate parameter in C#, so that it passes
into the interop as an OBject, and then passes to the COM call as a
VARIANT*?

Gabe
 
D

Dan Bass

Hmm, I'm not sure, never had to do it.

One problem straight away is that your C++ function declaration is passing
in parameters which are pointers (like the double Gender score), yet the
tlbimp seems to have it as a value type. When (If) the method then changes
the object that it has been given a pointer to, this wouldn't be reflected
in the System.Double variable that was passed in.

http://support.microsoft.com/kb/317030/EN-US/
This article suggests you simply need to do an implicit cast into the type
you want from the variant. Presumably the VARIANT pointer has some sort of
extraction that pulls the data from it, then puts it in a general object,
which can then be used. Again, these are "ref'ed" so I'm not sure how any
values are passed back out of the method.
I'd suggest creating blank objects ( EG. System.Object dibImageObj = new
Object() ) for each parameter except for the GenderScore double, which can
be a double typed variable, then pass these into the method. Once it's been
called, cast them into the type you'd expect them to be in to access to get
the data you need.

If you have no more luck, try posting in the group:
microsoft.public.dotnet.framework.interop

Thanks.

Daniel.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top