P/Invoke array para

  • Thread starter Thread starter news.microsoft.com
  • Start date Start date
N

news.microsoft.com

When i use API
int WINAPI HHGetPhrase(WORD wCode,LPWORD* pResult);

I write the following c# code :

[DllImport("HHRES.dll", EntryPoint="HHGetPhrase", SetLastError=true)]
internal static extern int HWGetPhrase( UInt16 wCode, UInt16[][]
pResult );

UInt16[][] LX=new UInt16[10][] ;
int num=InputMethod.HanWang.HWGetPhrase(tempUInt16,LX);

but it throw NotSupportException , why ?
 
[DllImport("HHRES.dll", EntryPoint="HHGetPhrase", SetLastError=true)]
internal static extern int HWGetPhrase( UInt16 wCode, UInt16[]pResult );

UInt16[] LX=new UInt16[10];
int num=InputMethod.HanWang.HWGetPhrase(tempUInt16,LX);


This method can run , but the returned result is not wrong .


Alex Feinman said:
I'm not sure if pResult is supposed to be an address of a single WORD or
WORD array, but you can do the following:

[DllImport("HHRES.dll", EntryPoint="HHGetPhrase", SetLastError=true)]
internal static extern int HWGetPhrase( UInt16 wCode, UInt16[]pResult );

UInt16[] LX=new UInt16[10];
int num=InputMethod.HanWang.HWGetPhrase(tempUInt16,LX);

or if it returns just one WORD:

[DllImport("HHRES.dll", EntryPoint="HHGetPhrase", SetLastError=true)]
internal static extern int HWGetPhrase( UInt16 wCode, out UInt16
pResult );

UInt16 LX;
int num=InputMethod.HanWang.HWGetPhrase(tempUInt16,out LX);

news.microsoft.com said:
When i use API
int WINAPI HHGetPhrase(WORD wCode,LPWORD* pResult);

I write the following c# code :

[DllImport("HHRES.dll", EntryPoint="HHGetPhrase", SetLastError=true)]
internal static extern int HWGetPhrase( UInt16 wCode, UInt16[][]
pResult );

UInt16[][] LX=new UInt16[10][] ;
int num=InputMethod.HanWang.HWGetPhrase(tempUInt16,LX);

but it throw NotSupportException , why ?
 
sorry , returned result is wrong .




news.microsoft.com said:
[DllImport("HHRES.dll", EntryPoint="HHGetPhrase", SetLastError=true)]
internal static extern int HWGetPhrase( UInt16 wCode, UInt16[]pResult );

UInt16[] LX=new UInt16[10];
int num=InputMethod.HanWang.HWGetPhrase(tempUInt16,LX);


This method can run , but the returned result is not wrong .


Alex Feinman said:
I'm not sure if pResult is supposed to be an address of a single WORD or
WORD array, but you can do the following:

[DllImport("HHRES.dll", EntryPoint="HHGetPhrase", SetLastError=true)]
internal static extern int HWGetPhrase( UInt16 wCode, UInt16[]pResult );

UInt16[] LX=new UInt16[10];
int num=InputMethod.HanWang.HWGetPhrase(tempUInt16,LX);

or if it returns just one WORD:

[DllImport("HHRES.dll", EntryPoint="HHGetPhrase", SetLastError=true)]
internal static extern int HWGetPhrase( UInt16 wCode, out UInt16
pResult );

UInt16 LX;
int num=InputMethod.HanWang.HWGetPhrase(tempUInt16,out LX);

news.microsoft.com said:
When i use API
int WINAPI HHGetPhrase(WORD wCode,LPWORD* pResult);

I write the following c# code :

[DllImport("HHRES.dll", EntryPoint="HHGetPhrase", SetLastError=true)]
internal static extern int HWGetPhrase( UInt16 wCode, UInt16[][]
pResult );

UInt16[][] LX=new UInt16[10][] ;
int num=InputMethod.HanWang.HWGetPhrase(tempUInt16,LX);

but it throw NotSupportException , why ?
 
Am I correct that this API fills pResult with a multidimensional jagged
array? There's no way to marshal something that complex. You might try
passing the array as just a byte stream and then add a few params that
describe the stream. Something like this:

[DllImport("HHRES.dll", EntryPoint="HHGetPhrase", SetLastError=true)]
internal static extern int HWGetPhrase( UInt16 wCode, byte[] resultData,
uint dataLength, byte[] boundsInfo );
 
So disappointed ,P/Invoke does not support multidimensional array .
This API is not writed by me . So i can not change it param structure .


Chris Tacke said:
Am I correct that this API fills pResult with a multidimensional jagged
array? There's no way to marshal something that complex. You might try
passing the array as just a byte stream and then add a few params that
describe the stream. Something like this:

[DllImport("HHRES.dll", EntryPoint="HHGetPhrase", SetLastError=true)]
internal static extern int HWGetPhrase( UInt16 wCode, byte[] resultData,
uint dataLength, byte[] boundsInfo );


--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net

news.microsoft.com said:
When i use API
int WINAPI HHGetPhrase(WORD wCode,LPWORD* pResult);

I write the following c# code :

[DllImport("HHRES.dll", EntryPoint="HHGetPhrase", SetLastError=true)]
internal static extern int HWGetPhrase( UInt16 wCode, UInt16[][]
pResult );

UInt16[][] LX=new UInt16[10][] ;
int num=InputMethod.HanWang.HWGetPhrase(tempUInt16,LX);

but it throw NotSupportException , why ?
 
You probably could use an array of IntPtr's:

[DllImport("HHRES.dll", EntryPoint="HHGetPhrase", SetLastError=true)]
internal static extern int HWGetPhrase( UInt16 wCode, IntPtr[] pResult );


IntPtr [] LX = new IntPtr[10];
int num=InputMethod.HanWang.HWGetPhrase(tempUInt16,LX);


At this point LX would contain pointers to native arrays of UInt16.
You could access this data directly using unsafe code or you could copy
data to managed jagged array.
You will have to know the size of these arrays somehow.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "news.microsoft.com" <[email protected]>
References: <[email protected]>
Subject: Re: P/Invoke array para
Date: Thu, 24 Jul 2003 09:37:35 +0800
Lines: 50
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: 203.126.19.234
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.compactframework:29043
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

So disappointed ,P/Invoke does not support multidimensional array .
This API is not writed by me . So i can not change it param structure .


Chris Tacke said:
Am I correct that this API fills pResult with a multidimensional jagged
array? There's no way to marshal something that complex. You might try
passing the array as just a byte stream and then add a few params that
describe the stream. Something like this:

[DllImport("HHRES.dll", EntryPoint="HHGetPhrase", SetLastError=true)]
internal static extern int HWGetPhrase( UInt16 wCode, byte[] resultData,
uint dataLength, byte[] boundsInfo );


--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net

news.microsoft.com said:
When i use API
int WINAPI HHGetPhrase(WORD wCode,LPWORD* pResult);

I write the following c# code :

[DllImport("HHRES.dll", EntryPoint="HHGetPhrase", SetLastError=true)]
internal static extern int HWGetPhrase( UInt16 wCode, UInt16[][]
pResult );

UInt16[][] LX=new UInt16[10][] ;
int num=InputMethod.HanWang.HWGetPhrase(tempUInt16,LX);

but it throw NotSupportException , why ?
 
Back
Top