fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

How to use External C++ dll 26 Aug 2019 16:06 #10404

  • hsc's Avatar

  • hsc

  • Topic Author


  • Posts: 126
  • Hi All,
    I want to implement an external C++ library into my application. I will write it in XSharp core dialect as a WPF Windows app. What a function to do from this library you would recommend?

    Juraj

    Please Log in or Create an account to join the conversation.

    How to use External C++ dll 26 Aug 2019 16:24 #10405

  • wriedmann's Avatar

  • wriedmann


  • Posts: 2300
  • Hi Juray,

    the C++ library comes in form of a DLL? And do you need only functions or also classes?
    Do you have tried to ask the vendor if he has also C# bindings?
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    How to use External C++ dll 26 Aug 2019 16:47 #10407

  • wriedmann's Avatar

  • wriedmann


  • Posts: 2300
  • Hi Juraj,

    the same rules apply for X# as for C#:
    stackoverflow.com/questions/772041/using-c-library-in-c-sharp
    stackoverflow.com/questions/2958416/call...ry-from-c-sharp?rq=1

    Basically it is the same situation as in VO (but since VO is written in C++, there is some documented but really complicated way to make it work nevertheless - please see "Using C++ DLLs" in the "How To" section of the VO help).

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    How to use External C++ dll 26 Aug 2019 17:47 #10409

  • hsc's Avatar

  • hsc

  • Topic Author


  • Posts: 126
  • Hi Wolfgang,

    Thank you for your response. From 1.1.2020 on-line cash register must be used in Slovakia. The EFox (on line cash register) manufacturer also ships this library with the hardware. I do not have more information from the manufacturer.
    In VO or Vulcan I use:

    _DLL FUNCTION BeginSaleReceipt(nHandle AS INT, cTransactionID AS STRING) AS INT
    PASCAL:EFoxComm.BeginSaleReceipt ANSI

    I wanted to see if there was another, better way.

    Juraj

    Please Log in or Create an account to join the conversation.

    How to use External C++ dll 26 Aug 2019 17:57 #10410

  • robert's Avatar

  • robert


  • Posts: 1793
  • Juraj,
    Try this

    STATIC CLASS EFox
    [DllImport("EFoxComm.dll")];
    STATIC METHOD BeginSaleReceipt(nHandle AS INT, cTransactionID AS STRING) AS INT
    END CLASS

    You can then call the function with EFox.BeginSaleReceipt(...)

    See also github.com/X-Sharp/XSharpPublic/blob/mas.../Functions/Win32.prg for an example

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Last edit: by robert.

    How to use External C++ dll 26 Aug 2019 18:19 #10412

  • hsc's Avatar

  • hsc

  • Topic Author


  • Posts: 126
  • Hi Robert,

    Thank for for your response.

    I use this code:

    USING System.Runtime.InteropServices

    STATIC CLASS EFox
    //
    [DllImport("eKasaEFoxComm.dll"];
    STATIC METHOD Abort(nHandle AS INT) AS INT
    //
    [DllImport("eKasaEFoxComm.dll"];
    STATIC METHOD BeginSaleReceipt(nHandle AS INT, cTransactionID AS STRING) AS INT
    //
    END CLASS

    Result:
    Error XS9002 Parser: unexpected input 'STATIC CLASS EFoxCRLF //[DllImport("eKasaEFoxComm.dll"]'

    Juraj

    Please Log in or Create an account to join the conversation.

    How to use External C++ dll 26 Aug 2019 18:23 #10414

  • hsc's Avatar

  • hsc

  • Topic Author


  • Posts: 126
  • Hi Robert

    in line

    [DllImport("EFoxComm.dll"];

    the right parenthesis was missing. My fault that I noticed it later

    Juraj

    Please Log in or Create an account to join the conversation.

    How to use External C++ dll 25 Jul 2020 20:27 #15328

  • Jean3riv's Avatar

  • Jean3riv


  • Posts: 2
  • Hi Robert
    I have not been able to call a function via a CLASS, even with your examples...
    However I have been able to call many functions to an external win32 DLL via the following code:
    //_________________

    [DllImport("Randomad32.dll")];
    _DLL FUNCTION MersenneRandomInitD ( IsEED AS INT ) AS VOID PASCAL:Randomad32.MersenneRandomInitD
    // Must be call before MersenneIRandomD() function
    // Must be called (ONLY 1 TIME) before you use the MersenneIRandomD() function, if this last function is
    //used many times in a loop. Otherwise there is very bad perfomance in speed.

    [DllImport("Randomad32.dll")];
    _DLL FUNCTION ReadTSC() AS INT PASCAL:Randomad32.ReadTSC
    // This function will generate the seed

    [DllImport("Randomad32.dll")];
    _DLL FUNCTION MersenneIRandomD( iMin AS INT , iMax AS INT ) AS INT PASCAL:Randomad32.MersenneIRandomD
    //This function to generate a number between Min and Max, it can be called many times into your own class or function

    //The DLL can be found here:
    //https://www.rayonline.com/jrinfo/downloads/randomad32.dll
    //______________________________
    Hope this will help somebody
    Best regards
    Jean Raymond
    rayonline.com/

    Please Log in or Create an account to join the conversation.

    How to use External C++ dll 26 Jul 2020 11:12 #15331

  • robert's Avatar

  • robert


  • Posts: 1793
  • Jean Raymond,
    The combination of DllImport and _DLL FUNCTION is not needed.
    _DLL FUNCTION will automacally generate the DllImport attribute

    Below is an example of DllImport in the XSharp.VO DLL.
    As you can see I am declaring strings with AS STRING and I am adding the CharSet attribute so the Marshalling code in the .Net runtime know that string needs to be converted from Unicode to Ansi
    STATIC CLASS XSharp.Win32
         CONST SW_SHOWNORMAL  := 1 AS LONG 
        [DllImport("kernel32.dll", CharSet := CharSet.Ansi )];
        STATIC METHOD WinExec(lpCmdLine AS STRING, uCmdShow AS DWORD) AS DWORD
        [DllImport("kernel32.dll" )];
        STATIC METHOD GetCurrentProcess() AS IntPtr 
        [DllImport("kernel32.dll" )];
        STATIC METHOD VirtualQueryEx(hProcess AS IntPtr, lpAddress AS IntPtr, ;
            lpBuffer AS _WINMEMORY_BASIC_INFORMATION, dwLength AS DWORD) AS DWORD PASCAL
    END CLASS


    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Last edit: by robert.
    • Page:
    • 1