Page 1 of 3 123 LastLast
Results 1 to 10 of 27

Thread: Use of DLL written with c#

  1. #1
    Senior Member
    Join Date
    Feb 2012
    Location
    Rome - Italy
    Posts
    1,862

    Use of DLL written with c#

    Hi all,
    I need to use a DLL written with c#.
    Can I use it directly on Lianja?

    thanks
    Fabio

  2. #2
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    5,732
    Hi Fabio,

    No. .net dlls requires the .net clr.

    They are not the same as normal (unmanaged) windows dlls.

    One solution is to create your own .net dll and enable COM Interop. That should then be able to be used with ActiveX.

    See microsoft doc,
    https://docs.microsoft.com/en-us/dot...ponents-to-com
    Last edited by barrymavin; 2020-01-30 at 23:22.
    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 MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,099
    Hi Fabio,

    Here is how I managed to use C# DLL with a little help of VFP (desktop app):
    https://www.lianja.com/community/sho...nja-Workaround

    Josip

  4. #4
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    5,732
    Hi Josip,

    As I pointed out in that old thread.

    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

    If you SET DEBUG ON and issue a createObject("...") in the console you can look in the debug file. Chances are the methods are not decorated properly, but that's not a show stopper, there is a another way to call those methods...

    obj = createObject("...")
    obj.dynamicCall( args... );
    Last edited by barrymavin; 2020-01-31 at 02: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

  5. #5
    Senior Member
    Join Date
    Feb 2012
    Location
    Rome - Italy
    Posts
    1,862
    Hi Barry, thanks for your suggestion, now I try to read the MS doc.
    meanwhile, I'm tryng the Josip sulution.

    I've created the project and compiled the DLL on my VFP machine and the sample work fine:
    Code:
    ox = CreateObject("vfpcomserver.vfpcom")    && create the server object
    ? "Time from server:" + ox.evalexpr("time()")    && get the record count
    Now, I've copied vfpcomserver.* files to my Lianja Dev machine, into "C:\lianja\library" folder.

    then I've try to:
    Code:
    set defa to C:\lianja\library
    ox = CreateObject("vfpcomserver.vfpcom")
    but I get this error:
    Fri Jan 31 01:49:03 2020
    **** Lianja error ****
    ox = CreateObject("vfpcomserver.vfpcom")
    ^
    CLASS 'vfpcomserver.vfpcom' not found

    what I'm wrong?

    thanks
    Fabio

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

    This solution is for

    DO vfpcomserver.prg

    on the same machine where you will CREATEOBJ and use it.

    VFP was doing COM registration with regsvr32 for you.
    Otherwise, you need to manualy register this COM DLL on the new machine with copied dll.

    Something like that:

    "%~d0\gacutil.exe" /i "%~d0\Interop.vfpcomserver.dll"
    "%SystemRoot%\Syswow64\regsvr32.exe" /i /s "%~d0\vfpcomserver.dll"

    (check where your gacutil.exe and regsvr32.exe are located. Be aware of tilda simbols right after %, not hyphen as forum post automatically transcribes.)

    Last edited by josipradnik; 2020-01-31 at 04:24.

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

    In VFP

    Name:  Screenshot - 31.01.2020. , 10_23_07.png
Views: 37
Size:  50.1 KB


    ... after DO BUILDVFPCOM.PRG in VFP console (see time shown)

    ...testing the object in VFP:

    Name:  Screenshot - 31.01.2020. , 10_25_49.png
Views: 36
Size:  12.9 KB

    Using it in Lianja console

    Name:  Screenshot - 31.01.2020. , 10_28_44.png
Views: 37
Size:  17.1 KB



    And C# (DLL) code was:

    Name:  Screenshot - 31.01.2020. , 11_04_13.png
Views: 36
Size:  8.2 KB

    Name:  Screenshot - 31.01.2020. , 11_05_44.png
Views: 36
Size:  6.0 KB
    Last edited by josipradnik; 2020-01-31 at 04:18.

  8. #8
    Senior Member
    Join Date
    Feb 2012
    Location
    Rome - Italy
    Posts
    1,862
    Hi Josib,
    many thanks, I try as soon as possible.

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

    I had a problem with your second link (maybe because this is MSDN blog, and my MSDN subsription is expired).
    For others interested in, here is the correct link:
    https://docs.microsoft.com/en-us/arc...x-control-in-c

    I did not know about dynamicCall function.

    In this scenario I can get it to work in Lianja if it is the procedure in VFP code without parameters (not for .NET part):

    Name:  Screenshot - 31.01.2020. , 11_47_49.png
Views: 37
Size:  50.9 KB

    Code:
    ox2 = CreateObject("vfpcomserver2.vfpcom2")    && create the server object
    ?ox2.dynamicCall('foxproc1')  && proc without parameters, with HOME(1)
    D:\Program Files (x86)\Microsoft Visual FoxPro 9\

    But not when there are parameters (foxproc2) no matter how I define types of parameters, as strings or as integers.
    The result is always
    .F.

  10. #10
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    5,732
    As I mentioned, you need to SET DEBUG ON before you issue the createObject(). The method signatures can be seen in the debug file. The signature is the firstly parameter to dynamicCall().

    By looking at the signatures you can see what the ActiveX exposes.
    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

Page 1 of 3 123 LastLast

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