LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Labwindows DLL and Excel VBA

I have a Labwindows DLL compiled under CVI 2012 that I can sucessfully call from Excel VBA (2010).  Now compiling under CVI 2013 I get a variety of errors including 'bad arguments' and excel crash.  Anyone aware of changes in CVI 2013 that would cause this? Arguments in the call include two user-defined types, and a string. Build options and other settings appear to be the same.

0 Kudos
Message 1 of 13
(6,306 Views)

One of the big changes between CVI 2012 and 2013 is a new compiler.  This might be the culprit.  What does your VBA code look like for calling the DLL?  I would love to play around with it and see if I see the same results or if I can get it working on my end.

 

Jesse S.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 13
(6,272 Views)

VBA code attached. I can get it to enter the DLL and produce a MessagePopup, but after that it crashes excel.

0 Kudos
Message 3 of 13
(6,265 Views)

Do you know which specific lines it is crashing on?  Knowing the specific functions with the inputs would be helpful.  Also, is this a 32 bit or 64 bit dll?  

Jesse S.
Applications Engineer
National Instruments
0 Kudos
Message 4 of 13
(6,238 Views)

I was able to get this DDL to work..

 

long _stdcall basicDLL(double x,char *path)
{
char str[64];

MessagePopup("Notice","In DLL");
MessagePopup("Notice",path);
sprintf(str,"Q %5.0f",x);
MessagePopup("Notice",str);
return -1;    
}

 

but not this...

 

long _stdcall testDLL(select_input sr,char *path)
{
char str[64];

MessagePopup("Notice","In DLL");

MessagePopup("Notice",path);
sprintf(str,"Q %5.0f",sr.q);
MessagePopup("Notice",str);
return -1;    
}

 

crash at sprintf.  I think it may have something to do with the structure that is passed.  Both methods work when called from CVI.  The VBA and CVI structure (sr) are both showing 36 bytes.

 

 

0 Kudos
Message 5 of 13
(6,221 Views)

So, we've got a couple of thoughts with this.  What happens if in your VBA code you declare the variable q as a double instead of a single.  Also, what is your structure declaration in your dll?  Can you perform a simple add with the sr.q you pass into the dll or does your VBA code crash on every operation you try to perform with the structure?  And if so, could you write sr.q to a double and then pass that into the sprintf?

Jesse S.
Applications Engineer
National Instruments
0 Kudos
Message 6 of 13
(6,193 Views)

The DLL crashes with any action on sr.q  Here is the DLL header:

 

#define NP 32

typedef struct
{
int selectMode;
int selectDrive;
float q;
float p;
float T;
float h;
float DDtol;
float DDspeed;
float DiaRestrict;
}select_input;

typedef struct
{
float qs;
float ps;
float hs;
float se;
float q[NP];
float p[NP];
float h[NP];
float speed;
float dia;
float maxHP;
float maxSpeed;
float denR;
float area;
float Lwi[8];
float Lwo[8];
float LW_i;
float LWiA;
float LW_o;
float LWoA;
int    AMCA_CP;
int AMCA_CA;
char pname[30];
char ptype[30];
}select_data;

 

select_input sr;

 

sr.q is a float so I think single is correct in the VBA.  Size of the structure is 36 bytes in C DLL.  In VBA I used the Len() function and it also shows as 36 bytes.

0 Kudos
Message 7 of 13
(6,180 Views)

The float does correspond to the single.  I thought you were declaring it as a double since one of your dll calls was set up for a double input.  

 

I have been trying to reproduce this issue, however, I am not fluent in VBA.  I keep getting a Run-time error '49': Bad DLL calling convention.  I was wondering if you could pass me the Excel file as well as the dll and project file.

Jesse S.
Applications Engineer
National Instruments
0 Kudos
Message 8 of 13
(6,150 Views)

Attached are the files for testing the DLL with VBA.  The path locating the DLL in VBA will have to be changed.  It will probably default to local directory, but I did not try that. Thanks.

0 Kudos
Message 9 of 13
(6,119 Views)

I've played around with the dll and the VBA code for a while.  I'm getting a crash and/or errors when I build the dll in both CVI 2012 and 2013.  Though, I am testing the VBA code in Excel 2007.  We are still looking into it, however,do you have a dll that was compiled in 2012 that works with the VBA script?

Jesse S.
Applications Engineer
National Instruments
0 Kudos
Message 10 of 13
(6,098 Views)