josipradnik
2015-02-06, 08:53
There have been one thread ("Calling a method on a .NET COM Object") ending:
COM/ActiveX is working fine (We just tested against Excel). This is a .net specific COM issue.
http://www.lianja.com/community/showthread.php?1250-ActiveX-Controls-Does-not-Recognize-License
After digging C# find nothing suspicious there. VFP is calling the same .NET COM quit fine. Declaration in C# like this is enough for VFP to work with it. In Lianja it does not work.
[ComVisible(true)]
In Lianja same .NET object is created but every property is .F. and methods can not be called from Lianja. I can accept that creating such an object from Excel works. Maybe activex is another story.
But I have stuff made inside .NET DLLs which I do not want to re-program in Lianja (desktop app). And am not sure if it can be done yet (fiscalization and wild XML structures). That ,NET stuff is called within my VFP application without any problem. There is an article in VFP Help ("Visual FoxPro and Advanced COM") which helped me to make the workaround wrapper. Until Lianja team find solution for calling .NET methods.
Step #1
In Visual Foxpro you need to create a PRG called VFPCOM.PRG and save it.
define class VFPCOM as session olepublic
procedure docmd(ccmd as string) as variant ;
helpstring "Execute a VFP cmd"
&ccmd && just execute parm as if it were a fox command
function evalexpr(cexpr as string) ;
helpstring "Evaluate a VFP expression"
return &cexpr && evaluate parm as if it were a fox expr
function error(nerror, cmethod, nline)
comreturnerror(cmethod+' err#='+str(nerror,5)+;
' line='+str(nline,6)+' '+message(),_vfp.servername)
function dotnet(cdotnet as string, cproporfunc as string) ;
helpstring "Evaluate a .NET function or propery"
rr=createobject(cdotnet)
kk="rr."+cproporfunc
return &kk
enddefine
Step #2
Create another PRG in VFP (BUILDVFPCOM.PRG) and save it
*SET STEP ON
IF FILE("vfpcom.dll")
DECLARE integer DllUnregisterServer IN vfpcom.dll
DllUnregisterServer()
CLEAR DLLS
ENDIF
BUILD PROJECT vfpcomserver FROM vfpcom.prg
BUILD DLL vfpcomserver from vfpcomserver recomp
*now test this COM server:
ox = CreateObject("vfpcomserver.vfpcom") && create the server object
?"Time from server:"+ox.evalexpr("time()") && get the record count
Step #3
Run this second prg ( ! ). It will build DLL and test it.
Now you can play with it in VFP Command Window with 3 methods exposed.
977
We are here because of "dotnet". Others are for VFP stuff.
ox = CreateObject("vfpcomserver.vfpcom") && create the server object
?ox.dotnet('PLUS.Lider.LiderConfig','url2')
?ox.dotnet('PLUS.Lider.Client.LiderClient','DOTNET _buildverzija()')
?ox.dotnet('PLUS.Lider.Client.LiderClient','GetGUI D()')
First parameter is .NET class
Second is .NET class property or method
Step #4
After you get the calling .NET works in VFP, it is time to move to Lianja. In Lianja Console:
ed myvfpcomscript
and write something similar to my .NET (DLLs with [ComVisible(true)] and properly built)
ox = CreateObject("vfpcomserver.vfpcom") && create the server object
?ox.evalexpr("TIME()")
?ox.dotnet('PLUS.Lider.LiderConfig','url2')
?ox.dotnet('PLUS.Lider.Client.LiderClient','DOTNET _buildverzija()')
?ox.dotnet('PLUS.Lider.Client.LiderClient','GetGUI D()')
Then in Console
do myvfpcomscript
Or you can execute line by line.
Josip
COM/ActiveX is working fine (We just tested against Excel). This is a .net specific COM issue.
http://www.lianja.com/community/showthread.php?1250-ActiveX-Controls-Does-not-Recognize-License
After digging C# find nothing suspicious there. VFP is calling the same .NET COM quit fine. Declaration in C# like this is enough for VFP to work with it. In Lianja it does not work.
[ComVisible(true)]
In Lianja same .NET object is created but every property is .F. and methods can not be called from Lianja. I can accept that creating such an object from Excel works. Maybe activex is another story.
But I have stuff made inside .NET DLLs which I do not want to re-program in Lianja (desktop app). And am not sure if it can be done yet (fiscalization and wild XML structures). That ,NET stuff is called within my VFP application without any problem. There is an article in VFP Help ("Visual FoxPro and Advanced COM") which helped me to make the workaround wrapper. Until Lianja team find solution for calling .NET methods.
Step #1
In Visual Foxpro you need to create a PRG called VFPCOM.PRG and save it.
define class VFPCOM as session olepublic
procedure docmd(ccmd as string) as variant ;
helpstring "Execute a VFP cmd"
&ccmd && just execute parm as if it were a fox command
function evalexpr(cexpr as string) ;
helpstring "Evaluate a VFP expression"
return &cexpr && evaluate parm as if it were a fox expr
function error(nerror, cmethod, nline)
comreturnerror(cmethod+' err#='+str(nerror,5)+;
' line='+str(nline,6)+' '+message(),_vfp.servername)
function dotnet(cdotnet as string, cproporfunc as string) ;
helpstring "Evaluate a .NET function or propery"
rr=createobject(cdotnet)
kk="rr."+cproporfunc
return &kk
enddefine
Step #2
Create another PRG in VFP (BUILDVFPCOM.PRG) and save it
*SET STEP ON
IF FILE("vfpcom.dll")
DECLARE integer DllUnregisterServer IN vfpcom.dll
DllUnregisterServer()
CLEAR DLLS
ENDIF
BUILD PROJECT vfpcomserver FROM vfpcom.prg
BUILD DLL vfpcomserver from vfpcomserver recomp
*now test this COM server:
ox = CreateObject("vfpcomserver.vfpcom") && create the server object
?"Time from server:"+ox.evalexpr("time()") && get the record count
Step #3
Run this second prg ( ! ). It will build DLL and test it.
Now you can play with it in VFP Command Window with 3 methods exposed.
977
We are here because of "dotnet". Others are for VFP stuff.
ox = CreateObject("vfpcomserver.vfpcom") && create the server object
?ox.dotnet('PLUS.Lider.LiderConfig','url2')
?ox.dotnet('PLUS.Lider.Client.LiderClient','DOTNET _buildverzija()')
?ox.dotnet('PLUS.Lider.Client.LiderClient','GetGUI D()')
First parameter is .NET class
Second is .NET class property or method
Step #4
After you get the calling .NET works in VFP, it is time to move to Lianja. In Lianja Console:
ed myvfpcomscript
and write something similar to my .NET (DLLs with [ComVisible(true)] and properly built)
ox = CreateObject("vfpcomserver.vfpcom") && create the server object
?ox.evalexpr("TIME()")
?ox.dotnet('PLUS.Lider.LiderConfig','url2')
?ox.dotnet('PLUS.Lider.Client.LiderClient','DOTNET _buildverzija()')
?ox.dotnet('PLUS.Lider.Client.LiderClient','GetGUI D()')
Then in Console
do myvfpcomscript
Or you can execute line by line.
Josip