LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

What is a good reference for developing and integrating DLL's in LabWindows/CVI apps (or C apps in general)?

NI's Developer Zone has some great tutorials on creating reusable code in LabWindows/CVI as well as integrating external code (such as DLL's.) These references can be found at:

http://zone.ni.com/devzone/devzone.nsf/webcategories/A3052B02557F502D862568660021B1AF?opendocument

Hope this helps!
0 Kudos
Message 2 of 8
(3,839 Views)
As well as the NI site, there is also a wealth of information on the MSDN

http://search.microsoft.com/us/dev/default.asp

The above link takes you to the search page where you can search for any info on DLL's you wish.

http://msdn.microsoft.com/library/default.asp?URL=/library/psdk/winbase/dll_8asu.htm

The above link is to the main overview of DLL's from which you can navigate from.

That will sort you out on the development, as to the integration in CVI Apps, the NI documentation will help you there.

Let me know if you need any more info,

Chris
Message 3 of 8
(3,839 Views)
The second link is wrong (takes you to DLL Main description).

Here is the correct link to the DLL Overview:

http://msdn.microsoft.com/library/default.asp?URL=/library/psdk/winbase/dll_512r.htm

Sorry
0 Kudos
Message 4 of 8
(3,839 Views)
Thanks for the reply. I actually had looked at those DLL pages on MSDN this weekend, but the explanations are fairly incomplete. I have a specific problem that I'm trying to figure out.

I have a main.c file that calls functions in a DLL, say DLL1. One of DLL1's exported functions, GetDoorStatus(), simply gets the physical status of a door on my system. I have another piece of equipment that has its own dll, DLL2, that need to call the same function, GetDoorStatus(), to get the status of the door. But when I try to link my DLL to create the .dll and .lib files, it says that GetDoorStatus() is not defined. It sees the prototype, but can't find the actual definition of the function. My main.c has no problem finding it. My #includes include the
glue code just like main.c does (the return of function pointers). Why would it not be able to find it while main.c does?

I've been trying to figure this out for a few days with no luck. Any help would be appreciated. Thanks.

Craig
0 Kudos
Message 5 of 8
(3,839 Views)
Craig
Do you add the *.lib file to your project and #include the *.h file to every source code, that uses the function? I often used external DLL's, but I never had a problem when calling the external functions.

Stephan
0 Kudos
Message 6 of 8
(3,839 Views)
There is an application called depends which you should have on your system. The first thing to do is use this application on your first DLL and verify that the function is exported from the DLL.
Your main might be able to see the function since it has been defined internal. If the DLL was built and the function not declared for export, then it will not exist within the .lib.

What I tend to do, is to have a seperate header file containing only the functions I wish to export. These are defined using the DLLEXPORT (or its eqivalent).

When building the DLL, I direct it to use this header file explicitly for producing the .lib files.

As someone said below, all you then need do is attach the .lib and header file to your project for DLL2.


It does appear that the function although defined in the header file you are attaching is not exported, and hence cannot be called from the DLL2.

Note: In order for DLL1 to use the function, you must also include the Exported Functions header file in that source file as well.

If you are still having problems, let me know and I'll look for an example I must have somewhere round here.

Chris

(Depends.exe is available as part of the SDK, and also I believe comes with CVI)
0 Kudos
Message 7 of 8
(3,839 Views)
Aha. After writing 90% of this response, a light bulb went on and I figured it out. I will post this anyway in case this helps someone else. Bottom line - I had neglected to put the gluecode.c in my project so the function definitions were not found, only the prototypes. If you want to see what I was writing before enlightenment, read on.

My project may sound a bit convoluted. My main program needs to access functions in several DLL's, and some of these DLL's need to access functions in my main program as well. At runtime, my main.c gets the type of the currently installed hardware, and calls the appropriate DLL's. Loading dynamically this way precludes putting the .lib in the main project. I created some glue code in a ki
nd of 'middle-man' way - call it gluecode.c. It has all the prototypes of the dll in its .h, and has the GetProcessAddr() function to assign pointers to the dll functions. Below this there are simple functions. It looks like this:

int LoadMotionDll(char *szDllName)
{
MotionDLLHandle = LoadLibrary(szDllName);
if (MotionDLLHandle == NULL)
{
return kFailedToLoadDllError;
}

if (!(ConfigMotionPortPtr = (void*)GetProcAddress(MotionDLLHandle, "ConfigMotionPort")) )
goto FunctionNotFoundError;
return 0;
}

// Glue code for each DLL function

int __stdcall ConfigMotionPort (int com_port, int baud, int parity, int data,
int stop, double user_units, double accel,
double velocity)
{

return (*ConfigMotionPortPtr)(com_port, baud, parity, data, stop, user_units, accel, velocity);
}

This works great when accessing the functions from my main.c code. This gluecode.c is in my main project along with its .h. But no .lib need
be in the project.
0 Kudos
Message 8 of 8
(3,839 Views)