LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How initialize array in Call Library Function for unknown size array

I learn all examples DLL in LabView, but I not understand, how to solve my problem. I create DLL for LabView (get file name and return read data, size file I get in DLL):
#include <windows.h>
#include <stdlib.h>
extern "C" int __declspec(dllexport) Summa(int n1, int n2);
extern "C" void __declspec(dllexport) readdata(char* filename,  double *bufdat, long *filesize);
BOOL APIENTRY DllMain(HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved) {
  return TRUE;
}
int __declspec(dllexport) Summa(int n1, int n2) {
  return n1+n2;
}
void __declspec(dllexport) readdata(char* filename, double *bufdat, long *filesize) {
  DWORD byteread = 0;
  HANDLE filedat = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ,  NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
  if(filedat == INVALID_HANDLE_VALUE) {
    MessageBox(NULL, "Файл с данными не найден!!!", NULL, MB_OK);
    exit(1);
  }
  *filesize = GetFileSize(filedat, NULL);
  bufdat = new double[*filesize/sizeof(double)];
  if(!ReadFile(filedat, bufdat, *filesize, &byteread, NULL)) {// Проверка правильности считывания файла
    MessageBox(NULL, "Ошибка чтения файла данных!!!", NULL, MB_OK);
    CloseHandle(filedat);
    exit(1);
  }
  CloseHandle(filedat);
  //return bufdat;
}
I will return array, but in LabView return type array be absent. My Vi with my DLL not work correctly. Help me, please!
0 Kudos
Message 1 of 11
(5,025 Views)
Hi,

Take a look at this KnowledgeBase article which explains how to call a DLL from LabVIEW. Do you receive any errors when calling your DLL from LabVIEW?

Amanda Howard
Americas Services and Support Recruiting Manager
National Instruments
0 Kudos
Message 2 of 11
(5,000 Views)
Which version of LabVIEW are you using?
Amanda Howard
Americas Services and Support Recruiting Manager
National Instruments
0 Kudos
Message 3 of 11
(4,988 Views)
Also, check out this KnowledgeBase article on how to use the Call Library Function node, which I assume you are using.
Amanda Howard
Americas Services and Support Recruiting Manager
National Instruments
0 Kudos
Message 4 of 11
(4,986 Views)
I use LabView 6.0.  I do not receive the message on a mistake. Thanks for links, I shall necessarily look them.
0 Kudos
Message 5 of 11
(4,970 Views)
I and could not understand. Look, please, my example and help to find a mistake.
0 Kudos
Message 6 of 11
(4,958 Views)
Are you using the Call Library Function node?
Amanda Howard
Americas Services and Support Recruiting Manager
National Instruments
0 Kudos
Message 7 of 11
(4,945 Views)
Here is the help file for the Call Library Function node.
Amanda Howard
Americas Services and Support Recruiting Manager
National Instruments
0 Kudos
Message 8 of 11
(4,944 Views)
Amanda, I use Call Library Function (LabView 6.0). See my example, please.
0 Kudos
Message 9 of 11
(4,935 Views)

Hi,

Have you tried calling a very simple DLL first? I don't see any problems with your code in general. Here is a document that explains tips on creating a DLL in Visual C++.

Amanda Howard
Americas Services and Support Recruiting Manager
National Instruments
0 Kudos
Message 10 of 11
(4,895 Views)