Forum Discussion

amirse's avatar
amirse
Contributor
3 years ago
Solved

Using .dll files in Readyapi

Hi,

 

In our c# development environment we use some .dll files (bought from external company) to convert files in different formats to .pdf.

Is there a way to use these .dll files in some way also via Readyapi?

I.e. I would like to point out a, let say, .jpeg file and then call the method found in the .dll files to convert it to .pdf?

 

Is this possible at all?

  • Hello amirse 

     

    Here is a sample groovy script that I hacked up from original source found from the link in the code. Put it in a Groovy Test Step to try it out.  It just goes against the Microsoft Windows supplied kernel32.dll that is on Windows computers.  It looks like the important part of the code is to get the interface method calls correct.  Finding the interface definition for your .DLL will probably be the tricky part.  This sample does not rely on any special tool pre-process or anything other than the imported libraries that are supplied with ReadyAPI (JNA).  Good Luck.

     

    Regards,

    Todd

     

    import com.sun.jna.Library;
    import com.sun.jna.Native;
    
    // source:
    //   https://www.codeproject.com/Questions/625580/calling-dll-function-java
    
    //** Simple example of Windows native library declaration and usage. */
    //public class BeepExampl{
    //   public interface Kernel32 extends Library {
    //       // FREQUENCY is expressed in hertz and ranges from 37 to 32767
    //       // DURATION is expressed in milliseconds
    //       public boolean Beep(int FREQUENCY, int DURATION);
    //       public void Sleep(int DURATION);
    //   }
    //   public static void main(String[] args) {
    //    Kernel32 lib = (Kernel32) Native.loadLibrary("kernel32",
    //           Kernel32.class);
    //    lib.Beep(698, 500);
    //    lib.Sleep(500);
    //    lib.Beep(698, 500);
    //   }
    //}
    //
    
    log.info 'Test Step "' + testRunner.runContext.currentStep.name + '" start...';
    log.info "";
    
    interface Kernel32 extends Library {
        boolean Beep(int FREQUENCY, int DURATION);
        void Sleep(int DURATION);
    };
    
    Kernel32 lib = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class);
    lib.Beep(698, 500);
    lib.Sleep(1000);
    lib.Beep(698, 1000);
    
    log.info "";
    log.info 'Test Step "' + testRunner.runContext.currentStep.name + '" done...';
    

     

7 Replies

  • richie's avatar
    richie
    Community Hero
    Hey amirse,

    I could be wrong, but i think the answer is "no" short of converting the source c# to java and recompiling the .dlls as ReadyAPI uses java runtime.

    Perhaps the coding experts ChrisAdams / nmrao / etc. can come up with something?

    Cheers,

    Rich
    • amirse's avatar
      amirse
      Contributor

      Hi, thank you for your input. I understand this is tricky. I will write here in case I manage to do something.

      I have simplified the subject. Hope it is more clear.