Jump to content

2-dimensional Array in Struct


Recommended Posts

hello @ all,

i would like to Create a Struct with DllStructCreate an d an 2-dimensional Array in it.

$tagZINT_SYMBOL = "struct;" & _
        "int symbology;" & _
        "int height;" & _
        "int whitespace_width;" & _
        "int border_width;" & _
        "int output_options;" & _
        "char fgcolour[10];" & _
        "char bgcolour[10];" & _
        "char outfile[256];" & _
        "float scale;" & _
        "int option_1;" & _
        "int option_2;" & _
        "int option_3;" & _
        "int show_hrt;" & _
        "int input_mode;" & _
        "byte text[128];" & _
        "int rows;" & _
        "int width;" & _
        "char primary[128];" & _
        "int row_height[178][143];" & _
        "char errtxt[100];" & _
        "char bitmap;" & _
        "int bitmap_width;" & _
        "int bitmap_height;" & _
        "endstruct" ;STRUCT ZINT_SYMBOL / PTR StructCreate
$tZINT_SYMBOL = DllStructCreate($tagZINT_SYMBOL)
ConsoleWrite("Error: " & @error & @CRLF)

My problem is row "int row_height[178][143]". I found 1 Post in the hole forum discussing this point.

The answer from "The Kandie Man" was: "You can't create multidimensional char arrays." --> Link to post

I would like to ask Jos, if it is possible to do something like that. ^^

I attach the original zint.h with the struct reference in "C" the zint.dll and my code. It is a little bit wierd cause there are a few Struct that are referenced with ptr. This part is also not working till now. But one after the other. ^^

In the demo i deleted the ptr in $tagZINT_SYMBOL cause it drops an error too.

here is the origin end of $tagZINT_SYMBOL
"BYTE bitmap_height;" & _
 "ptr* "& $ptrZINT_RENDER & " *rendered;" & _ ; this one is the second problem ^^
 "endstruct" ;STRUCT ZINT_SYMBOL / PTR StructCreate"

Spoiler
#include <Array.au3>

$tagZINT_RENDER_LINE = "struct;" & _
        "float x;" & _
        "float y;" & _
        "float length;" & _
        "float width;" & _
        "ptr *next;" & _
        "endstruct" ;STRUCT ZINT_RENDER_LINE / PTR StructCreate
$tagZINT_RENDER_STRING = "struct;" & _
        "float x;" & _
        "float y;" & _
        "int length;" & _
        "char* text;" & _
        "ptr *next;" & _
        "endstruct" ;STRUCT ZINT_RENDER_STRING / PTR StructCreate
$tagZINT_RENDER_RING = "struct;" & _
        "float x;" & _
        "float y;" & _
        "float radius;" & _
        "float line_width;" & _
        "ptr *next;" & _
        "endstruct" ;STRUCT ZINT_RENDER_RING / PTR StructCreate
$tagZINT_RENDER_HEXAGON = "struct;" & _
        "float x;" & _
        "float y;" & _
        "ptr *next;" & _
        "endstruct" ;STRUCT ZINT_RENDER_HEXAGON / PTR StructCreate

$tZINT_RENDER_LINE = DllStructCreate($tagZINT_RENDER_LINE)
$tZINT_RENDER_STRING = DllStructCreate($tagZINT_RENDER_STRING)
$tZINT_RENDER_RING = DllStructCreate($tagZINT_RENDER_RING)
$tZINT_RENDER_HEXAGON = DllStructCreate($tagZINT_RENDER_HEXAGON)

$ptrZINT_RENDER_LINE = DllStructGetPtr($tZINT_RENDER_LINE)
$ptrZINT_RENDER_STRING = DllStructGetPtr($tZINT_RENDER_STRING)
$ptrZINT_RENDER_RING = DllStructGetPtr($tZINT_RENDER_RING)
$ptrZINT_RENDER_HEXAGON = DllStructGetPtr($tZINT_RENDER_HEXAGON)

$tagZINT_RENDER = "struct;" & _
        "float width;" & _
        "float height;" & _
        "ptr* " & $ptrZINT_RENDER_LINE & " *lines;" & _
        "ptr* " & $ptrZINT_RENDER_STRING & " *strings;" & _
        "ptr* " & $ptrZINT_RENDER_RING & " *rings;" & _
        "ptr* " & $ptrZINT_RENDER_HEXAGON &" *hexagons;" & _
        "endstruct";STRUCT ZINT_RENDER / PTR StructCreate
$tZINT_RENDER = DllStructCreate($tagZINT_RENDER)
$ptrZINT_RENDER = DllStructGetPtr($tagZINT_RENDER)

$tagZINT_SYMBOL = "struct;" & _
        "int symbology;" & _
        "int height;" & _
        "int whitespace_width;" & _
        "int border_width;" & _
        "int output_options;" & _
        "char fgcolour[10];" & _
        "char bgcolour[10];" & _
        "char outfile[256];" & _
        "float scale;" & _
        "int option_1;" & _
        "int option_2;" & _
        "int option_3;" & _
        "int show_hrt;" & _
        "int input_mode;" & _
        "char text[128];" & _
        "int rows;" & _
        "int width;" & _
        "char primary[128];" & _
        "byte encoded_data[178][143];" & _
        "int row_height[178];" & _
        "char errtxt[100];" & _
        "char bitmap;" & _
        "int bitmap_width;" & _
        "BYTE bitmap_height;" & _
        "endstruct" ;STRUCT ZINT_SYMBOL / PTR StructCreate
$tZINT_SYMBOL = DllStructCreate($tagZINT_SYMBOL)
ConsoleWrite("Error: " & @error & @CRLF)

 

 

zint.h zint.dll manual.pdf

The two basic principles of Windows system administration:
For minor problems, reboot -- For major problems, reinstall
"Sarkasm is the lowest form of humor, but the highest form of intelligenz"
Val McDermid
Link to comment
Share on other sites

zint.h = 0 bytes

 

https://github.com/samlown/zint/blob/master/backend/zint.h

int row_height[178]; /* Largest symbol is 177x177 QR Code */

https://zint.org.uk/manual/chapter/5

row_height = array of integers     Representation of the height of a row.     (output only)

 

I would think this means that row_height is an array of 178 elements, where each element ranges between 0 and 177 in value.

 

Edit: The structure in the above linked zint.h file looks different than yours:

    unsigned char encoded_data[178][143];
    int row_height[178]; /* Largest symbol is 177x177 QR Code *

Googling unsigned char encoded_data leads to this:

https://social.msdn.microsoft.com/Forums/sqlserver/en-US/f29fbf40-094f-4ece-933d-4f161923ebfa/problem-using-a-struct-as-parameter-for-bidirectional-data-transfer-c-c-interop?forum=csharplanguage

 [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U1, SizeConst=25454)]

 

So it seems like encoded_data might be represented by

byte encoded_data[25454]

 

     
Edited by KaFu
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...