RE: pass complex structure to native function

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi all,

I have posted this question to compactframework thread, but nobody helped...

Maybe you have smoe ideas?
see details below.

Reards,
Ivan

"Ivan" <ivande@xxxxxxx> wrote in message
news:eXJHBKFiFHA.2472@xxxxxxxxxxxxxxxxxxxxxxx
>
> update:
>
> when I added string size to structures as below, I made the Deserialize
> method work, byt it did not helped - I have same structure (empty) as
> passed. I even tried to pass that params as ByRef, but no luck...
>
> maybe you will find some problems in my code?
>
> ------
> Public Class Struct1
>
> Inherits CustomMarshaler 'AdvancedMarshaler '
>
> Public numClue As Integer
>
> <CustomMarshalAs(SizeConst:=MAX_INTERFACE_NAME_LEN)> _
>
> Public strClue As String
>
> Private Const MAX_INTERFACE_NAME_LEN As Integer = 256
>
> End Class
>
>
>
> "Ivan" <ivande@xxxxxxx> wrote in message
> news:ekcRSDFiFHA.3568@xxxxxxxxxxxxxxxxxxxxxxx
>>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
    ... I have converted the code to VB.NET I've found that that crash was on String ... Public Class Struct1 ... Public numExtData As Integer ' Number of extended data structures ... >> Arrays, and also Arrays of another structures that also contains Strings, ...
    (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: 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)