User Tools

Site Tools


calling_20object_20methods_20using_20structures

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

calling_20object_20methods_20using_20structures [2018/03/31 13:19]
127.0.0.1 external edit
calling_20object_20methods_20using_20structures [2018/04/14 13:18] (current)
richardrussell Added syntax highlighting
Line 1: Line 1:
 =====Calling object methods using structures===== =====Calling object methods using structures=====
  
-//by Richard Russell, March 2007//\\ \\  Calling **COM**, **OLE** or **ActiveX** object //methods// generally involves the use of a rather arcane syntax, such as this example taken from the BB4W manual under [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwine.html#​gifjpeg|Displaying GIF and JPEG images]]:\\ \\ +//by Richard Russell, March 2007//\\ \\  Calling **COM**, **OLE** or **ActiveX** object //methods// generally involves the use of a rather arcane syntax, such as this example taken from the BB4W manual under [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwine.html#​gifjpeg|Displaying GIF and JPEG images]]: 
 + 
 +<code bb4w> ​
         SYS !(!gpp%+24),​ gpp%, ^hmw% : REM. IPicture::​get_Width         SYS !(!gpp%+24),​ gpp%, ^hmw% : REM. IPicture::​get_Width
         SYS !(!gpp%+28),​ gpp%, ^hmh% : REM. IPicture::​get_Height         SYS !(!gpp%+28),​ gpp%, ^hmh% : REM. IPicture::​get_Height
-Here it is not at all clear what methods are being called, and how, hence the need for comments.\\ \\  It is possible to improve the clarity considerably by using a **structure** to represent the object. You can then call the object'​s methods as follows:\\ \\ +</​code>​ 
 + 
 +Here it is not at all clear what methods are being called, and how, hence the need for comments.\\ \\  It is possible to improve the clarity considerably by using a **structure** to represent the object. You can then call the object'​s methods as follows: 
 + 
 +<code bb4w>
         SYS IPicture.get_Width%,​ gpp%, ^hmw%         SYS IPicture.get_Width%,​ gpp%, ^hmw%
         SYS IPicture.get_Height%,​ gpp%, ^hmh%         SYS IPicture.get_Height%,​ gpp%, ^hmh%
-To make this work you need to declare a structure containing all the object'​s methods in the correct order. In the case of the **IPicture** interface the structure needs to be declared as follows:\\ \\ +</​code>​ 
 + 
 +To make this work you need to declare a structure containing all the object'​s methods in the correct order. In the case of the **IPicture** interface the structure needs to be declared as follows: 
 + 
 +<code bb4w>
         DIM IPicture{QueryInterface%,​ AddRef%, Release%, get_Handle%,​ get_hPal%, \         DIM IPicture{QueryInterface%,​ AddRef%, Release%, get_Handle%,​ get_hPal%, \
         \            get_Type%, get_Width%, get_Height%,​ Render%, set_hPal%, get_CurDC%, \         \            get_Type%, get_Width%, get_Height%,​ Render%, set_hPal%, get_CurDC%, \
         \            SelectPicture%,​ get_KeepOriginalFormat%,​ put_KeepOriginalFormat%,​ \         \            SelectPicture%,​ get_KeepOriginalFormat%,​ put_KeepOriginalFormat%,​ \
         \            PictureChanged%,​ SaveAsFile%,​ get_Attributes%}         \            PictureChanged%,​ SaveAsFile%,​ get_Attributes%}
-To complete the process we must point the structure at the object'​s dispatch table:\\ \\ +</​code>​ 
 + 
 +To complete the process we must point the structure at the object'​s dispatch table: 
 + 
 +<code bb4w>
         !(^IPicture{}+4) = !gpp%         !(^IPicture{}+4) = !gpp%
-The memory originally allocated when the structure was created is wasted, but this isn't a problem if it is declared as a **LOCAL** structure.\\ \\  As a practical illustration of the use of this technique here is a replacement for the **PROCdisplay** routine listed in the BB4W manual:\\ \\ +</​code>​ 
 + 
 +The memory originally allocated when the structure was created is wasted, but this isn't a problem if it is declared as a **LOCAL** structure.\\ \\  As a practical illustration of the use of this technique here is a replacement for the **PROCdisplay** routine listed in the BB4W manual: 
 + 
 +<code bb4w>
         DEF PROCdisplay(picture$,​ xpos%, ypos%, xsize%, ysize%)         DEF PROCdisplay(picture$,​ xpos%, ypos%, xsize%, ysize%)
         LOCAL iid{}, IPicture{}, oleaut32%, olpp%, gpp%, hmw%, hmh%, picture%, res%         LOCAL iid{}, IPicture{}, oleaut32%, olpp%, gpp%, hmw%, hmh%, picture%, res%
Line 49: Line 67:
         SYS "​UpdateWindow",​ @hwnd%         SYS "​UpdateWindow",​ @hwnd%
         ENDPROC         ENDPROC
 +</​code>​
calling_20object_20methods_20using_20structures.txt · Last modified: 2018/04/14 13:18 by richardrussell