CWindow RC18

Started by José Roca, August 25, 2016, 09:56:54 PM

Previous topic - Next topic

José Roca

CWindow Release Candidate 18

Incorporates all the previously discussed changes.

The most notable recent feature is the implementation of an OLE Container.

José Roca

The attached example demonstrates how to host the WebBrowser Control, connect to the events fired by it and use the IDocHostUIHandler interface to customize the control, in this case to make it DPI aware.

José Roca

GDI+ Examples

These are the examples that I have used to test the CGdiPlus classes.

Around 300 small examples demostrating the use of the methods.

James Fuller

Jose,
  I was just taking a peek at your AfxOleCon.inc.
Is this line correct with the double braces at the end???
CONST OC_IID = "{12520D52-F372-47FF-A74D-5FFA862BF4BA}}"   ' // Container's IID

James

José Roca

You can remove it. It is not used at all.

José Roca

I'm currently working in the another datatype missing in FB, VARIANTs. It is going very well.

When finished, I will be able to add support to several Windows COM technologies, such WMI and ADO.

Everything using FB code, without C++, Visual Basic or wathever.

José Roca

Because the FB headers don't provide support for PropSys.dll, an essential library to work seriously with variants, I'm loading it in the CVAR class and calling the functions dynamically, e.g.


' ========================================================================================
PRIVATE FUNCTION CVar.VariantToStringArray (BYVAL pvar AS VARIANT PTR, BYVAL prgsz AS PWSTR PTR, BYVAL crgsz AS ULONG, BYVAL pcElem AS ULONG PTR) AS HRESULT
   FUNCTION = E_POINTER
   IF psLib = NULL THEN EXIT FUNCTION
   DIM pVariantToStringArray AS FUNCTION (BYVAL pvar AS VARIANT PTR, BYVAL prgsz AS PWSTR PTR, BYVAL crgsz AS ULONG, BYVAL pcElem AS ULONG PTR) AS HRESULT
   pVariantToStringArray = DyLibSymbol(psLib, "VariantToStringArray")
   IF pVariantToStringArray THEN FUNCTION = pVariantToStringArray(pvar, prgsz, crgsz, pcElem)
END FUNCTION
' ========================================================================================


José Roca

#7
CVar - Variant class

A wrapper class to deal with variants.

The constructors and LET operators only admit a string, a variant or another CVAR because if, for example, you assign a value of 1, there is no way to know if the variant type of the target variant has to be byte, long, single, etc. Therefore, to assign or cast a numeric value you have to use the various vtxxx properties, e.g. vtLong, vtSingle, etc.


DIM cv AS CVAR
cv.vtLong = 12345
print cv.vtLong


With strings, you can use a constructor


DIM cv AS CVAR = "This is a test string"
print cv.Str


or the Str property


DIM cv AS CVAR
cv.Str = "This is a test string"
print cv.Str


When calling a function with an OUT variant parameter you will use the @operator


Foo @cv


When wanting to pass it by value, you will use


Foo cv


where Foo is the name of the procedure.

José Roca

#8
A default constructor for numbers could be added to allow to pass numbers by value to functions that have parameters declared as CVar, just as we can already do with strings, without having to declare first a variable as CVAR ans pass this variable. But which type to choose for the variant, double?

José Roca

#9
I have added two new constructors for numbers, one for LONGs and another for DOUBLEs, that are the ones most used in COM. For other types, dim a CVAR variable, assign the correct type and pass the variable.

José Roca

There is a way but implies the use of casting, eg. CLNG(12),

José Roca

#11
Be warned that this class is still evolving. I'm going to add new methods.

If the variant is of the type VT_ARRAY, I will add methods to return the number of dimensions of the underlying safe array, the lower and upper bounds, and if the underlying safe array is an array of variants, a method to get individual elements as a CVAR.

I will also add new constructors and operators for each data type, but if you pass a number instead of a variable, you will have to cast it with CLNG, CBYTE, etc.

This is going to be another great new data type. I'm already using it to implement an associative array of variants. Such an array can be added to CWindow to store all kind of indexed data available at any time from any part of the application.

If I ever implement a safearray class (a one-dimensional is not too difficult) we will have all we need to work with COM.

Marc Pons

#12
Jose

QuoteBecause the FB headers don't provide support for PropSys.dll

if you are still interrested i've managed to make the libpropsys.dll.a (32bits)
as i understood, James Fuller has already done a working 64bits version,
and with your propvautil.bi file you normally have everything to use propsys.dll,
without calling dynamically each function...

even in win xp ( wich does not have the propsys.dll), i've put a vista version in my system32

and tested like that (following your proposal on other post)

#include "windows.bi"
#include once "win/ole2.bi"


#INCLIB "propsys"

extern "Windows"

DECLARE FUNCTION VariantGetElementCount (BYVAL varIn AS VARIANT PTR) AS ULONG
DECLARE FUNCTION VariantToInt16(BYVAL varIn AS VARIANT PTR, BYVAL piRet AS SHORT PTR) AS HRESULT

end extern

PRIVATE FUNCTION VariantFromInt16(BYVAL iVal AS SHORT, BYVal pvar AS VARIANT PTR) AS HRESULT
pvar->vt = VT_I2
   pvar->iVal = iVal
   return S_OK
END FUNCTION




'CoInitialize NULL

DIM v AS VARIANT
VariantFromInt16(-32000,@v)
DIM n AS ULONG = VariantGetElementCount(@v)
DIM m AS short
VariantToInt16(@v, @m)
'CoUninitialize
print n
print m
sleep


i've also done tests with your propvautil.bi , its seems ok

here the attached file with libpropsys.dll.a and the def file used to make it

José Roca

#13
Thanks very much, but I no longer need it since I already have implemented the functions in CVar.inc. It has the advantage of not having to force the users of copying the libraries and includes to the FB lib and inc folders. Another advantage is not to have to deal with libraries, that I find annoying: one for 32 bit, another for 64 bit, one function exists in one library but not in the other...

IMO the best system is the one used by other BASICs, but with delay loading, that is what I have done. If implemented in the compiler, only declares will we needed, with a clause like "DELAY".

I have added constructors and operators for all the types, and several additional methods. Testing will tell us if more methods will be needed.

The attached file contains the current CVar.inc.


José Roca

And for testing it, I have written another class, CDicObj, that implements an associative array with variants.

Usage example:


#include "Afx/CDicObj.inc"
using Afx

' // Create an instance of the CDicObj class
DIM pDic AS CDicObj

DIM cv AS CVAR

pDic.Add "a", "Athens"
pDic.Add "b", "Madrid"
pDic.Add "c", "Roma"

print pDic.Count
print pDic.Exists("a")
print pDic.Item("a").Str

print "-------------"

DIM cvItems AS CVAR = pDic.Items
FOR i AS LONG = cvItems.GetLBound TO cvItems.GetUBound
   print cvItems.GetVariantElem(i).Str
NEXT

PRINT
PRINT "Press any key..."
SLEEP


As it uses variants, both the keys and items can be any type, and also can be mixed.

The code of CDicObj also demonstrates how to use CVar effectively.