LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

DLL with no header file but VI's..

Hello,

very frequently the lab instruments that we buy in our laboratory come with LabView example software but not LabWindows/CVI.

I would like someone to help me in my struggling to address a .dll which comes with a .llb LabWindows file but not a .lib/header file.

My approach is usually to open the "Call library function" in labview, look at the prototype, and then use it to build a header file in labwindows. At this point I create an import library in labwindows. Everything works fine with simple functions, with a few numeric arguments and a single numeric output. But when I try to call functions like the one of the example in the figure

unsigned long HR4000_IdentifyHR4000(short int DevNum, CStr SerialNumber);

which have a pointer to char argument, the system gets stuck and i receive the "the system has encountered a problem"  message from windows. Note that everything is compiled properly and the other functions do not give problems.

I paste here the code, I think that probably i forget something fundamental in the header file. From the labview window i see that the calling convention is C..

the header file i use to create the .lib:

#ifdef __cplusplus
    extern "C" {
#endif

void __cdecl OOI_Config(unsigned short int spec, unsigned short int adctype, unsigned short int irq, unsigned short int baseaddress);
unsigned short int __cdecl OOI_GetIRQ(void);
unsigned short int __cdecl OOI_GetNumberOfPixels(void);
unsigned long __cdecl HR4000_IdentifyHR4000(short int DevNum, char *serial);

#ifdef __cplusplus
}      
#endif

and the code which gets stuck when I call "HR4000_Identify"

#include <ansi_c.h>
#include <cvirte.h>       
#include <userint.h>
#include "spectroHR4000.h"
#include "global.h"
#include "hr4000.h"  

static int panelHandle;

int i;
unsigned short int IRQ,nPixs,out;
float dataarray[16384];
unsigned long doubleWordArray[18];
char serial[32];//="         \0";
int main (int argc, char *argv[])
{
    if (InitCVIRTE (0, argv, 0) == 0)
        return -1;    /* out of memory */
    if ((panelHandle = LoadPanel (0, "spectroHR4000.uir", PANEL)) < 0)
        return -1;
    DisplayPanel (panelHandle);
    initialize();
    RunUserInterface ();
    DiscardPanel (panelHandle);
    return 0;
}

void initialize(void)
{

OOI_Config(1536, 12, 7, 768);
IRQ=OOI_GetIRQ();
nPixs=OOI_GetNumberOfPixels();
printf("irq:%i\tnPix:%i\n",IRQ,nPixs); // up to here it works fine

HR4000_IdentifyHR4000(0, serial); // here it gets stuck
printf("%s\n",serial);

}


Thank you ïn advance for your support !

Luigi


0 Kudos
Message 1 of 5
(4,048 Views)
Hello Luigi,

I'm really sorry for the late reply, but I received your question yesterday.


At first glance it doesn't look bad at all.

After some searching I found out that there may be a problem with the dll:

http://forums.ni.com/ni/board/message?board.id=170&message.id=260431&requireLogin=False


So the first question is: Does the function of the dll you are using work fine in LabVIEW?

I did some tests with the dll from the thread above yesterday evening, but it doesn't work under LabVIEW and CVI. Maybe it has to do with the dll or that the hardware is missing...

To reproduce it, we need the dll and the LabVIEW-vi with the original call. Because we don't have the hardware here: Is there a similar function (or another dll) which doesn't require the hardware?


Thanks,

Ralf N.
Applications Engineering
Germany
0 Kudos
Message 2 of 5
(3,994 Views)
Dear Ralf,

thank you very much for your message, and for the link to the thread about the Ocean Optics  dll.  By experience I know that they produce very good hardware, but software and driver installation are usually very tricky. This is why I have first carefully ensured myself that the hardware was correctly working on my machine. To answer your question: yes, the VI which calls the DLL works fine when run under Labview.

Since I was struggling so much with calling the dll from LabWindows with no success, after I posted my request on the forum, I have also tried to proceed in a different way: in LabView I have compiled a project composed by the two VI's I need into a dll.  In practice I have now a dll which calls the Ocean Optics dll, this way Labview also provided me the header file for my C program. Unfortunately it does not work, in the sense that the program compiles correctly, when I run it it returns me no error, but I cannot get the right data array which is the result of the VI (this array is correctly filled when I run the VI under Labview). I have an evidence that when i call the function in the dll I created the external dll function is called because if  the calling function in the C program has a certain parameter set to 0 (frequency) I get an error from the Ocean Optics dll. On the other hand I see only the default values in the output array of the function.

I profit of your experience to send you the C program, the compiled dll, the original ocean optics dll, and the VI's. If you have time to look into it I would greatly appreciate it. To simplify your task I can also ask you two direct questions:

1) when you compile a VI as a dll calling a third party dll, the third party function are implemented in your dll or are they always called from the original one ? In this case is there any way to be sured that the program looks for them in the right place ?

2) do you know about any  compatibility problem concerning memory allocations among LabView and LabWindows ? The output of my function is a pointer to an array. But if I look into that array from the C program I only get the default values of this  array as I set them in the VI, and not those I expect from the device. If you can tell me if in my code I look correctly into that array is already of great help for me.

Thank you very much for your help and support.

Luigi
<meta http-equiv="Content-Type" content="text/html; "> <meta name="ProgId" content="Word.Document"> <meta name="Generator" content="Microsoft Word 11"> <meta name="Originator" content="Microsoft Word 11"> Luigi Bonacina, PhD
0 Kudos
Message 3 of 5
(3,967 Views)
Hello Luigi,

thank you for your message.


The dll is a little bit "special", e.g. it always opens a window and returns interesting values...

So I did some tests and hope it will help you:

I. The first example (call.zip) represents a simple dll-call to detect the version-number. The number is returned via an array of char.

II. Calling the dll within LabVIEW and after that calling the LabVIEW-dll by CVI seems to work if you copy the dll to the same directory. The Ocean Optics dll opens a window and when you hit the OK-button you will get an array with 5es. (The errormessages which appear are from the inside of the dll. There should ask Ocean Optics.)

Here are some additional links:
http://digital.ni.com/public.nsf/allkb/70995EC2CA1B523386256DD4004F3DE6?OpenDocument
http://sine.ni.com/devzone/cda/epd/p/id/1288


Please let me know, if this helps you.


With best regards,

Ralf N.
Applications Engineering
Germany

Download All
0 Kudos
Message 4 of 5
(3,931 Views)
Dear Ralf,

thank you so much for your example. I am currently on a trip and I unfortunately cannot check it with the hardware. When I am back in Geneva I will immediately send you a feedback about your code.

Sincerly,

Luigi
0 Kudos
Message 5 of 5
(3,909 Views)