LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing array of large cluster to CLN fails

Solved!
Go to solution

Hi,

 

I'm trying to pass an array of clusters to a DLL but it doesn't get passed correctly. I have passed a few clusters similar to this (although smaller) with no issues before, but somehow this one doesn't line up correctly or something. What I'm trying to do is passing an array of items followed by a info struct. The length of the array is the nItems param in the info structure. The problem is that when reading nItems in the cpp code it doesn't match with the value passed as you can see in the log file when run and from the assertion error. This indicates that the structures are not passed correctly.

 

It looks to me that the cluster matches the struct definitions and I'm pretty sure I'm using the correct parameters in the CLN. I have had trouble before with large clusters where labview would get confused and I'd get instane objects issues but I'm not sure if that's the issue here.

 

 

 

h file

 

#pragma pack(4)
typedef struct TKdlgItemVal
{
	int	intVal;
	double	doubleVal;
	char    szVal[256];
} TKdlgItemVal;


typedef struct TKdlgItemConf
{
    int     nType;	                // The item type code (see below), replaces nParam2
    double  dX;	                    // Item x position or 0 for default layout (was dParam1)
    double  dY;	                    // Item y position or 0 for default layout (was dParam2)
    char    szText[256];		    // The prompt string for the item, following | then tooltip is optional
    double  dWide;                  // Item width in dialog units.
    double  dHigh;                  // Item height for group boxes only.
    double  dLo;                    // Item value limits for reals and integers.
    double  dHi;
    double  dSpin;                  // Spinner value or zero for no spinner.
    int     nPre;                   // Precision for real items & max chars for string (0 for don't care).
    char    szList[1024];           // Selector list - items separated by | char. Required for list type.
    char    szLegal[256];           // Legal characters for string type, leave blank for all legal.
	TKdlgItemVal	sDlgItemVal;
} TKdlgItemConf;

typedef struct TKdlgInfoConf
{
	int		nItems;							// The number of dialog items
	double		dWide;			                // Dialog width
    double		dHigh;			                // Dialog height
    char		szTitle[60];				    // The dialog title
} TKdlgInfoConf;
#pragma pack()

extern "C"	__declspec(dllexport) int setS2Dlg(TKdlgItemConf asDlgItems[], TKdlgInfoConf sDlgInfo);

 

cpp file

 

 

extern "C"	__declspec(dllexport) int setS2Dlg(TKdlgItemConf asDlgItems[], TKdlgInfoConf sDlgInfo)
{
	std::ofstream myfile;
	std::vector<TKdlgItemConf>	m_asDlgItems;
	myfile.open ("logger.txt", std::ios::out | std::ios::app); 
	myfile<<"NItems: "<<sDlgInfo.nItems<<std::endl;
	m_asDlgItems.clear();
	if (!asDlgItems && sDlgInfo.nItems)	// Array not empty yet is NULL
		return 1;
	ASSERT(sDlgInfo.nItems<11);
	m_asDlgItems.reserve(sDlgInfo.nItems);
	myfile<<"RSize: "<<m_asDlgItems.capacity()<<std::endl;
	for (int i= 0;i<sDlgInfo.nItems;++i)
	{
		m_asDlgItems.push_back(asDlgItems[i]);
		myfile<<"RSize: "<<m_asDlgItems.size()<<std::endl;
		myfile<<"RSize: "<<m_asDlgItems[i].nType<<","<<m_asDlgItems[i].szText<<std::endl;
	}
	m_asDlgItems.shrink_to_fit();
	myfile.close();
	return 0;
}

 

Thanks in advance,

M

 

Download All
0 Kudos
Message 1 of 2
(2,022 Views)
Solution
Accepted by topic author myle00

I wish I could delete this post because I feel very stupid. It was a simple case of passing a cluster to the CLN but I forgot to set the params in the c code to pass by pointer instead of by value... Smiley Sad

0 Kudos
Message 2 of 2
(2,008 Views)