Re: pass complex structure to native function



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.
>>
>>
>>


.



Relevant Pages

  • RE: pass complex structure to native function
    ... > when I added string size to structures as below, ... >> this param is byref and should return filled structure. ... >> Public Class Struct1 ... >> Public numExtData As Integer ' Number of extended data structures ...
    (microsoft.public.dotnet.framework.interop)
  • RE: pass complex structure to native function
    ... Public strClue As String ... > Public Class Struct1 ... > Public numExtData As Integer ' Number of extended data structures ... >>> Arrays, and also Arrays of another structures that also contains ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: pass complex structure to native function
    ... Public strClue As String ... > Public Class Struct1 ... > Public numExtData As Integer ' Number of extended data structures ... >>> Arrays, and also Arrays of another structures that also contains ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: pass complex structure to native function
    ... Public strClue As String ... > Public Class Struct1 ... > Public numExtData As Integer ' Number of extended data structures ... >>> Arrays, and also Arrays of another structures that also contains ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Need a little help
    ... for the information to add to the arrays. ... JTextPane textPane = new JTextPane; ... String newArtist = JOptionPane.showInputDialog(null, "Please enter ... }//end public void actionPerformed ...
    (comp.lang.java.programmer)