02-11-2014 07:19 AM
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.
02-12-2014 10:51 AM
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.
02-12-2014 11:21 AM
VBA code attached. I can get it to enter the DLL and produce a MessagePopup, but after that it crashes excel.
02-13-2014 04:50 PM
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?
02-14-2014 07:43 AM
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.
02-17-2014 04:25 PM
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?
02-18-2014 07:11 AM
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.
02-19-2014 03:46 PM
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.
02-24-2014 01:19 PM
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.
02-25-2014 05:23 PM
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?