calling a DLL in Visual C++
-
Hello, I've written a program in VisualC++ to call a DLL file. I came to the DLL file by compiling a Matlab file with the function mcc. When I write a simple DLL file (output=input) my C++ program works very well and gets a good link with the DLL. But when I change the DLL file a little bit(output = 3* input), my program gets no good link with the DLL file. It seems that the main function can't call the other subfunctions of my dll file(the functions that are extra created when I changed my DLL file to "output=3*input" and are needed to perform the multiplication) Please, can you explain me what's wrong, what I have to change?? Is their something wrong with the settings of my program? Could you give me a good example of such a program? Is there maybe something wrong with the mcc compiler code? The code I used was "mcc -W lib:libFLOPS -t -h -T link:lib libmmfile.mlib FLOPS". This is a part of my C++ program: void CDLLTESTDlg::OnStartdllbutton() { typedef mxArray*(* LPFNDLLFUNC1)(mxArray* input); HINSTANCE hDLL; // Handle to DLL LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer hDLL = LoadLibrary("libFLOPS.dll"); if (hDLL != NULL) { lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,"mlfFLOPS"); if (!lpfnDllFunc1) { // handle the error FreeLibrary(hDLL); SetDlgItemText(IDC_RESULTDLLCALL,"ddl found, but no function"); } else { // call the function char szTemp[100]; mxArray *INPUT=NULL, *OUTPUT=NULL; INPUT=mxCreateScalarDouble(100); OUTPUT=(*lpfnDllFunc1)(INPUT); sprintf(szTemp,"%f",mxGetScalar(OUTPUT)); SetDlgItemText(IDC_RESULT,szTemp); SetDlgItemText(IDC_RESULTDLLCALL,"ddl en functie gevonden"); FreeLibrary(hDLL); } } } Thanx for your support , kind regards, Geert
-
Hello, I've written a program in VisualC++ to call a DLL file. I came to the DLL file by compiling a Matlab file with the function mcc. When I write a simple DLL file (output=input) my C++ program works very well and gets a good link with the DLL. But when I change the DLL file a little bit(output = 3* input), my program gets no good link with the DLL file. It seems that the main function can't call the other subfunctions of my dll file(the functions that are extra created when I changed my DLL file to "output=3*input" and are needed to perform the multiplication) Please, can you explain me what's wrong, what I have to change?? Is their something wrong with the settings of my program? Could you give me a good example of such a program? Is there maybe something wrong with the mcc compiler code? The code I used was "mcc -W lib:libFLOPS -t -h -T link:lib libmmfile.mlib FLOPS". This is a part of my C++ program: void CDLLTESTDlg::OnStartdllbutton() { typedef mxArray*(* LPFNDLLFUNC1)(mxArray* input); HINSTANCE hDLL; // Handle to DLL LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer hDLL = LoadLibrary("libFLOPS.dll"); if (hDLL != NULL) { lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,"mlfFLOPS"); if (!lpfnDllFunc1) { // handle the error FreeLibrary(hDLL); SetDlgItemText(IDC_RESULTDLLCALL,"ddl found, but no function"); } else { // call the function char szTemp[100]; mxArray *INPUT=NULL, *OUTPUT=NULL; INPUT=mxCreateScalarDouble(100); OUTPUT=(*lpfnDllFunc1)(INPUT); sprintf(szTemp,"%f",mxGetScalar(OUTPUT)); SetDlgItemText(IDC_RESULT,szTemp); SetDlgItemText(IDC_RESULTDLLCALL,"ddl en functie gevonden"); FreeLibrary(hDLL); } } } Thanx for your support , kind regards, Geert
Hi, the simplest reason could be a PATH problem. Probably Mathlab engine must be addressed to the OS: your DLL has the Mathlab Engine implicilty linked and so OS do load your DLL only if all the dependencies are loadad. Try to add the Mathlab engine path in the PATH env variable: use Dependency Walker to find the dependencies of your DLL and than search the file in HD.:)
-
Hi, the simplest reason could be a PATH problem. Probably Mathlab engine must be addressed to the OS: your DLL has the Mathlab Engine implicilty linked and so OS do load your DLL only if all the dependencies are loadad. Try to add the Mathlab engine path in the PATH env variable: use Dependency Walker to find the dependencies of your DLL and than search the file in HD.:)
Could you explain me what you mean with "try to add the Mathlab engine path in the PATH env variable: use Dependency Walker to find the dependencies of your DLL and than search the file in HD" Thanx, kind regards, Geert
-
Could you explain me what you mean with "try to add the Mathlab engine path in the PATH env variable: use Dependency Walker to find the dependencies of your DLL and than search the file in HD" Thanx, kind regards, Geert
In order to use Mathlab functionality you need some DLL for sure. You probably have linked your app with the enty point lib of these. There is a free utility called Dependency Walker that can help in identify the DLL your component need. All these DLLs must be present in one or more of the following path list: - your app path; - the %systemroot% path; - the %winnt%\system32 path; - one of the path specified by the PATH environment variable; If something gets wrong in loading any of these DLLs your primary DLL cannot be loaded and you experience the problem you have reported. More info in "Advanced Programming for Windows" by Richter
-
In order to use Mathlab functionality you need some DLL for sure. You probably have linked your app with the enty point lib of these. There is a free utility called Dependency Walker that can help in identify the DLL your component need. All these DLLs must be present in one or more of the following path list: - your app path; - the %systemroot% path; - the %winnt%\system32 path; - one of the path specified by the PATH environment variable; If something gets wrong in loading any of these DLLs your primary DLL cannot be loaded and you experience the problem you have reported. More info in "Advanced Programming for Windows" by Richter
What do you just mean with? - the %systemroot% path; - one of the path specified by the PATH environment variable; I'm not such an experienced programmaer:-) Kind regards, ciao, Geert
-
What do you just mean with? - the %systemroot% path; - one of the path specified by the PATH environment variable; I'm not such an experienced programmaer:-) Kind regards, ciao, Geert
%systemroot% : the directory of windows (if you are using XP it's probably c:\windows, if you are using NT/2000 it's probably c:\winnt). Check in the Windows online help "Environment Variables", type SET PATH on command prompt and get the content of the PATH env var. You'll see ";"-separated list of paths, append the path of the Mathlab DLL folder you found w/ the method I have explained earlier. Probably you 'll need a help by someone more expert in the dept you are working...