LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to return integer using pointer from dll made in vc in labwindows??

I am trying to use pointer in the interfacing of dll and labwindows..But I am not able to achieve this..I am returning base address of array from dll to labwindows and from that base address i am trying to obtain entire array..Please suggest me the way to do this..

Thank you

0 Kudos
Message 1 of 7
(3,529 Views)

If I understand the question correct: this is NOT possible.

 

If the pointer refers to an ASCII array, typical one can use the nul-terminator to find the end the of array/string.

Sometimes a special value is used to indicate the end of the array.

 

My own method for buffer exchange between functions or DLL:

1. long GetBuffer(int *Buffer, long BuffserSize), or

2. long GetBuffer(int *Buffer, long *BufferSize), or

3. void GetBufferPointer(int *Buffer, long *BufferSize)

With option 1, I create a buffer, and send the pointer to the start of my array to the DLL. I also send the size of the buffer i.e. the maximum number of values that can be stored in my buffer. The DLL copies values to my buffer. The DLL reports the actual number of values as the return value of the function. And typical, the DLL returns a negative value (instead of buffer length) as error code.

With option 2, I create a buffer, and send the pointer to the start of the array to the DLL. I also send the size of the buffer, but now I send it as pointer. On return, the DLL can overwrite the content of the BufferSize with the actual size of the buffer. The function return value can be void or it can be used for a status report.

With option 3, the DLL does not copy values to my buffer, but I have to retrieve values from the DLL buffer. However the DLL needs to report to me the pointer to the start of the array AND the number of values in the buffer. This again can be done as the return value or as a second parameter.

 

P.S. I am just starting to use 64-bit. The use of buffersize (long) should probably be replaced in LabWindows/CVI with size_t or ssize_t. However if the DLL has an explicit definition for the buffersize as long, you should use the same.

 

0 Kudos
Message 2 of 7
(3,514 Views)

I actually not understood your reply..Sorry for that...My exact question is that is it possible to send an address of integer from dll to labwindows and from labwindows get that integer value????? and if it is possible then how???? and if possible reply wid an example so I can understand that better....Thank you..

0 Kudos
Message 3 of 7
(3,509 Views)

I have not the compiler in front of me. Therefore only an ASCII text, without full code and probably some typing errors.

Note that this examples send a pointer to a buffer from the DLL to the exe-source. So the buffer must still exist when sometimes later the exe-source retrieves the data from that same DLL.

 

Still I prefer one of the examples where the exe-source creates a buffer, sends a pointer  and buffersize to the DLL, and that the DLL fills the buffer.

 

Succes, Jos

 

 

 

// in your DLL
static int DllBuffer[256];
...
...
long __stdcall GetBuffer(int *Buffer, long *BufferSize)
{
   long i;
   DllBuffer[0] = 1;
   DllBuffer[1] = 1;
   for (i=2; i<5; i++)
     DllBuffer[i] = DllBuffer[i-1] * i;
   Buffer = DllBuffer;
   *BufferSize = 7;
   return(0);
}

 

// in your labwindows exe
 int *Buffer;
 int *ptrBuffer;
 long BufferSize;
 long i, Status;
 Status = GetBuffer(Buffer, &BufferSize);
 if ((Status == 0) && (BufferSize > 0))
 {
    ptrBuffer = Buffer;
    for (i = i; i<BufferSize; i++)
    {
     printf("for counter %ld the values is %d", i, *ptrBuffer);
     ptrBuffer += 1;
    }
 }

 

Message 4 of 7
(3,507 Views)

I tried your code but its giving an error of  "pointer was referenced before initializing"....This error occurs in labwindows because the pointer declared is not initialized before getting passed to export function of dll..Now what is the solution to solve this problem?????

0 Kudos
Message 5 of 7
(3,482 Views)

I tried your code but its giving an error of  "pointer was referenced before initializing"....This error occurs in labwindows because the pointer declared is not initialized before getting passed to export function of dll..Now what is the solution to solve this problem?????

0 Kudos
Message 6 of 7
(3,473 Views)

I made a quick new example WITH CVI compiler. And I noted that I had ignored that the exchange is an array.

I have added the CVI code. It are two projects: TestDll for generating the DLL. TestExe for an exe with GUI that retrieves and displays some data.

 

Succes, Jos

 

For the array in the DLL:

static int DllBuffer[256];

... ...

long __stdcall GetBuffer(int **Buffer, long *BufferSize)

{   

long i, nmax=7;   

DllBuffer[0] = 1;   

DllBuffer[1] = 1;   

for (i=2; i<nmax; i++)

      DllBuffer[i] = DllBuffer[i-1] * i;

*Buffer = DllBuffer;

*BufferSize = nmax;

return(0);

}

 

 

For the exe file:

void GetDllValues() {

  int *Buffer=NULL;

  int *ptrBuffer;

  long BufferSize;

  long i, Status;

  char Message[256] = {0};

    Status = GetBuffer(&Buffer, &BufferSize);

  if ((Status == 0) && (BufferSize > 0))

  {

   DeleteTextBoxLines (mainp, PANEL_TEXTBOX, 0, -1);

   ptrBuffer = Buffer;

   for (i = 0; i<BufferSize; i++)

   {

    sprintf(Message,"for counter %ld the values is %d", i, *ptrBuffer);

    InsertTextBoxLine (mainp, PANEL_TEXTBOX, -1, Message);

    ptrBuffer += 1;

   }

  }

 }

 

 

0 Kudos
Message 7 of 7
(3,469 Views)