Results 1 to 3 of 3

Thread: .NET COM in Lianja - Workaround

  1. #1
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,099

    .NET COM in Lianja - Workaround

    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/show...ognize-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.
    Code:
      [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.

    Code:
    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

    Code:
    *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.
    Name:  _SP32-20150206-133836.jpg
Views: 103
Size:  5.6 KB

    We are here because of "dotnet". Others are for VFP stuff.

    Code:
    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','GetGUID()')
    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:

    Code:
    ed myvfpcomscript
    and write something similar to my .NET (DLLs with [ComVisible(true)] and properly built)

    Code:
    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','GetGUID()')
    Then in Console
    Code:
    do myvfpcomscript
    Or you can execute line by line.

    Josip
    Last edited by josipradnik; 2015-02-06 at 08:00.

  2. #2
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    5,770
    If the .net DLL is properly built for COM interop then SET DEBUG ON and look in debug_client.txt to see what methods are being exposed.

    Also make sure the .net dll is registered and that it is 32 bit as Lianja runs as a 32 bit application.

    You should also try accessing it using its GUID {....} and experiment to see which access method works best after registering the dll with regasm.
    Last edited by barrymavin; 2015-02-06 at 10:52.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  3. #3
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    5,770
    My initial thoughts on this are that the .net dll is not exposing the methods as they are missing the correct decorators.

    At first I thought maybe it was because it is a non UI object but then VFP OLEDB works fine so I ruled that out.

    You will need to investigate the .net dll and how it is being built and registered on the machine.

    This thread in stack overflow may help you create a .net dll that is properly enabled for COM Interop.
    http://stackoverflow.com/questions/7...erop-component

    EDIT: ComVisible(true) needs to be on the class AND the methods.
    http://blogs.msdn.com/b/asiatech/arc...trol-in-c.aspx
    Last edited by barrymavin; 2015-02-07 at 01:46.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Journey into the Cloud
Join us