473,785 Members | 2,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(unsi gned 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.c s(132):
Argument '1': cannot convert from 'byte[]' to 'ref byte'
SDK Declaration:

VARIANT_BOOL CreateAllTempla tes(IUnknown* pIDibImage, IUnknown*
pIFacePosition, VARIANT* FullTemplate, VARIANT* StoredNormalize r, VARIANT*
VectorTemplate, double *dGenderScore)

tlbimp result:
public abstract new System.Boolean CreateAllTempla tes (System.Object
pIDibImage, System.Object pIFacePosition, System.Object FullTemplate,
System.Object StoredNormalize r, System.Object VectorTemplate, System.Double
fGenderScore)

il result:
..method public hidebysig newslot virtual
instance bool CreateAllTempla tes([in] object marshal(
iunknown) pIDibImage,
[in] object marshal(
iunknown) pIFacePosition,
[out] object& marshal(
struct) FullTemplate,
[out] object& marshal(
struct) StoredNormalize r,
[out] object& marshal(
struct) VectorTemplate,
[out] float64& fGenderScore)
runtime managed internalcall
{
.override XXX::CreateAllT emplates
} // end of method XXX::CreateAllT emplatesErrors: Code.cs(140): The best
overloaded method match for 'XXX.CreateAllT emplates(object , object, out
object, out object, out object, out double)' has some invalid
argumentsCode.c s(140): Argument '3': cannot convert from
'System.Collect ions.ArrayList' to 'out object'Code.cs( 140): Argument '4':
cannot convert from 'System.Collect ions.ArrayList' to 'out
object'Code.cs( 140): Argument '5': cannot convert from
'System.Collect ions.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!Gab e
Nov 16 '05 #1
3 1855
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********@ear thlink.net> wrote in message
news:EI******** *********@newsr ead2.news.atl.e arthlink.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(unsi gned 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.c s(132):
Argument '1': cannot convert from 'byte[]' to 'ref byte'
SDK Declaration:

VARIANT_BOOL CreateAllTempla tes(IUnknown* pIDibImage, IUnknown*
pIFacePosition, VARIANT* FullTemplate, VARIANT* StoredNormalize r, VARIANT*
VectorTemplate, double *dGenderScore)

tlbimp result:
public abstract new System.Boolean CreateAllTempla tes (System.Object
pIDibImage, System.Object pIFacePosition, System.Object FullTemplate,
System.Object StoredNormalize r, System.Object VectorTemplate,
System.Double fGenderScore)

il result:
.method public hidebysig newslot virtual
instance bool CreateAllTempla tes([in] object marshal(
iunknown) pIDibImage,
[in] object marshal(
iunknown) pIFacePosition,
[out] object& marshal(
struct) FullTemplate,
[out] object& marshal(
struct) StoredNormalize r,
[out] object& marshal(
struct) VectorTemplate,
[out] float64& fGenderScore)
runtime managed internalcall
{
.override XXX::CreateAllT emplates
} // end of method XXX::CreateAllT emplatesErrors: Code.cs(140): The best
overloaded method match for 'XXX.CreateAllT emplates(object , object, out
object, out object, out object, out double)' has some invalid
argumentsCode.c s(140): Argument '3': cannot convert from
'System.Collect ions.ArrayList' to 'out object'Code.cs( 140): Argument '4':
cannot convert from 'System.Collect ions.ArrayList' to 'out
object'Code.cs( 140): Argument '5': cannot convert from
'System.Collect ions.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!Gab e

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 CreateAllTempla tes has the followinf declaration in the
C++-based SDK:

VARIANT_BOOL CreateAllTempla tes(IUnknown* pIDibImage, IUnknown*
pIFacePosition, VARIANT* FullTemplate, VARIANT* StoredNormalize r,
VARIANT* VectorTemplate, double *dGenderScore)

The tlbimp interop is:
public abstract new System.Boolean CreateAllTempla tes (System.Object
pIDibImage, System.Object pIFacePosition, System.Object FullTemplate,
System.Object StoredNormalize r, 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.publi c.dotnet.framew ork.interop

Thanks.

Daniel.
"Gabe Covert" <ga**@thecovert s.net> wrote in message
news:uz******** ********@TK2MSF TNGP10.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 CreateAllTempla tes has the followinf declaration in the
C++-based SDK:

VARIANT_BOOL CreateAllTempla tes(IUnknown* pIDibImage, IUnknown*
pIFacePosition, VARIANT* FullTemplate, VARIANT* StoredNormalize r,
VARIANT* VectorTemplate, double *dGenderScore)

The tlbimp interop is:
public abstract new System.Boolean CreateAllTempla tes (System.Object
pIDibImage, System.Object pIFacePosition, System.Object FullTemplate,
System.Object StoredNormalize r, 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
1561
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. in the first line I would appreciate it deeply ... for ($y = 0, $x = $cx-$cy-1; $y <= $cy; ++$y,++$x) { $prd = $q * $y_ar + $car; $prd -= ($car = intval($prd / 1E7)) * 1E7;
2
1703
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 cpp_exception_1: do_stuff except cpp_exception_2:
1
2044
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, but I am stumped at translating LaTeX character encodings to something XML won't choke on. I found GNU recode to solve most of this, using cat milestone.tex | recode -d tex..xml | itemdb -s xml -o milestone.xml
0
924
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; /* sprawdzamy zapis czy odczyt */ \ int state; /* aktualny stan maszynki */ \
9
5678
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 a window or not. My callback function get a long pointer (lParam) to a structure which contains further information. This structure is described at MSN as follows: typedef struct tagCREATESTRUCT {
1
1867
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 some help on translating it into SQL as a subquery so I can use it in an application. the queries in Access are the subquery... (query4) SELECT Movement.DateTime, Movement.StudentID, Movement.Subject, Movement.Teacher, Movement.Destination,...
3
1944
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 Marshal.Copy(new IntPtr(pRawData), bRawData, 0, raw.hid.dwSizHid - 1); int rawData = bRawData | bRawData << 8; the full code is taken from the following article:
5
2724
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 != win32event.WAIT_TIMEOUT: really_do_start_my_app() else:
1
3198
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 issue I have is that I need to get this code translated into Python. The Python mechanize library is not very well documented and I was wondering if anyone here had any experience using this library in Ruby or Python. Basically the only tricky...
0
9643
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10085
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.