473,395 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Need help translating COM library

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
Nov 16 '05 #1
3 1838
Gabe,

Are you aware that VS.Net will automatically create the interop's required
for your to call COM objects from .Net code?

http://msdn.microsoft.com/library/de...AsAssembly.asp
[beware line wraps]

Dan.
"Gabe Covert" <ga********@earthlink.net> wrote in message
news:EI*****************@newsread2.news.atl.earthl ink.net...
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

Nov 16 '05 #2


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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
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.
"Gabe Covert" <ga**@thecoverts.net> wrote in message
news:uz****************@TK2MSFTNGP10.phx.gbl...


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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Davis Marques | last post by:
hi; I'm translating some PHP scripts to Python and have hit a roadblock with a for statement. If someone could explain to me how one should translate the multiple increment, evaluations, etc....
2
by: calin.hanchevici | last post by:
Hi all, I have a C++ library I call from python. The problem is I have c++ exceptions that i want to be translated to python. I want to be able to do stuff like: try: my_cpp_function() except...
1
by: Michael Friendly | last post by:
I have a LaTeX document describing a long list of items that I want to translate to XML to treat these as a database. I've written a perl script to do the basic translation, and a basic DTD file,...
0
by: winthux | last post by:
I'm trying to use the library in c++ by using but it requires some specific structures and macros: #define gg_common_head(x) \ int fd; /* podgl?dany deskryptor */ \ int check; /*...
9
by: Hugo Amselschlag | last post by:
Hi there, I've implemented a local system hook to suppress certain windows beeing displayed by the axWebbrowser control. Now I need some more information before I can decide, whether to suppress...
1
by: timn | last post by:
Translating Access SQL queries into SQL subqueries. -------------------------------------------------------------------------------- I have a query in Access that uses a subquery, I would like...
3
by: stax76 | last post by:
Hello, can anybody tell me what it would look like in C++? byte bRawData = new byte; int pRawData = buffer.ToInt32() + Marshal.SizeOf(typeof(RAWINPUT)) + 1; // buffer is of type IntPtr...
5
by: GHUM | last post by:
hello, in my application I am using hSem = win32event.CreateSemaphore (None, 1, 1,"stringincludinginterfaceandport") rt=win32event.WaitForSingleObject (hSem, 0) if rt !=...
1
by: trihaitran | last post by:
Hi I am new to Ruby from Python and am still learning some stuff. I have a Ruby program that uses the mechanize library to connect to a Web site and authenticate with a username and password. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.