pooja81 Posted April 12, 2006 Report Share Posted April 12, 2006 Dear members, Whenever I call a dll to multiply two matrices in labview, it crashes. plz tell me what can be problem , i m ataching the .cpp file #include "matrix1.h" #include "stdafx.h" #define DllExport __declspec(dllexport) extern "C" DllExport void mult(int x,int y,int z,int aa[10][10],int bb[10][10]) { int i,j,k,cc[10][10]; printf("Result of Matrix Multiplication"); printf("\n"); for(i=0; i<x; i++ ) for(j= 0; j<y; j++ ) cc[j] = 0; for(i=0; i<x; i++ ) for(j=0; j<y; j++ ) for(k=0; k<z ; k++ ) { cc[j] += aa[k]*bb[k][j]; } } /*Printing Elements of Matrix*/ DllExport void prntm() { int i,j,x=0,y=0,cc[10][10]; for(i=0;i<x;i++) { for (j=0;j<y;j++) { printf("%d",cc[j]); printf("\t"); } printf("\n"); } } Plz tell me as soon as possible. Thanks in advance Pooja Quote Link to comment
Khalid Posted April 12, 2006 Report Share Posted April 12, 2006 Couple of things: 1. I don't see your DLL function return anything. 2. How are you calling the funciton in LabVIEW -- what are the arguments you're passing, etc.? -Khalid Quote Link to comment
pooja81 Posted April 12, 2006 Author Report Share Posted April 12, 2006 Couple of things:1. I don't see your DLL function return anything. 2. How are you calling the funciton in LabVIEW -- what are the arguments you're passing, etc.? -Khalid The arguements which i m paasing in this dll r 1. signed 16 bit int 2. signed 16 bit int 3. signed 16 bit int 4. array->signed 16 bit 5. array->signed 16 bit whenever i return cc[j] , it also gives the same error wat can be d prob with this Thanks in advance Pooja Quote Link to comment
Rolf Kalbermatter Posted April 12, 2006 Report Share Posted April 12, 2006 The arguements which i m paasing in this dll r 1. signed 16 bit int 2. signed 16 bit int 3. signed 16 bit int 4. array->signed 16 bit 5. array->signed 16 bit whenever i return cc[j] , it also gives the same error wat can be d prob with this Thanks in advance Pooja LabVIEW (and Windows 95 and higher) being a 32bit application you only can use 32bit compiled DLLs. That means that int is really a 32bit integer. Configuring the Call Library Node to use int16 instead will create some serious problems. For the skalars you won't see crash but just some strange and truncated values. For the array this certainly will cause serious trouble including invalid pointer accesses and crashes since the memory area you are telling LabVIEW to pass in will be only half as large as the DLL thinks it should fill in. Also I hope you make sure that the two arrays are preallocated in LabVIEW to the necessary size. In calling DLLs the caller is ALWAYS supposed to allocate memory for the DLL funcitons to fill in their result. For your case this would mean that you have to allocate two arrays of 10 * 10 elements to pass in. Another issue is the use of two dimensional C arrays. This is an area in C where the specification is not always very clear. A C compiler usually will create an array of n * x elements and internally treat it as one dimensional array which happens to be the same way as LabVIEW looks at multidimensional arrays. But it also can sometimes mean that you have an array of pointers each pointing to a different array of elements (which is not very simple to create in LabVIEW at all). Of course doing Matrix multiplication entirely in LabVIEW is another solution, if done right not really slower than doing it in C too. And LabVIEW 8 has additional support for Matrix operations. Rolf Kalbermatter Quote Link to comment
larsen Posted May 3, 2006 Report Share Posted May 3, 2006 extern "C" DllExport void mult(int x,int y,int z,int aa[10][10],int bb[10][10]){ int i,j,k,cc[10][10]; printf("Result of Matrix Multiplication"); printf("\n"); for(i=0; i<x; i++ ) for(j= 0; j<y; j++ ) cc[j] = 0; ..... This code has a lurking disaster because you dont do any check of the x and y is within bounds. If not, crashes are certain. Printf is not posible from a dll. Where should it print to? there is no terminal. You can however use a messagebox char msg[300]; sprintf(msg, "Result of Matrix Multiplication\n"); MessageBox(NULL,msg,"info",MB_OK|MB_ICONERROR); regards henning Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.