10-18-2005 12:38 PM
10-19-2005 04:10 PM
10-20-2005 09:04 AM
Hi Tica,
Thanks for the response. I actually built a little test dll from a Labwindows/CVI example I found on ni.com. I added one function (besides DllMain) to return 3.14159 as a double. Here's the source:
#include <ansi_c.h>
#include <cvirte.h>
#include <cvidef.h>
int DLLEXPORT myvar = 0;
int __stdcall DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
if (InitCVIRTE (hinstDLL, 0, 0) == 0)
return 0; /* out of memory */
break;
case DLL_PROCESS_DETACH:
CloseCVIRTE ();
break;
}
return 1;
}
double DLLEXPORT returnValue(void) {
double value = 3.14159;
return(value);
}
I have read in cvi\manuals\progref.pdf (pg 3-11) that to resolve references to Utility Library calls you need to add cvi\extlib\refsym.c to the project. Since the DllMain function calls InitCVIRTE and CloseCVIRTE I added refsym.c. I did this because I thought that matlab crapped when it tried to initialize testdll.dll for use in the mex file hanging on the unreferenced CVI calls. However, adding refsym.c to the project did nothing for me and I'm still getting the "procedure not found" thing.
testdll.dll works fine used with LW/CVI compiled code. Mex/LCC happily compiles everything including refsym.c and hapily links everthing, too. But when I try to run the mex file matlab still responds saying "specified procedure could not be found. Now I wonder what procedure it cannot find.
I've even gone as far as to place all the dlls in the same directory as the mex file thinking there was some kind of PATH problem searching for the dlls: testdll.dll, cviauto.dll, cvibgi.dll, cviogl.dll, cvirt.dll, cvirte.dll. I don't even know what they're all for, it was just a shot in the dark and it didn't work either.
-shrew
02-14-2006 10:45 AM
I figured out what the problem was a while ago. I figured that I would post it here in case someone else comes a searchin' for the answer.
To use the dll created in LabWindowsCVI you have to build a static library listing all the functions found in the dll. CVI does this, but it is not compatible with lcc compiler packaged with Matlab which is what I use to build mex files. There is a utility in Matlab in the lcc directory (MATLAB_ROOT\sys\lcc\bin) to build a proper static library for lcc to use when linking. It is called buildlib.exe. In order to create the .lib file you have to create an exports file for buildlib to read. The file basically lists the functions found in the dll.
For instance if you built a dll named zurbit.dll with 3 functions named foo, bar, hoo. Then the contents of the export file would look like this:
zurbit.dll
_foo
_bar
_who
You can name the file whatever you want but the following syntax will create a static library with the same name as the export file name so it is a good idea to use the same name for the export file as the name of the dll to be used. In order to build the static library call "buildlib.exe zurbit.exp" This will create a static library called zurbit.lib for use when linking in the function names found in the dll. Use this library when building your mex file and you should be good to go!
-shrew