C-Structure > Pb-Structure

Just starting out? Need help? Post your questions and find answers here.
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

C-Structure > Pb-Structure

Post by Josh »

I have this C-Structure:

Code: Select all

typedef struct tagFUNCDESC {
  MEMBERID   memid;
  SCODE      *lprgscode;
  ELEMDESC   *lprgelemdescParam;
  FUNCKIND   funckind;
  INVOKEKIND invkind;
  CALLCONV   callconv;
  SHORT      cParams;
  SHORT      cParamsOpt;
  SHORT      oVft;
  SHORT      cScodes;
  ELEMDESC   elemdescFunc;
  WORD       wFuncFlags;
} FUNCDESC, *LPFUNCDESC;
I translated this to Pb with 2 structures:

Code: Select all

Structure ELEMDESCARRAY
  ElemDescParam.ELEMDESC[0]
EndStructure

Structure FUNCDESC Align #PB_Structure_AlignC
  MemId.l
  *rgScode
  *ElemDescParams.ELEMDESCARRAY
  FuncKind.l
  InvKind.l
  CallConv.l
  cParams.w
  cParamsOpt.w
  oVft.w
  cScodes.w
  ElemDescFunc.ELEMDESC
  FuncFlags.w
EndStructure
This works, but it looks a little bit ugly using following code

Code: Select all

Flags = *FuncDesc\ElemDescParams\ElemDescParam[Index]\ParamDesc\ParamFlags
Is there an other way for translating the structure?
sorry for my bad english
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: C-Structure > Pb-Structure

Post by skywalk »

You did not show all types defined within the struct?

Code: Select all

  MEMBERID
  SCODE
  ELEMDESC
  FUNCKIND
  INVOKEKIND
  CALLCONV
  ELEMDESC
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: C-Structure > Pb-Structure

Post by Josh »

Hi Sky,
  • MEMBERID is a DispId, I need this only for compare with other structures, so the .l is enough for me. Nothing to do
  • SCODE, I don't need, so the Pb-* is enough for me. Nothing to do
  • ELEMDESC is a structure. The content doesn't matter for my problem, but for the sake of completeness the C-structure here:

    Code: Select all

    typedef struct tagELEMDESC {
      TYPEDESC tdesc;
      union {
        IDLDESC   idldesc;
        PARAMDESC paramdesc;
      };
    } ELEMDESC, *LPELEMDESC;
  • FUNCKIND is a Enumeration. Nothing to do
  • INVOKEKIND is a Enumeration. Nothing to do
  • CALLCONV is a Enumeration. Nothing to do
As shown in my small example in my first posting, the problem is that I had to split the C-structure into two Pb-structures. With this split the Pb call looks a bit strange:

Code: Select all

Flags = *FuncDesc\ElemDescParams\ElemDescParam[Index]\ParamDesc\ParamFlags
Look at the double call ElemDescParams \ ElemDescParam[Index], what is in C only one call. This works, but maybe there is a better way to implement the structure in Pb.
sorry for my bad english
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

Re: C-Structure > Pb-Structure

Post by cas »

Another option is to use macro. I, personally, would not bother too much about this double call ElemDescParams \ ElemDescParam[Index] and just leave it as it is now.
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: C-Structure > Pb-Structure

Post by nco2k »

shouldnt it work like this?

Code: Select all

Flags = *FuncDesc\lprgelemdescParam(Index)\paramdesc\wParamFlags
edit: updated.

Code: Select all

Structure TYPEDESC Align #PB_Structure_AlignC
  StructureUnion
    *lptdesc;.TYPEDESC
    *lpadesc;.ARRAYDESC
    hreftype.l
  EndStructureUnion
  vt.w
EndStructure

Structure ARRAYDESC Align #PB_Structure_AlignC
  tdescElem.TYPEDESC
  cDims.w
  StructureUnion
    rgbounds.SAFEARRAYBOUND[0]
    dummyrgbounds.SAFEARRAYBOUND[1]
  EndStructureUnion
EndStructure

Structure IDLDESC Align #PB_Structure_AlignC
  *dwReserved
  wIDLFlags.w
EndStructure

Structure PARAMDESCEX Align #PB_Structure_AlignC
  cBytes.l
  varDefaultValue.VARIANT
EndStructure

Structure PARAMDESC Align #PB_Structure_AlignC
  StructureUnion
    *pparamdescex.PARAMDESCEX
    *dummypparamdescex; to avoid pb-bug
  EndStructureUnion
  wParamFlags.w
EndStructure

Structure ELEMDESC Align #PB_Structure_AlignC
  tdesc.TYPEDESC
  StructureUnion
    idldesc.IDLDESC
    paramdesc.PARAMDESC
  EndStructureUnion
EndStructure

Structure FUNCDESC Align #PB_Structure_AlignC
  memid.l
  StructureUnion
    *lprgscode.Long
    *dummylprgscodex; to avoid pb-bug
  EndStructureUnion
  Array lprgelemdescParam.ELEMDESC(0)
  funckind.l
  invkind.l
  callconv.l
  cParams.w
  cParamsOpt.w
  oVft.w
  cScodes.w
  elemdescFunc.ELEMDESC
  wFuncFlags.w
EndStructure
c ya,
nco2k
Last edited by nco2k on Mon Nov 27, 2017 10:09 am, edited 3 times in total.
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: C-Structure > Pb-Structure

Post by Josh »

cas wrote:I, personally, would not bother too much about this double call ElemDescParams \ ElemDescParam[Index] and just leave it as it is now.
Yeah, I'll leave it as it is. Maybe you know that, there's a simple solution and you just don't see it. That's why I actually asked :D
nco2k wrote:shouldnt it work like this?
Sorry, doesn't work


Thank you all for your efforts.
sorry for my bad english
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

Re: C-Structure > Pb-Structure

Post by cas »

nco2k wrote:shouldnt it work like this?
Here is sample code that can be compiled and shows the "problem". You can experiment on it.

Code: Select all

EnableExplicit

Structure element
  x.l
  y.l
  z.l
EndStructure

Structure elementsArray
  ElemDescParam.element[0]
EndStructure

Structure main
  a.l
  b.l
  c.l
  d.l
  *ElemDescParams.elementsArray
  f.l
EndStructure

DataSection ;do not modify datasection!
  struct_a:
  Data.l 1,2,3,4,?struct_b,5
  struct_b:
  Data.l 100,101,102
  Data.l 200,201,202
  Data.l 300,301,302
  Data.l 400,401,402
EndDataSection

Define *struct.main=?struct_a

Debug *struct\a ;1
Debug *struct\b ;2
Debug *struct\c ;3
Debug *struct\d ;4
Debug *struct\f ;5
Debug *struct\ElemDescParams\ElemDescParam[0]\x ;100
Debug *struct\ElemDescParams\ElemDescParam[1]\x ;200
Debug *struct\ElemDescParams\ElemDescParam[2]\x ;300
Debug *struct\ElemDescParams\ElemDescParam[3]\x ;400

;can ElemDescParams\ElemDescParam[index] in last 4 debug lines be shortened?
One solution with macro (only downside is no autocomplete after "ElemDesc[index]\"):

Code: Select all

Macro ElemDesc
  ElemDescParams\ElemDescParam
EndMacro

Define *struct.main=?struct_a

Debug *struct\ElemDesc[0]\x ;100
Debug *struct\ElemDesc[1]\x ;200
Debug *struct\ElemDesc[2]\x ;300
Debug *struct\ElemDesc[3]\x ;400
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: C-Structure > Pb-Structure

Post by nco2k »

Code: Select all

EnableExplicit

Structure element
  x.l
  y.l
  z.l
EndStructure

Structure main
  a.l
  b.l
  c.l
  d.l
  Array ElemDescParams.element(0)
  f.l
EndStructure

DataSection ;do not modify datasection!
  struct_a:
  Data.l 1,2,3,4,?struct_b,5
  struct_b:
  Data.l 100,101,102
  Data.l 200,201,202
  Data.l 300,301,302
  Data.l 400,401,402
EndDataSection

Define *struct.main=?struct_a

Debug *struct\a ;1
Debug *struct\b ;2
Debug *struct\c ;3
Debug *struct\d ;4
Debug *struct\f ;5

Debug *struct\ElemDescParams(0)\x ;100
Debug *struct\ElemDescParams(1)\x ;200
Debug *struct\ElemDescParams(2)\x ;300
Debug *struct\ElemDescParams(3)\x ;400
i also updated the previous code, added a missing structure and removed some unnecessary stuff.

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

Re: C-Structure > Pb-Structure

Post by cas »

Yes, that is the solution. So simple. I completely forgot about using Array keyword in structure.
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: C-Structure > Pb-Structure

Post by Josh »

Tried with Array. Doesn't work.

No problem, it runs like it is ^^
sorry for my bad english
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: C-Structure > Pb-Structure

Post by nco2k »

then you are doing something wrong. hard to help without any example code.

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Post Reply