Dear Rolf,
Thanks for the advice - inspired me to continue. After mulling around the LV external code manuals for a while and looking at the string stuff in extcode.h, I tried the following DLL code, which seems to work fine:
//------------------------------------------
// Test sending arrays back to Labview caller via events
#include <windows.h>
#include <extcode.h>
#include "LVevent1.h"
typedef struct {
int32 length; // Length of array
int32 data[1]; // Array
} arr1D, *arr1DP, **arr1DH;
// Sends a 1D array of 32-bit integers, length N, Nevents times with msWait in between
DEXP int sendLVevents(LVUserEventRef *msg, int N, DWORD msWait, int Nevents)
{
int ii, jj;
arr1DH arrayH;
for (jj=0;jj<Nevents;jj++){
Sleep(msWait);
arrayH=(arr1DH)DSNewHandle(sizeof(int32)+N*sizeof(int32));
(*arrayH)->length = N;
for (ii=0;ii<N;ii++) (*arrayH)->data[ii]=(int32)(ii+jj);
PostLVUserEvent(*msg,(void *)&arrayH);
}
return 0;
}
//------------------------------------------
I can post a screen shot of the LV diagram (with an event structure, similar to those in the posts I quoted above), if anyone wants...
This seems to work error-free so far, i.e. tests with a 10000-element vector sent with 50 ms waits, 100 times, did not cause a crash or anything weird.
Just one question: Do I need to add some additional code to be more conscientious with the creation/deletion of these handles? Am I building up a ton of trash in the memory, or are the handles destroyed after LV gets the event? (The DLL should run for minutes to hours, sending 10-100 kB/second...).
Regards, MT