PDA

View Full Version : COM and Oxygen



Charles Pegge
06-08-2010, 19:41
These examples are included in the examples/COM folder.


Basic access to SAPI voice Interface




'-----------------------------------------
'SAPI VOICE
'=========================================


Uses "oxygen"
Dim src As String
src="
#basic
#include Voice.inc


'
'
'
' ###############
' ###################
' ### ###
' ### ### ###
' ### ## ## ###
' ### ## ## ###
' ### ## ## ###
' ### ## ## ###
' ### ## ## ###
' ### #### ## ###
' ### #### ###
' ### ###
' ### ###
' #############
' #########

CoInitialize(byval 0)

dim as GUID VoiceObjGuid, ISpVoiceGuid
dim as HRESULT hr
dim as ISpVoice ptr voice
dim as LPUNKNOWN pUnkOuter
dim as dword flags

const as PVOID NULL=0

guidval VoiceObjGuid, "96749377-3391-11D2-9EE3-00C04F797396"
guidval ISpVoiceGuid, "6C44DF74-72B9-4992-A1EC-EF996E0422D4"

& pUnkouter=0

hr=CoCreateInstance VoiceObjGuid, pUnkouter, context, ISpVoiceGuid, voice

if hr then print "SAPI Error " hex(hr) : jmp fwd done

voice.Speak w("Hello Everyone!"),flags,NULL
voice.WaitUntilDone &hFFFFFFFF
voice.Release
& voice=0

done:

CoUninitialize()

"
'msgbox 0,O2_prep src+o2_error
O2_asmo src
if Len(O2_ERROR) Then
msgbox 0,O2_ERROR
else
o2_exec
end if




OOPIFIED:




'=================================
'ATTACHING SAPI VOICE TO AN OBJECT
'=================================
'
'
' ###############
' ###################
' ### ###
' ### ### ###
' ### ## ## ###
' ### ## ## ###
' ### ## ## ###
' ### ## ## ###
' ### ## ## ###
' ### #### ## ###
' ### #### ###
' ### ###
' ### ###
' #############
' #########

Uses "oxygen"
Dim c,src As String
dim v as long
src="
#basic
#include Voice.inc
incl VoiceMacros
Connect voice
ErrorHandler jmp fwd done



'---------
class mind
'=========
memory as string
end class


'-----------
class person
'===========
ISpVoice * voice
has mind
'
method new()
memory="<>"
end method
'
method del()
memory=""
end method
'
method learn(string s)
memory+=s "<>"
end method
'
method recall(string s)
sys a,b,c
string r
a=instr(memory,s)
if a then
a+=len(s)
b=instr(a,memory,"<>")
end if
if a then
r=mid(memory,a,b-a)
else
r="I do not remember " s
end if
if & voice then
voice.speak w(r)
voice.WaitUntilDone forever
else
print r
end if
end method
'
end class

def Create
{
%1 %2
%2.new()
}

def CreatePersistent
{
%1 * %2
& %2=news sizeof %1
%2.new
}

def Delete
{
%1.del
frees & %1
& %1=0
}



'====
'MAIN
'====

CreatePersistent Person Hilda
Give Hilda voice
'Remove Hilda voice
Hilda.learn ".greeting. Hello Everyone"
Hilda.recall ".greeting."

Delete Hilda

'====
done:
'====

DisConnect voice


"
'msgbox 0,O2_prep src+o2_error
O2_asmo src
if Len(O2_ERROR) Then
msgbox 0,O2_ERROR
else
o2_exec
end if






Latest Oxygen


http://community.thinbasic.com/index.php?topic=2517


Charles

Petr Schreiber
06-08-2010, 21:01
Thanks Charles,

examples worked well here! I had a look at the code, there are some unbelieveable stunts. With proper documentation, Oxygen will be perfect.


Happy Petr

ErosOlmi
06-08-2010, 23:20
Chals,

you are doing an astonishing incredible work!
I agree with Petr: some documentation is needed not to vaste the great amount of work done and time spent.
You have an great product.

Eros

Charles Pegge
07-08-2010, 01:50
Thanks Petr and Eros,

You will find documentation in its raw state in o2keyw.bas. All the main keywords are coded in this file along with descriptive records which will be used to generate the manual in whichever format is desired. I'm continually adding new material to this file, and occasionally removing redundant keywords.

The syntax rules are still evolving - mostly towards reading C header files in their entirety.

Charles

Example


data "#case" ,-13, 41
'===========================

'action: specify mode of case sensitivity.
'use: case can be 'sensitive' insensitive' or 'capital'
example:
' #case insensitive 'AbC is the same as 'aBC' and 'ABC'
' #case sensitive 'AbC and 'abc' are not the same
' #case capital 'AbC is the same as 'aBC' but not 'ABC'
'remarks: The default is 'insensitive'.
' #case has block scope and reverts to its previous state when
' the block ends.

zak
07-08-2010, 08:58
thanks Charles for those examples, i have tried voice.Speak w(spk),flags,NULL with big texts assigned to string variable spk and it is working properly.
the compiler co2.exe in the new version seems not working. i have tried an older oxygen version downloaded in Mars-5-2010 and it is working such as compiling like this:
co2.exe fibo.bas to produce the standalone fibo.exe but not in the new version


#file "fibo.exe"
Function fibonacci(ByVal sequence As DWord) As DWord
If sequence < 2 Then
Function = sequence
Else Function = fibonacci(sequence - 1) + fibonacci(sequence - 2)
End If
End Function
Print fibonacci(30)
terminate

Charles Pegge
07-08-2010, 11:37
Hi Zak,

Yes I see the the problem. It is looking in the wrong locations for thinBasic_Oxygen.dll. If you place a copy of this in the same folder as your compiled EXE or DLL then it should work.

Meanwhile I will investigate why it loses the path.

Many thanks

Charles


PS: scripts compiling directly from thinBasic (#file "myprog.exe") do not manifest this problem.

Charles Pegge
07-08-2010, 14:54
I've fixed the problem.

There is a new instruction for explicitly configuring the Oxygen filepaths.

#o2paths

I have deployed this in CO2Maker:


Charles


#o2paths "
`.\thinBasic_oxygen.dll`? `lib\thinBasic_oxygen.dll`?
`..\thinBasic_Oxygen.dll`?
`..\lib\thinBasic_Oxygen.dll`?
`\thinbasic\lib\thinBasic_Oxygen.dll`?
`c:\thinbasic\lib\thinBasic_Oxygen.dll`? "

zak
07-08-2010, 17:34
Hi Charles
the new Oxygen co2.exe are working perfectly on windows 7, and i guess the same for vista,
just a report that in windows xp/sp2 it gives an error like in the attached picture, i have tried it on two computers with xp/sp2. but i do not know the situation with xp/sp3, i need someone else to confirm or not the situation with xp/sp3.
the older version downloaded in mars 2010 was working okay on xp/sp2.
regards

P.S:when we double click co2_maker.tbasic it will make co2.exe with a message compiled ok.
but using it will give the error as in the picture " co2.exe is not a valid win32 application"
the helloworld.exe in the picture is compiled using windows 7

Petr Schreiber
07-08-2010, 17:49
I tried the CO2 from SVN,

after launching co2_maker.tbasic it creates 4608 bytes big CO2, but when I try to launch it, it says it is not valid Win32 app on Windows XP SP3.
I tried to shutdown antivirus for a while, but with same results.


Petr

Charles Pegge
07-08-2010, 18:01
I will investigate!

I have pre-March versions stored away somewhere. I'm assuming the problem came in when I introduced 64 bit capability, so I will check the flag settings. Were you able to run these samples under XP2 previously?

Charles

zak
07-08-2010, 18:38
yes Charles, the co2.exe and the generated executables such as HelloWin1.exe was able to run okay on the xp/sp2 using the mars 2010 version
ps : sorry i will post after minutes the version which was running okay on xp

Charles Pegge
07-08-2010, 18:45
Thanks Zak. My earliest source code is 31 Mar 2010

Charles

zak
07-08-2010, 18:53
Charles here is the version which co2.exe works perfectly i have just tried it to compile fibo.bas and HelloWin1.exe, it may be from Feb 2010
http://rapidshare.com/files/411609054/thinBasic_Oxygen.zip

zak
07-08-2010, 20:36
Hi Charles
i have found on my hard disk the oxygen source code thinBasic_O2Source.zip + thinBasic_Oxygen.zip downloaded in 30 july 2009 togethor with the module
i hope it may be usefull
http://rapidshare.com/files/411623237/30_july_2009.rar

Petr Schreiber
07-08-2010, 22:00
I have pre-March versions stored away somewhere. I'm assuming the problem came in when I introduced 64 bit capability, so I will check the flag settings. Were you able to run these samples under XP2 previously?


I think so, but I am not sure to be fair. I did not played with stand alone compiler much yet.


Petr

Charles Pegge
07-08-2010, 22:31
This may take a while. I will post some test pieces ASAP

Charles.

zak
07-08-2010, 22:41
take your time Charles, since co2.exe is not an ingredient of the thinbasic installation with its modules, it is an add on.
the module are working okay within thinbasic on xp such as the posted examples sapi... etc.

Charles Pegge
07-08-2010, 23:08
Zak,

I am very glad you found the problem and described it. It is vital that Oxygen compiles successfully on all Windows 32/64 bit platforms.

Here is the first test for running under Windows XP or earlier. I would like to know if anyone else has problems in running HelloWin1 on these platforms.

I have made the PE Optional Header settings very close to those of FreeBasic compiled programs.


Charles

Charles Pegge
08-08-2010, 02:21
I think this is the right track because My Executive program which runs scripts directly without producing an EXE file is now working again.

So I have reposted Oxygen with these updates.

Charles :)

zak
08-08-2010, 07:09
thanks Charles
i have downloaded the new oxygen module from http://community.thinbasic.com/index.php?topic=2517,
i confirm that co2.exe are working correctly on win xp,
1- i double clicked on the file HelloWin1.tbasic ; the output is the hello world window and an executable HelloWin1.exe when i double clicked on it also produce the hello world wondow.
2- using co2.exe to compile *.bas files for producing the standalone exe's:
as an example using the fibo.bas listed in page one of this thread
co2.exe fibo.bas will produce fibo.exe which works on win xp.
many thanks Charles

Petr Schreiber
08-08-2010, 09:00
Worked good here :)

Charles Pegge
08-08-2010, 09:56
I am much relieved. Thank you both!

When PE files go wrong. The OS has no mercy.

Charles