Page 6 of 23
Posted: Sat May 23, 2009 11:45 am
by srod
WebRequestFactory is a .NET class so no you cannot translate that code to COMatePLUS.
Instead, use the MSXML2.XMLHTTP object and use the SetRequestHeader() method to set a referer.
E.g.
Code: Select all
myHTTPObject\Invoke("SetRequestHeader('referer', 'http://www.microsoft.com')")
etc.
(Untested.)
Posted: Sat May 23, 2009 12:00 pm
by besko
browser = COMate_WrapCOMObject(GetWindowLong_(GadgetID(BrowserID), #GWL_USERDATA))
If browser
If COMate_GetIIDFromName("DWebBrowserEvents2", @iid.IID) = #S_OK
browser\SetEventHandler(#COMate_CatchAllEvents, @BrowserEventProc(), 0, iid)
browser\Invoke("SetRequestHeader('referer', 'http://www.microsoft.com')")
browser\Release()
FreeObjects()
EndIf
Here?
edited:
Oh i cant use this with WebGadget?
Posted: Sat May 23, 2009 12:08 pm
by srod
No, that is a different object! The MSXML2.XMLHTTP object I referred to can be used to retrieve a webpage in text form; which was similar to what the VB.NET code you posted was doing.
If you wish to set some of the HTTP headers prior to the web-gadget retrieving a web-page then you will have to delve into the document object and set the headers prior to requesting a new page etc. I am pretty sure it can be done because I recall browsing through the required methods/properties some time ago.
I haven't time to write the code for you though.
Posted: Sat May 23, 2009 12:15 pm
by besko
Yes i wish to set some of the HTTP headers prior to the web-gadget

Posted: Sat May 23, 2009 2:09 pm
by srod
Here you are then Besko : (I found a bit of time)
Code: Select all
If OpenWindow(0, 302, 15, 600, 300, "WebGadget Header Test", #PB_Window_SystemMenu | #PB_Window_TitleBar )
WebGadget(#Web_Gadget, 20, 20, 560, 215, "")
ButtonGadget(#Button_Start, 20, 250, 110, 40, "Start")
browser = COMate_WrapCOMObject(GetWindowLong_(GadgetID(#Web_Gadget), #GWL_USERDATA))
EndIf
Repeat
EventID = WaitWindowEvent()
Select EventID
Case #PB_Event_Gadget
Select EventGadget()
Case #Button_Start
referer$ = "'referer : http://www.msn.com$000d$000a'" ;#CRLF$
browser\Invoke("Navigate('http://www.stardrifter.org/cgi-bin/ref.cgi', #empty, '_self', #empty, " + referer$ + ")")
EndSelect
EndSelect
Until EventID = #PB_Event_CloseWindow
browser\Release()
End
The website navigated to shows the referer which I have fooled into thinking the request came from MSN.
Note that javascript may fail to pick up this referer.
Note also that you can use the BeforeNavigate2 event to set the header; which may actually be a better place to do it - though I haven't tested that. Doing it in this event means that you can set the request header for every site visited etc.
===============================
@All COMatePLUS users : Please download COMatePLUS version 1.0.4 again as it fixes a very minor bug with the error reporting etc.
Posted: Sat May 23, 2009 4:39 pm
by besko
[16:51:07] [COMPILER] Line 18: The following variable doesn't have a 'Structure': browser.
your example works fine but in my code i have this error
---------------------------------------------------------------------
NOw all fine
Tnx Srod i am happy with you Man
Posted: Sat May 23, 2009 4:46 pm
by srod
Well there's something wrong with your code then!
My guess is that 'browser' has not been declared as a COMateObject etc.
Posted: Mon Jun 01, 2009 5:51 pm
by Xombie
I've searched and searched to no avail - is there an example for dumping an array (two dimensional preferably) into an Excel spreadsheet?
Posted: Mon Jun 01, 2009 11:38 pm
by srod
Here is a simple example.
Assuming you wish to be able to dump an array into a spreadsheet with a single method call, then you have to use a 2-dimensional SafeArray (aka - a pain in the arse!

) I have taken the required structures from mk-soft's VariantHelper.pb utility. Of course this utility will only deal with 1-dimensional SafeArrays, but the structures required are exactly the same.
In this example I set up a 2-dimensional SafeArray of signed integers, but you could as easily use a SafeArray of variants in order to populate a range of Excel cells with different types of data (integers, strings etc.) all in one go!
Once you have your array you can then populate an entire range of cells in your spreadsheet with a single method call.
Code: Select all
IncludePath "..\"
XIncludeFile "COMatePLUS.pbi"
;-Safe array structures - taken from "VariantHelper_Include.pb"
;==============================================================
Structure SAFEARRAYBOUND
cElements.l
lLbound.l
EndStructure
Structure SAFEARRAY
cDims.w
fFeatures.w
cbElements.l
cLocks.l
*pvData.pData
rgsabound.SAFEARRAYBOUND[0]
EndStructure
;-Set up a 2-d safearray of signed integers of dimensions 20 by 20.
;==================================================================
;Begin with an array of SAFEARRAYBOUND structures; one for each dimension.
Dim safeArrayBound.SAFEARRAYBOUND(2)
With safeArrayBound(0)
\lLbound = 1
\cElements = 20
EndWith
With safeArrayBound(1)
\lLbound = 1
\cElements = 20
EndWith
;Now create the array and check for success.
*safeArray.SAFEARRAY = SafeArrayCreate_(#VT_I4, 2, @safeArrayBound())
If *safeArray = 0
MessageRequester("COMate -Excel 2-d Safearray demo!", "Couldn't create the Safearray!")
End
EndIf
;Populate the array.
Dim indices(1)
For i = 1 To 20
For j = 1 To 20
indices(0) = i
indices(1) = j
temp = 20*(i-1)+j
SafeArrayPutElement_(*safeArray, @indices(), @temp)
Next
Next
;Bundle the Safearray up into a variant suitable for passing to a COM method.
Define var.VARIANT
With var
\vt = #VT_ARRAY|#VT_I4
\parray = *safeArray
EndWith
;-Fire up Excel and load cells from the array in one go.
;=======================================================
Define.COMateObject ExcelObject, WorkBook
ExcelObject = COMate_CreateObject("Excel.Application")
If ExcelObject
If ExcelObject\SetProperty("Visible = #True") = #S_OK
WorkBook = ExcelObject\GetObjectProperty("Workbooks\Add")
If WorkBook
ExcelObject\SetProperty("Range('A1:T20') = " + Str(var) + " as variant")
ExcelObject\Invoke("Quit()")
WorkBook\Release()
EndIf
EndIf
ExcelObject\Release()
Else
MessageRequester("COMate -Excel demo", "Couldn't create the application object!")
EndIf
;Now free the Safearray. Either use SafeArrayDestroy_() or VariantClear_() on any variant containing the array.
VariantClear_(var)
I hope it helps.
Posted: Tue Jun 02, 2009 9:18 am
by mback2k
I am running on a 32bit Windows 7, but I am unable to create a COM object for this interface:
Code: Select all
http://msdn.microsoft.com/en-us/library/dd378402(VS.85).aspx
This is my test code so far:
Code: Select all
#COMATE_NOINCLUDEATL = #True
IncludePath #PB_Compiler_Home+"COMatePLUS\"
IncludeFile "COMatePLUS.pbi"
IncludePath ""
Procedure.s StrGUID(*GUID.GUID)
Protected GUID$, Seperator$ = "-"
If *GUID
GUID$ = Right(Hex(*GUID\Data1), 8)
GUID$ + Seperator$+Right(Hex(*GUID\Data2), 4)
GUID$ + Seperator$+Right(Hex(*GUID\Data3), 4)
GUID$ + Seperator$+Right(Hex(*GUID\Data4[0]), 2)+Right(Hex(*GUID\Data4[1]), 2)
GUID$ + Seperator$+Right(Hex(*GUID\Data4[2]), 2)+Right(Hex(*GUID\Data4[3]), 2)+Right(Hex(*GUID\Data4[4]), 2)+Right(Hex(*GUID\Data4[5]), 2)+Right(Hex(*GUID\Data4[6]), 2)+Right(Hex(*GUID\Data4[7]), 2)
ProcedureReturn "{"+GUID$+"}"
EndIf
ProcedureReturn ""
EndProcedure
Interface IObjectArray
GetAt(uiIndex, riid, *ppv)
GetCount(*pcObjects)
EndInterface
Interface ICustomDestinationList
AbortList()
AddUserTasks(*poa.IObjectArray)
AppendCategory(pszCategory.p-unicode, *poa.IObjectArray)
AppendKnownCategory(category)
BeginList(*pcMinSlots, riid, *ppv)
CommitList()
DeleteList(pszAppID.p-unicode)
GetRemovedDestinations(riid, *ppv)
SetAppID(pszAppID.p-unicode)
EndInterface
Debug COMate_GetIIDFromName("ICustomDestinationList", @IID.GUID)
Debug StrGUID(@IID)
If OpenWindow(0, 100, 200, 195, 260, "PureBasic Window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
Debug COMate_CreateObject("ICustomDestinationList")
Debug COMate_GetLastErrorDescription()
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_CloseWindow
Quit = 1
EndIf
Until Quit = 1
EndIf
I get the following debug output:
Code: Select all
0
{6332DEBF-87B5-4670-90C0-5E57B48A49E}
0
Invalid progID/CLSID. Check your spelling of the programmatic identifier. Also check that the component / ActiveX control has been registered.
Any ideas? Thanks in advance.
Posted: Tue Jun 02, 2009 9:44 am
by srod
As far as I can see, this interface does not inherit from iDispatch which means that COMatePLUS will be of little use. COMatePLUS uses iDispatch automation and if an interface is not a dual interface then you are buggered!
However, if I am wrong, then you would need to try something like :
Code: Select all
GUID$ = StrGUID(@IID)
myObject.COMateObject = COMate_CreateObject(GUID$)
In your case we do not have a friendly ProgID for the object and so you can use the GUID in string form (with the curly braces etc.)
As I say though I do not think that COMatePLUS will help you in this case. Why not simply use CoCreateInstance_() and use the interface directly?
Posted: Tue Jun 02, 2009 9:47 am
by mback2k
Thanks, even the string form cannot be used to create the COM object. So I would like to use CoCreateInstance_(), but can you tell me how I do the following in PB, please?
Code: Select all
ICustomDestinationList *pcdl;
HRESULT hr = CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pcdl));
I am unable to find CLSID_DestinationList and I can't reproduce IID_PPV_ARGS.

Posted: Tue Jun 02, 2009 10:04 am
by srod
IID_PPV_ARGS looks like some kind of macro - I wouldn't worry about it and do things the long way!
You will need to look in the Win 7 sdk and the shobjidl.h header file for the required GUID's.
The GUID you report for IID_ICustomDestinationList looks incomplete! It does not have enough characters!
Once you have these use the following :
Code: Select all
pcdl.ICustomDestinationList
CoCreateInstance_(?CLSID_DestinationList, 0, #CLSCTX_INPROC_SERVER, ?IID_iCustomDestinationList, @pcdl)
with a suitable data section.
**EDIT : good luck with this. I shall not be online until tomorrow now so can be of no further help until then.

Posted: Tue Jun 02, 2009 10:39 am
by mback2k
Thanks. You are right, the GUID was too short, a 0 was missing. But even the full GUID doesn't help here. I am downloading the Windows 7 SDK at the moment.
Posted: Tue Jun 02, 2009 10:46 pm
by Xombie
srod - thanks for the code. I had to fiddle with it a bit to figure out how to work with strings rather than longs but it worked out great in the end.
Cheers!