Re: pass complex structure to native function
- From: "Ivan" <ivande@xxxxxxx>
- Date: Thu, 14 Jul 2005 11:48:22 +0300
I have tried to use AdvansedMarshaller from OpenNETCF and it did not work.
Actually - native OpenNETCF.Runtime.InteropServices.AdvansedMarshaller
crashed.
I have converted the code to VB.NET I've found that that crash was on String
type handling in GetFieldSize method (index out of bounds). I have added
error handlers there and looks that it started to work, but when I pass
bytes array to the function - it returned array with no changes. Byt this
param is byref and should return filled structure.
Below are some pieces of simplified code I used:
'----------
<DllImport("lib.dll", EntryPoint:="Input", _
CallingConvention:=CallingConvention.Winapi, SetLastError:=True)> _
Private Shared Function InputInt(ByVal filename As String, _
ByVal param() As Byte) As Integer
End Function
'----------
Public Class Struct1
Inherits CustomMarshaler 'AdvancedMarshaler '
<CustomMarshalAs(SizeConst:=ArrSize)> _
Public extDataSignature() As Byte ' Four byte character signature
Public dataSize As Integer ' Size of extended data in bytes
Public extData() As Byte ' uninterpreted bytes of data
Private Const ArrSize As Integer = 4
End Class
'----------
Public Class Struct2
Inherits CustomMarshaler 'AdvancedMarshaler '
Public struct_size As Integer ' size of the data structure passed in bytes
must be initialized
Public szAcross As Integer ' Grid size - No. of cells across
Public szDown As Integer ' Grid Size - No. of cells down
Public strTitle As String ' Puzzle Title
Public numExtData As Integer ' Number of extended data structures
Public extDataList() As Struct2 ' Pointer to array of extended data
structures
End Class
'----------
Public Shared Function Input(ByVal filename As String, _
ByRef param As Struct2) As Integer
Dim lRes As Integer
Try
ACROSS_InputPuzzle = ACROSS_InputPuzzleInt(filename,
param.ByteArray) 'pass and returns bytearray with zeros
param.Deserialize() 'crashes on bytearray from zeros only
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Function
----------
"Alex Yakhnin [MVP]" <a.yakhnin@xxxxxxxxxxxxxx> wrote in message
news:4F585C76-6241-455D-A7B2-87F125732B90@xxxxxxxxxxxxxxxx
> Take a look at these articles:
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/ProcessManager.asp?frame=true
>
> http://www.opennetcf.org/PermaLink.aspx?guid=abe6694a-ff15-4617-a21f-8163d427a89c
>
> --
> Alex Yakhnin, .NET CF MVP
> www.intelliprog.com | www.opennetcf.org
>
>
> "Ivan" wrote:
>
>> Hi,
>>
>> I have a problem with passing complex structures to native code.
>> complex structures means that I have structure with Integers, Strings,
>> Byte
>> Arrays, and also Arrays of another structures that also contains Strings,
>> Byte Arrays etc.
>>
>> Any ideas how should I implement this?
>> I tried to use IntPrt, but I beleive this is not acceptable due to using
>> of
>> dynamic arrays in the structure.
>>
>> Note that I also need this structure to be passed ByRef and get data.
>>
>>
>> Thanks in advance,
>> Ivan.
>>
>>
>>
.
- Follow-Ups:
- References:
- pass complex structure to native function
- From: Ivan
- RE: pass complex structure to native function
- From: Alex Yakhnin [MVP]
- pass complex structure to native function
- Prev by Date: Re: Debugging assemblies on CF devices.
- Next by Date: Re: WebBrowser Component has no JavaScript history.back()?
- Previous by thread: RE: pass complex structure to native function
- Next by thread: Re: pass complex structure to native function
- Index(es):
Relevant Pages
|