PowerBASIC Peer Support Forums
 

Go Back   PowerBASIC Peer Support Forums > Jose's Corner > Discussion

Discussion Discussion area for all things related to Jose's code. Posts and uploads are available to all forum members.

Reply
 
Thread Tools Display Modes
  #1  
Old Feb 9th, 2012, 10:39 AM
Chris Boss Chris Boss is offline
Member
 
Join Date: Feb 1999
Posts: 5,771
A good use for this Forum - Discuss Metro/WinRT

Rather than make this forum a rehash of what is already on Jose's current forums, maybe it would be a good idea to start discussions on new topics where Jose would be a moderator and contributor.

IMO Jose may be one the best persons to lead a discussion about Metro and how to improve the PowerBasic compiler for building Metro applications.

Also his knowledge would help all of us to start digging into the WinRT, which is not only used in Metro apps, but I have read that WinRT can also be accessed by desktop apps.

So maybe add two new child forums to Joses Corner:

Metro Discussions

WinRT Discussions
__________________
Chris Boss
Computer Workshop
Developer of "EZGUI"
http://cwsof.com
http://twitter.com/EZGUIProGuy
Reply With Quote
  #2  
Old Feb 9th, 2012, 01:52 PM
Josť Roca Josť Roca is online now
Moderator
 
Join Date: Mar 2004
Location: Valencia, Spain
Posts: 6,727
Sorry to disappoint you, but besides not having Windows 8, I don't know more about Metro applications than you, and I don't have any expertise with the languages currently available to develop them.

Regarding WinRT, if Bob has already read the scarce preliminary documentation, he already knows what is needed to do. It is more a problem of PBers not being yet used to use low-level COM that anything else.

I told Bob that having worked so hard to implement one of the best low-level COM support in any compiler, it is a crime that almost nobody is using it. So the purpose of this forum is to demonstrate that it is not so hard to use.

Contrarily to Automation servers, most low-level COM servers don't come with type libraries. Why? Because these servers can not be used by Automation languages and have to be used with direct interface calls. Therefore, you can't simply take a browser to generate the interface definitions, but have to be translated from the ones in the C++ headers, just as we have to do with standard function declares.

The PB includes don't provide any interface declarations; therefore, you can't use the low-level COM servers provided by Windows with them. Mine provide them, but there are differences in the translation of many of the declares that they have in common. Many that have tried them, have stopped at the first conflict, because having no good knowledge of the Windows API, don't know how to solve them, and others that only post in the PB Forums, prefer to use code that Semen or I wrote 8 or 10 years ago to no force the use of my includes. Anybody lurking this forum and seeing this kind of code still being used must thing that PB is an arcane compiler.

So I have modified my headers to wrap the differences with #IF/ENDIFs. The only gotcha is that the PB includes and mine can't be mixed. Maybe one day we will got one version of the PB IDE with provision for more than one set of include files and a menu option to easily switch between them.

My goal is that PBer's start to learn and use low-level COM. About 2/3 (a rough estimate) of the Windows 7 API are low-level COM servers and this proportion is only going to increase. If they don't, they won't be able to use any of the new technologies and WinRT will be the least of his problems.
__________________
Website: http://www.jose.it-berater.org/index.html
SED Editor, TypeLib Browser.
Forum: http://www.jose.it-berater.org/smfforum/index.php
Reply With Quote
  #3  
Old Feb 9th, 2012, 03:06 PM
Chris Boss Chris Boss is offline
Member
 
Join Date: Feb 1999
Posts: 5,771
Well then, why not use this new forum to help the rest of us get up to speed with Powerbasic COM and then let those of us who do have Windows 8 try to put it into practical use for accessing the WinRT.

Maybe a child form entitled:

Prepare for WinRT by learning PB COM now
__________________
Chris Boss
Computer Workshop
Developer of "EZGUI"
http://cwsof.com
http://twitter.com/EZGUIProGuy
Reply With Quote
  #4  
Old Feb 9th, 2012, 03:24 PM
Eric Pearson Eric Pearson is offline
Member
 
Join Date: Oct 1987
Location: Traverse City, Michigan, USA
Posts: 7,939
It's pretty hard to justify adding a subforum at this early date, when this is literally the one and only thread on the three existing ones. Let's see what our oh-so-competent friend Josť has in store for us before suggesting improvements.

I suspect that if Metro/etc. is a hot enough topic, for long enough, it could eventually earn a dedicated section. Until then, there's plenty of wide open space here, and an excellent host to guide us.

-- Eric

Last edited by Eric Pearson; Feb 9th, 2012 at 03:26 PM.
Reply With Quote
  #5  
Old Feb 9th, 2012, 07:28 PM
Josť Roca Josť Roca is online now
Moderator
 
Join Date: Mar 2004
Location: Valencia, Spain
Posts: 6,727
Contrarily to Automation, low-level COM is quite similar to calling a function dynamically.

To call a function dynamically, what we do?

1. Call LoadLibrary to load a library module into the address space of the process. It successful, it increments the reference count of the library and returns an handle.

2. Call GetProcAddress to retrieve the address of the wanted function.

3. Use CALL DWORD to call he function directly and pass the parameters.

4. Call FreeLibrary to drecement the reference count. When the reference count reaches zero, the module is unloaded from the address space of the calling process and the handle is no longer valid.

COM is similar, but deals with a group of functions (called methods), and this agroupation is called an interface. Several interfaces can be grouped in a class.

1. Instead of calling LoadLibrary, we call CoCreateInstance (or the PB NEWCOM statement, that calls CoCreateInstance). CoCreateInstance calls LoadLibrary to load a library module into the address space of the process, but instead of returning the handle, it calls the CreateInstance method of an interface called IClassFactory, implemented in the COM server, and returns the address of a pointer (COM uses double indirection) to an array of DWORDs containing the addresses of all the methods that belong to the requested interface. This has a similar effect to what GetProcAdress does, but for a group of methods instead of a single function.

2. We use CALL DWORD to call the method, but as what we have is the address of a pointer to an array of pointers, instead of CALL DWORD pAdress, we have to use CALL DWORD @@pAdress[offset], where the offset is 0 for the first method, 4 for the second, 8 for the third and so on. Another particularity is that the first parameter passed is always this address to a pointer to the array of pointers, commonly know as pthis. To make it easier to use, instead of CALL DWORD @@pAdress[offset] USING <prototype declaration> <pthis, parameters>, we group the prototypes in an interface declaration and the compiler calculates the correct offset based on it. This allows to use pInterface.MethodName(parameters) instead of the more convoluted CALL DWORD @@pAdress[offset] USING <prototype declaration> <pthis, parameters>, but it does the same thing.

3. Instead of FreeLibrary, you set pInterface = NOTHING.

Events work as callback functions, but instead of passing a pointer to a single function, we group several related ones in a class and we pass a reference to this class.

The most important interface is IUnknown (all interfaces inherit ultimately from it), which has three methods: AddRef and Release to manage reference counting, and QueryInterface to navigate between the different interfaces implemented in the same class. You will see them being constantly used in C and other languages, but you don't need to call them with PB because it does it under the hood. However, it is important to know what they do.
__________________
Website: http://www.jose.it-berater.org/index.html
SED Editor, TypeLib Browser.
Forum: http://www.jose.it-berater.org/smfforum/index.php

Last edited by Josť Roca; Feb 9th, 2012 at 07:36 PM.
Reply With Quote
  #6  
Old Feb 11th, 2012, 08:54 AM
Steve Hutchesson Steve Hutchesson is offline
Member
 
Join Date: Oct 1999
Location: Sydney Australia
Posts: 2,423
That's an excellent description Josť, compliments.
__________________
hutch at movsd dot com
www.masm32.com
Reply With Quote
  #7  
Old Feb 17th, 2012, 03:11 AM
Patrice Terrier Patrice Terrier is offline
Member
 
Join Date: Aug 1998
Location: France
Posts: 3,658
Josť--

I would like also to say thank you, for these descriptions helping us to understand how low level COM works.
__________________
Patrice Terrier
pterrier@zapsolution.com
www.zapsolution.com
Addons: GDImage (advanced graphic control), WinLIFT (Skin Engine), Artwork (logo creation).
Reply With Quote
  #8  
Old Feb 17th, 2012, 06:05 AM
Eric Pearson Eric Pearson is offline
Member
 
Join Date: Oct 1987
Location: Traverse City, Michigan, USA
Posts: 7,939
I too have learned a great deal already! Thanks Josť !
Reply With Quote
  #9  
Old Feb 17th, 2012, 06:54 PM
Josť Roca Josť Roca is online now
Moderator
 
Join Date: Mar 2004
Location: Valencia, Spain
Posts: 6,727
If I had talent for writing, I could have written a book of 1,950 pages and you wouldn't have understood anything and got the wrong impresion that low-level COM is a pain to learn, when in fact is pretty straightforward.

If you look at the declaration of a METHOD, you will see that it is the same that the one for a standard function:

Code:
METHOD GetBindOptions ( _                            ' VTable offset = 28
   BYREF pbindopts AS BIND_OPTS _                     ' __in BIND_OPTS * pbindopts
) AS LONG                                            ' HRESULT
In PB, we are using the keyword METHOD instead of FUNCTION, but only to avoid confussion. In C, it would be:

Code:
HRESULT STDMETHODCALLTYPE GetBindOptions(
            /* [out][in] */ BIND_OPTS *pbindopts)
You can also use with them all kind of data types and structures. Almost none of them uses VARIANTs and SAFEARRAYs because they aren't needed. To pass an array, you simply do the same that with a standard C function: to pass a pointer to the first element of the array and the number of elements of the array.

Anybody that already knows how to use the Windows API has much of the way traveled.
__________________
Website: http://www.jose.it-berater.org/index.html
SED Editor, TypeLib Browser.
Forum: http://www.jose.it-berater.org/smfforum/index.php
Reply With Quote
  #10  
Old Feb 18th, 2012, 09:45 AM
Theo Gottwald Theo Gottwald is offline
Member
 
Join Date: Aug 2001
Location: 76706 Dettenheim, Germany
Posts: 2,001
Quote:
Maybe one day we will got one version of the PB IDE with provision for more than one set of include files and a menu option to easily switch between them.
While this would be a next step, the PB IDE already is not so far from that as we can already move INCLUDE sets up or down in the includes list.
And the include set that is up is taken. I found myself doing that quite often, trying which include set was the right for an old project.

Therefore what I would prefer is not a change in the IDE but a Meta-statement in the compiler to override the IDE.Setting, like the one in CSED.
As its the compiler that uses the "Include Path" at the end, thsource code is the right place where it should be,

Code:
$CSED_INCPATH = "E:\...\pbwin10\WINAPI_IV"
Only informations that are in the source code are backup'ed with the source code.

If the setting are in the IDE, how will you know in several years, when the next PB is on the market,
which set of includes the old project has used?
__________________
--Theo Gottwald
------------------------------------------------
76706 Dettenheim * Germany * info@it-berater.org
------------------------------------------------
Joses Forum * Theo's Link Site * IT-Berater.org

Last edited by Theo Gottwald; Feb 18th, 2012 at 09:48 AM.
Reply With Quote
  #11  
Old Mar 12th, 2012, 04:17 AM
Anabelle Mills Anabelle Mills is offline
Member
 
Join Date: Mar 2012
Posts: 1
I've been watching this thread for a while, it's useful to me since I'm only a beginner in this subject - it helps me learn and figure everything out. Thanks for sharing your expertise, guys!
__________________
m4a to mp3 converter
Reply With Quote
  #12  
Old Mar 12th, 2012, 03:57 PM
Rick McNeely Rick McNeely is offline
Member
 
Join Date: Oct 2006
Location: Oreana Illinois
Posts: 80
I've been trying COM for a while now. Mainly by stealing Jose's code and modifying to suit. I really appreciate all of the guidance that he and others are willing to provide. The learning curve on COM seems a little steeper than most technologies. Just have to keep pushing.
__________________
Rick
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:58 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright © 1999-2011 PowerBASIC, Inc. All Rights Reserved.
Error in my_thread_global_end(): 1 threads didn't exit