Type (struct) declared in Extern issue
BlitzMax Forums/BlitzMax Programming/Type (struct) declared in Extern issue
| ||
If I declare a 'type' that is in effect a struct, I get an error "expecting field or method declaration but encountered '['"Import "-lTestDLL" Extern "C" Type TGUID2 Field Data1 : Int Field Data2 : Short Field Data3 : Short Field Data4 : Byte[8] End Type End Extern Can't we declare arrays in an external struct? |
| ||
With respect to:Data4:Byte[ 8 ] Data4 is a pointer to a byte array, and that line is equivilant to Data4:Byte[] = New Byte[ 8 ] I'm guessing what you want is an inline array within the struct, 8 bytes long? I'd say this is where the problem lies. |
| ||
Thanks for the reply, Michael. I thought the reason for declaring a type within an 'extern' was to make it compatible with external structures. There are lots of structures that have inline arrays, so having to declare them could get ugly. I was assuming it was like C, C++, Delphi, C#, VB, VB.Net, etc.. :) I think this could get somewhat confusing, as I imagine the percentage of programmers using BMax is going to be (at minimum) evenly spread amongst new to advanced. Cheers mate, Stu |
| ||
until recently, only Function definitions (maybe Const too?) were allowed inside of Extern. unfortuntely the documentation is a little shady on what can be in Extern. with the coming of the directx mod, mark stated that Type declarations in there were now possible, but still experiemental. i would guess that this is another potential issue in that arrays may not be compatible as of right now. as for accessing a structure. you can define the structure outside of the extern in BMAX and still pass it to functions defined inside extern as pointers. i cant remember exactly, but i think you need to define the pointer as a Byte Ptr. you then must pass the Varptr() of the first field to bypass the type headers BMAX have. if i find some time i can work up a quick example. a long time ago i did a test and i was able to populate and use a structure in C that was passed from BMAX. |
| ||
Thanks gman. I was able to pass 'structures' to an external DLL by passing a reference to the first field, but it seems the byte array is still a pointer, as described. Given it is experimental, I imagine Mr. Sibly will be making future enhancements to this support, which I look forward to. Cheers, Sti |
| ||
funny... i was looking at some old code and happened upon where i was passing a struct. i defined the parameter in the function i was passing it to as Int and then passed Int(Varptr(field1)) as the parameter where field1 was the first field defined in my type. the caveat is that the function parameter on the C side was a pointer to a struct. so something like:Type teststruct Field fld1:Int Field fld2:Float EndType Extern Function test(structptr:int) EndExtern Local testparam:teststruct=New teststruct test(Int(Varptr(testparam.fld1))) |