This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to use nrfjprog.dll

We are trying to use nrfjprog.dll in a c# program to help us with manufacturing and quality assurance. We are able to load and call the functions from c# and all the functions work one by one, but if we call NRFJPROG_open_dll and then one of the other functions we get an error saying:

"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

This happens no matter which of the functions we are calling after calling NRFJPROG_is_dll_open even if it is NRFJPROG_close_dll or NRFJPROG_is_dll_open.

This is the code we are using:

   [DllImport("Flash/nrfjprog/nrfjprog.dll", CallingConvention = CallingConvention.Cdecl)]
   private static extern nrfjprogdll_err_t NRFJPROG_dll_version(out UInt32 major, out UInt32 minor, [MarshalAs(UnmanagedType.LPWStr)] out string revision);

   [DllImport("Flash/nrfjprog/nrfjprog.dll", CallingConvention = CallingConvention.Cdecl)]
   private static extern nrfjprogdll_err_t NRFJPROG_is_dll_open(out bool opened);

   [DllImport("Flash/nrfjprog/nrfjprog.dll", CallingConvention = CallingConvention.Cdecl)]
   private static extern nrfjprogdll_err_t NRFJPROG_open_dll(string jlink_path, msg_callback_cb cb, device_family_t family);

   [DllImport("Flash/nrfjprog/nrfjprog.dll", CallingConvention = CallingConvention.Cdecl)]
   private static extern nrfjprogdll_err_t NRFJPROG_close_dll();

   public static void TestNrfj()
   {
       UInt32 major, minor;
       string revision = "";
       bool open;
       nrfjprogdll_err_t return_value;

       return_value = NRFJPROG_open_dll(JLinkPath, msg_callback, device_family_t.NRF52_FAMILY);
       return_value = NRFJPROG_is_dll_open(out open);
       return_value = NRFJPROG_dll_version(out major, out minor, out revision);
       return_value = NRFJPROG_close_dll();        
Related