Home Forums HTBasic Forum about call dll-C and CSharp

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #9368
    Dongxu Li
    Participant

      Hello Sir,
      I have an issue during call dll with HTBasic version v9.20. The program is like below. CppCLINETAssemblyWrapper.dll is programmed by C. I can DLL LOAD and DLL GET in CppCLINETAssemblyWrapper.dll successfully. In this CppCLINETAssemblyWrapper.dll it calls another dll(programmed by CSharp, all source code are in CSharp dll,CppCLINETAssemblyWrapper.dll just an interface to HT Basic). Then it is crashed during call FNHtb_cropto(String_in2$,String_in$,Ret$,Ok).
      Could you please tell me if this method is ok or not? HT Basic—>dll(C program)—>dll(CSharp program)
      thanks a lot.

      DLL UNLOAD ALL
      DIM Org_msi$[999]
      DIM Ret$[256],String_in$[256],String_in2$[256]
      INTEGER Ret,Ok
      Org_msi$=SYSTEM$(“MSI”)
      MASS STORAGE IS “D:\DLL_frames\”
      DLL LOAD “CppCLINETAssemblyWrapper”
      DLL GET “SHORT CppCLINETAssemblyWrapper:BTBasic_DLL_Call” AS “Htb_cropto”
      IF NOT POS(SYSTEM$(“VERSION:HTB”),”RUNTIME”) THEN LIST DLL
      String_in$=”3|2|1″
      String_in2$=”Sum”

      Ret=FNHtb_cropto(String_in2$,String_in$,Ret$,Ok) !call another dll(C sharp programed)

      END

      public int BTBasic_DLL_Call(string functionName, string parameters, ref string returnString, ref int returnNumber)

      #9369
      Dongxu Li
      Participant

        Hello,
        I update my question to make you better understand.
        BASIC language programs need to call a class library written in C#. We created an intermediate DLL with a C language interface using C++/CLI. BASIC program—>dll(C++/CLI with C interface)—>dll (C# program). This solution works fine on ICT devices with BT BASIC , but fails to execute on programs written in HT BASIC language. Any suggestions on what to do?
        thanks a lot.

        #9370
        PatB
        Moderator

          Hi Dongxu,

          I setup a similar test where I created an unmanaged C++ dll and from it called into a managed C# dll. Loading the unmanaged C++ dll from HTBasic and calling the unmanaged function that calls into the managed dll, I was able to reproduce the same exception you are seeing. I have spent some time looking into it and finally found a solution. There were two steps I needed to take before i was able to call the unmanaged dll function from HTBasic successfully.

          First, make sure that your unmanaged DLL and Managed DLL are both targeting x86 since that is what HTBasic targets.

          Second, put the managed dll into the same folder that the HTBwin.exe file is in.

          Hopefully this will allow it to work for you.

          Thanks,

          Pat

          #9373
          Aimaz Arain
          Participant

            Hello,

            It looks like you’re experiencing a challenging issue with calling a C# DLL through a C++ wrapper in HTBasic. Here are a few suggestions that might help you resolve this:

            Compatibility: Ensure that the C++ DLL (CppCLINETAssemblyWrapper.dll) and the C# DLL are compatible with each other and the HTBasic environment. Make sure the data types and calling conventions match between HTBasic, the C++ DLL, and the C# DLL.

            Debugging: Verify that the C++ DLL is correctly loading the C# DLL and calling its functions. Adding logging or breakpoints in the C++ wrapper can help you see if parameters are correctly passed and responses are properly received from the C# DLL.

            Error Handling: Ensure that the C# DLL isn’t throwing unhandled exceptions. Wrap the C# function calls in try-catch blocks and log any exceptions to troubleshoot any issues.

            Memory Management: Check for any memory management issues, such as buffer overflows or incorrect memory allocations. Ensure that the buffers (String_in$, String_in2$, Ret$) are correctly sized and used.

            Calling Convention: Verify that the calling convention used in the C++ DLL matches the expected calling convention in the C# DLL.

            Testing the C# DLL and the C++ wrapper independently might also help you identify where the issue lies. If you need more structured learning on such integration issues, platforms like Fast Learner offer comprehensive courses on programming and troubleshooting that could be very beneficial.

          Viewing 4 posts - 1 through 4 (of 4 total)
          • You must be logged in to reply to this topic.
          Scroll to Top
          HTB icon

          Please Sign In