Detecting JLINK with nrfjprog

Hi all,

I'm trying something similar to this:

i.e. using the nrfprog.dll to connect with a Jlink from a c# application.

Opening the .dll works fine and I now want to use this function:

nrfjprogdll_err_t NRFJPROG_enum_emu_snr(uint32_t serial_numbers[], uint32_t serial_numbers_len, uint32_t * num_available);

wrapped in my App as:

[DllImport("nrfjprog.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int NRFJPROG_enum_emu_snr(UInt32[] serial_numbers,UInt32 serial_numbers_len, out UInt32 num_available);

The num_available returned is correct, i.e. 1 if one JLINK is connected, 2 if two are connected etc. The serial_numbers and serial_numbers_len are, however, empty.

Looking at the arguments one would think that this is because serial_numbers and serial_numbers_len are not "pointers" and can therefore not "return" any values. 

Consequently I try to modify the wrapper to:

private static extern int NRFJPROG_enum_emu_snr(out UInt32[] serial_numbers,out UInt32 serial_numbers_len, out UInt32 num_available);

Unfortunately this result in the following runtime error:

>>Exception thrown: 'System.AccessViolationException' in NRFJPROG.exe
>>An unhandled exception of type 'System.AccessViolationException' occurred in NRFJPROG.exe
>>Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Any ideas on how to make this work ?