where I could find examples of O2 code for Msxml2.XMLHTTP.6.0
example
#import "msxml6.dll"
using namespace MSXML2;
void XMLHttpRequestSample()
{
IXMLHTTPRequestPtr pIXMLHTTPRequest = NULL;
BSTR bstrString = NULL;
HRESULT hr;
try {
hr=pIXMLHTTPRequest.CreateInstance("Msxml2.XMLHTTP.6.0");
SUCCEEDED(hr) ? 0 : throw hr;
hr=pIXMLHTTPRequest->open("GET", "http://localhost/books.xml ", false);
SUCCEEDED(hr) ? 0 : throw hr;
hr=pIXMLHTTPRequest->send();
SUCCEEDED(hr) ? 0 : throw hr;
bstrString=pIXMLHTTPRequest->responseText;
MessageBox(NULL, _bstr_t(bstrString), _T("Results"), MB_OK);
if(bstrString)
{
::SysFreeString(bstrString);
bstrString = NULL;
}
} catch (...) {
MessageBox(NULL, _T("Exception occurred"), _T("Error"), MB_OK);
if(bstrString)
::SysFreeString(bstrString);
}
}
"VBA code"
Set Site = CreateObject("MSXML2.XMLHTTP.6.0")
Site.Open "GET", strUrl, False
Site.send
tjoson = Site.responseText
What language is that? Is it .net code?
https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms759148(v%3Dvs.85)
c, but I just want some example for O2, and being able to have a base, I could not find anything related
If you look into Oxygen basic forum you may found IUP
example for o2 ,i think that John posted about it.
And my small example for ATL..very trivial.
Also look here on Jose Examples for web(ATL browser..i think) and similar.
Zlatko Vid
Thank you, I'll take a look,
I just need to get a json and pass it to an array
json is as far as i know javaScript ..right?
so you need html control to produce something with js
and of course control which support java script.
Eduardo
I just looking into open source html control called mCtrl
which have great things.it is 32 and 64 bit in a form of .dll
written in C ,so you can connect it with any windows app
i must invesigate this more...
Zlatko Vid
json is just a text file
in the case here, it is only to use a handful of if within a for loop.
an example of json
http://data.ny.gov/resource/d6yy-54nr.json
with Msxml2.XMLHTTP, the text file can be obtained directly, and just work the file directly
ok
i see but still you need protocol to xml.control
i don't think that someting similar is in any example of o2 but
because i am not very much interested for that I might be wrong.
you must wait for Charles respond...
I think there is no way to do it easily in O2,
so I read the O2 has no implementation use COM
I do not even know where to start
is not quite an important demand, what I did in vba works well, I just wanted to try something on O2 without depending on excel and vba
We need some expertise in scripting-com, but o2 now has the infrastructure to support variants.
From the dregs of my poor memory I believe Excel is notorious for not following the COM norm making it a bear to code outside of the vba environment.
James
WebBrowser, Excel, scripting-COM... OMG
All you need is an interface declaration (something like)
'--------------------
class IXMLHttpRequest
'====================
public
extends IDispatch
HRESULT open(BSTR bstrMethod,BSTR bstrUrl,VARIANT varAsync,VARIANT bstrUser,VARIANT bstrPassword)
HRESULT setRequestHeader(BSTR bstrHeader,BSTR bstrValue)
HRESULT getResponseHeader(BSTR bstrHeader,BSTR *pbstrValue)
HRESULT getAllResponseHeaders(BSTR *pbstrHeaders)
HRESULT send(VARIANT varBody)
HRESULT abort(void)
HRESULT get_status(LONG *plStatus)
HRESULT get_statusText(BSTR *pbstrStatus)
HRESULT get_responseXML(IDispatch **ppBody)
HRESULT get_responseText(BSTR *pbstrBody)
HRESULT get_responseBody(VARIANT *pvarBody)
HRESULT get_responseStream(VARIANT *pvarBody)
HRESULT get_readyState(LONG *plState)
HRESULT put_onreadystatechange(IDispatch *pReadyStateSink)
end class
guidval CLSID_XMLHTTP60, "88D96A0A-F192-11D4-A65F-0040963251E5"
guidval IID_IXMLHTTPRequest, "ED8C108D-4349-11D2-91A4-00C04F7969E8"
And then the usual way of using low-level COM:
CoInitialize NULL
CoCreateInstance(...)
Call the appropriate methods
CoUninitialize
Thanks José,
I am puzzled why variants are often passed byval though.
QuoteI am puzzled why variants are often passed byval though.
Charles
I think they are just another name for integer pointers.
- Aurel
No, they aren't another name for integer pointers. They're variants passed by value.
They are 16 byte structures (24 bytes in x64) so its strange to see them loaded straight onto the stack. UDTs are rarely passed directly.
In the beginning of COM programming, variants and guids (both 16-byte structures) were always passed by reference. Later, they decided that it was more convenient to pass them by value. Variants and guids can also be returned as the result of a method, although different languages do it well... differently, because it's never too late to create incompatibilities. I think that Microsoft C++ compilers return them in the stack. Delphi and GCC, I don't know.
So you can find old rechnologies, like the Dictionary Object, whose methods are byref variants (guess that it was because VB Script was not able to deal by byval variants at that time), and more recent technologies and the .Net Framework, that, in general, only uses byref variants and guids for out parameters and byval for in parameters.
It gets messy with MS64.
Variants inflate to 24 bytes due to their non-optimal structure, which gets padded out according to the standard C type-alignment rules.
Then the MS64 calling convention requires the 1st 4 (non-float) params to be passed in RCX,RDX,R8,R9 (8 bytes each). The remainder of the params must be stored within a stack frame before making the call.
The base of the stack frame (value in RSP) must be kept 16-byte aligned.
So we have to struggle with some very poor design decisions in the system.
Jose
I don't want to argue with you because you have lot more experience than me in such a things
BUT
i was not completely in wrong
from wiki-diki
In Visual Basic (and Visual Basic for Applications) the Variant data type is a tagged union
so ...if is union then is UDT, if is UDT then is some sort of pointer
so .. if i understand it each time we create variant we also create some sort of union structure.
again ...i am not very smart in that stuff ..so i just follow the logic. ;D
i think ..
all best ...Aurel
An UDT is not a pointer, but a composite data type. A Variant is an structure which has a member that is an Union.
When the parameter is byref variant, you pass a pointer to that structure, but when it is byval, you have to push all the members of that structure into the stack. As Charles has pointed, it is not difficult to do with 32 bit, but it is messy with 64-bit.
Besides, the methods get_responseBody and get_responseStream return a Variant as the result, not a pointer to a Variant.
I see this is how variants are returned in C/C++
The first param (after the invisible
this) is a variant reference. The caller must create a variant to receive the return value.
I have already adopted a similar scheme for all direct UDT returns, with invisible returns variables..
Quote
Visual Basic Syntax
strValue = oServerXMLHTTPRequest.responseBody
C/C++ Syntax
HRESULT get_responseBody(VARIANT* pvarVal);
https://msdn.microsoft.com/en-us/windows/ms753682(v=vs.71)
> The first param (after the invisible this) is a variant reference. The caller must create a variant to receive the return value.
This applies when using low-level COM, that almost always returns an HRESULT value as the result of a method, but not when using automation languages. Anyway, O2 does not support COM Automation, so O2 users must learn that they can't use something like bstrString=pIXMLHTTPRequest->responseText;
QuoteWhen the parameter is byref variant, you pass a pointer to that structure, but when it is byval, you have to push all the members of that structure into the stack. As Charles has pointed, it is not difficult to do with 32 bit, but it is messy with 64-bit.
Hi Jose
Thank you , i hope that i understand it now..
if I understand, it is not possible to use with O2
So is there an interface for getting files, or reading, working the html of a web page?
There is an o2 folder: examples\system\winsock containing 2 examples of low-level internet access.
thank you Charles
I looked at Dict_Send_Receive.o2bas but it seems to be very advanced for me
I found Wininet to be be quite friendly. This is how to get a web page, and file it:
extern lib "wininet.dll"
! InternetOpenA
! InternetOpenUrlA
! InternetCloseHandle
! InternetReadFile
end extern
string buf=nuls 100000
string url="https://www.oxygenbasic.org/index.html"
int cbytes
sys hInternet
sys hFile
hInternet = InternetOpenA( "o2demo",0,0,0,0 )
hFile = InternetOpenUrlA( hInternet,url,0,0,0,0 )
InternetReadFile( hFile,buf,len(buf),@cbytes )
InternetCloseHandle( hFile )
InternetCloseHandle( hInternet )
print left( buf,500 )
putfile( "t.txt",left(buf,cbytes) )
NOTES:
======
'https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetopena
'https://docs.microsoft.com/en-us/cpp/mfc/wininet-basics?view=vs-2019#_core_create_a_very_simple_browser
/*
% INTERNET_OPEN_TYPE_DIRECT 1
% INTERNET_FLAG_ASYNC 0x10000000
*/
/*
extern lib "wininet.dll"
sys InternetOpenA(
LPCSTR lpszAgent,
DWORD dwAccessType,
LPCSTR lpszProxy,
LPCSTR lpszProxyBypass,
DWORD dwFlags
);
BOOLAPI InternetCloseHandle(
HINTERNET hInternet
);
BOOLAPI InternetCanonicalizeUrlA(
LPCSTR lpszUrl,
LPSTR lpszBuffer,
LPDWORD lpdwBufferLength,
DWORD dwFlags
);
sys InternetOpenUrlA(
HINTERNET hInternet,
LPCSTR lpszUrl,
LPCSTR lpszHeaders,
DWORD dwHeadersLength,
DWORD dwFlags,
DWORD_PTR dwContext
);
BOOLAPI InternetReadFile(
HINTERNET hFile,
LPVOID lpBuffer,
DWORD dwNumberOfBytesToRead,
LPDWORD lpdwNumberOfBytesRead
);
BOOLAPI InternetFindNextFileA(
HINTERNET hFind,
LPVOID lpvFindData
);
*/
'#include <afxinet.h>
/*
void DisplayPage(LPCTSTR pszURL)
{
CInternetSession session(_T("My Session"));
CStdioFile* pFile = NULL;
CHAR szBuff[1024];
//use a URL and print a Web page to the console
pFile = session.OpenURL(pszURL);
while (pFile->Read(szBuff, 1024) > 0)
{
printf_s("%1023s", szBuff);
}
delete pFile;
session.Close();
}
*/
Thank you, Charles.
is basically what I need, I just do not understand why it does not grab all the content.
for most Json I'm going to use is 100% because they are small but some are of indefinite size
I tested this
http://data.ny.gov/resource/d6yy-54nr.json
and does not take all content
> is basically what I need, I just do not understand why it does not grab all the content.
This is because the buffer is too small.
There are likely to be limits on the internal read-buffer. So it may take a few ReadFile calls to get the complete web page/file. Perhaps I'm being over-cautious :)
No buffer limits:
extern lib "wininet.dll"
! InternetOpenA
! InternetOpenUrlA
! InternetCloseHandle
! InternetReadFile
string buf=nuls 0x20000 '128k
string tbuf
string url="https://www.oxygenbasic.org/index.html"
int cbytes
sys hInternet
sys hFile
int c
hInternet = InternetOpenA( "o2demo",0,0,0,0 )
hFile = InternetOpenUrlA( hInternet,url,0,0,0,0 )
do
cbytes=0
InternetReadFile( hFile,buf,len(buf),@cbytes )
if cbytes
tbuf+=left(buf,cbytes)
c++
else
exit do
endif
loop
InternetCloseHandle( hFile )
InternetCloseHandle( hInternet )
'print tbuf
putfile( "t.txt",tbuf )
'print c 'readfile loops
improved loop!
Yes, it worked perfectly
Is it advisable to use the other for those of limited size or can this be used for everyone without problems?
It's amazing how there are so many different tools and ways of doing the same task
only years of dedication and a mind capable of assimilating all this
Many thanks Charles
It will work for all sizes, and it is optimizable.
I've also improved the loop.
cool
can I use the same method to download zip files?
may be interesting a ".inc" for use on the web, after all today everything is captured and sent to the big network
"The internet here is horrible today"
It should work. Both http and ftp protocols are supported, (ftp files could be of any type).
Thanks, Charles.
I can probably do things by myself, I'm off here looking for examples and doing tests.
most changes little of how I do in vba
Charles, it might be a good idea to put a separate folder in github to put new examples and .inc files, so you could organize better, besides having a range of examples located without having to change the zip of O2
Hello Charles , Jose, Eduardo
i found the below code from PB about cursor browser
https://forum.powerbasic.com/forum/jose-s-corner/discussion/763266-big-browser-cursor (https://forum.powerbasic.com/forum/jose-s-corner/discussion/763266-big-browser-cursor)
can this be converted to O2 ?
#Compile Exe
#Dim All
%Unicode = 1
%UseWebBrowser = 1 ' // Use the WebBrowser control
#Include Once "CWindow.inc" ' // CWindow class
%IDC_WebBrowser = 1001
Global hDlg, hBrowser, hCursor As Dword, OldProc&, pWindow As IWindow
Function PBMain
Dialog New Pixels, 0, "WebBrowser", , , 800, 600, %WS_OverlappedWindow To hDlg
pWindow = Class "CWindow"
hBrowser = pWindow.AddWebBrowserControl(hDlg, %IDC_WEBBROWSER, "http://www.powerbasic.com",Nothing, 0, 0, 600,400)
Dialog Show Modal hDlg, Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case CbMsg
Case %WM_InitDialog
hCursor = LoadImage (ByVal 0, "c:\windows\cursors\larrow.cur", %IMAGE_ICON, 125, 125, %LR_LOADFROMFILE)
OldProc& = SetWindowLong(hBrowser, %GWL_WndProc, CodePtr(NewProc)) 'subclass
Case %WM_SetCursor
SetCursor hCursor
Function = 1
Case %WM_Destroy
SetWindowLong hBrowser, %GWL_WNDPROC, OldProc& 'un-subclass
End Select
End Function
Function NewProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case Msg
Case %WM_SetCursor
SetCursor hCursor
Function = 1
Exit Function
End Select
Function = CallWindowProc(OldProc&, hWnd, Msg, wParam, lParam)
End Function
Yes it could be if you have
CWindow.inc from powerBasic translated to o2 inc.
I consider that, more than adapting lines of code of the PB, it has to determine direct examples with the own O2
start with simple and commented examples
o2 is very versatile in its syntax, but it also seems to be its weakest link
passing from the vba to him
ReDim Arrayindice (100) the string, and was giving errors within parts of the code
ReDim string Arrayindice (100), and it worked
ReDim string Arrayindice (C), I do not understand why it is necessary to define string of a variable that had already been defined,
the biggest failure for me is wanting to lean on other platforms, O2 is already consistent to follow with his own legs, and define a proper authority
I also noticed that simple codigo that works perfectly in 32bit hangs in 64bit
ainda apanhando para escrever algo
extern lib "wininet.dll"
! InternetOpenA
! InternetOpenUrlA
! InternetCloseHandle
! InternetReadFile
string buf=nuls 0x20000 '128k
string tbuf
string url="http://data.ny.gov/resource/d6yy-54nr.json"
int cbytes
sys hInternet
sys hFile
int c
hInternet = InternetOpenA( "o2demo",0,0,0,0 )
hFile = InternetOpenUrlA( hInternet,url,0,0,0,0 )
do
cbytes=0
InternetReadFile( hFile,buf,len(buf),@cbytes )
if cbytes
tbuf+=left(buf,cbytes)
c++
else
exit do
endif
loop
InternetCloseHandle( hFile )
InternetCloseHandle( hInternet )
string Saida
Dim Arraydados(4) as string
Dim L As int, C As int, cc As int, tt As int, s as char,s2 as string
dim ch,ch2 as int
tt = Len(tbuf)
C = 1: L = 1
For cc = 1 To tt
s = Mid tbuf, cc, 1
If s = chr(34) Then 'para as aspas (")
If ch2 = 0 Then ch2 = 1 Else ch2 = 0
GoTo PULA
End If
If ch2 = 0 Then
If s = "," Then C = C + 1: L = 1: GoTo PULA
If s = ":" Then L = 2: GoTo PULA
'If s = "{" Or s = "}" Then GoTo PULA
End If
If s = "{" Then GoTo PULA
'If s = chr(13) Then 'Enter
If s = "}" Then
s = Mid tbuf, cc+1, 1
saida=saida & left(Arraydados(1),10) & " ; " & Arraydados(2) & " ; " & Arraydados(3) & s
Arraydados(1)="" : Arraydados(2)="" : Arraydados(3)=""
c=0: GoTo PULA
end if
If s = "[" or s = "]" Then GoTo PULA
If L = 2 Then
Arraydados(C) = Arraydados(C) & s
End If
PULA:
Next
putfile( "t2.txt",saida )
putfile( "t1.txt",tbuf )
ainda apanhando para escrever algo
he he ...i don't get it..
EDuardo you must learn o2 code
there is no just copy from other dialect...
but what is the default of O2?
is the basic C standard?
As I said, O2's strongest point is its virtually free syntax, and it's also its weakest point.
In the case of "REDIM", note that it is accepted to declare variables with "DIM x AS LONG", not that I prefer to use this mode, but I hope that accepting a mode using dim is also suitable for REDIM, and the error appeared in another line. took longer to know where it was
I had commented before that I would prefer syntax blocks, to force the chosen syntax avoiding typos
to me, C's bad point is his "symbolism" {}; && ++! = ... I couldn't get used to it, I don't miss Gosub so much despite having certain uses,
but for me End if, Next .., is paramount to locate me in the logic of what I'm doing
Having so many ways to declare variables as I see it is only useful for reusing code, because writing something from scratch is the most important thing.
The simpliest way to declare variables in 02 is
INT a,s,d,f,g,h
STRING q,w,e,r,t,z
FLOAT x,y,c,v,b
INT arr1[100] : STRING s[200] : FLOAT x[300]
as you can see there is no need to use DIM
Yes I know,
as I said the possibility of so many methods is only useful for reusing lines of code without having to rewrite
but this feat has to be consistent, or at least show syntax error on the right line and not elsewhere
I wouldn't mind if O2 had only one method of declaring variables that would just force manually declaring without being able to paste ready-made codes
would even be good because it would make O2 independent of other languages and make it easier for Charles
Quote from: Eduardo Jorge on July 27, 2019, 03:35:07 PM
I wouldn't mind if O2 had only one method of declaring variables that would just force manually declaring without being able to paste ready-made codes
would even be good because it would make O2 independent of other languages and make it easier for Charles
Maybe a #SYNTAX=[O2] statement ??
James
James C. Fuller
Yes, it would be interesting and something less permissive
I noticed that the values are explicit in the generated code
I think it would be interesting to code to prevent others from exchanging these texts so easily
like a link, someone malicious could link to a malicious page very easily
I am trying to add the encrypted values and a function that will decrypt for use, of course I can only do this simply and inefficiently for those who know the subject
I want to build some simple programs but that has a certain requirement
so I thought of putting a link to the O2 page as an advertisement,
Is there a way to insert a link and open it through their default browser?