AInvisibleNinja Posted June 4, 2018 Report Share Posted June 4, 2018 I'm trying to use the Import Shared Library Wizard to call C/C++ calls from the ClearPath-SC SDK in LabVIEW. I'm having issues with the wizard creating the VIs where it's saying that none of the functions can be created. It also seems like it's importing the names of the functions incorrectly as well. Does anyone have any idea what's going on or what I can do to fix it? Thank you. Quote Link to comment
JKSH Posted June 5, 2018 Report Share Posted June 5, 2018 1 hour ago, AInvisibleNinja said: Does anyone have any idea what's going on or what I can do to fix it? The dialog tells you what's going on and what you can do to fix it: "The function is not declared in the header file.... Check the header file to make sure it contains declarations of the function.... Undefined symbols can prevent the wizard from recognizing functions." Which header file did you provide? Have a look inside. Does it look right? 1 hour ago, AInvisibleNinja said: It also seems like it's importing the names of the functions incorrectly as well. What should the correct names be? Quote Link to comment
AInvisibleNinja Posted June 5, 2018 Author Report Share Posted June 5, 2018 Thanks for the response. I provided it the master header file, and I have looked inside it and all of the functions show up correctly in there. For example, the header file shows the function: virtual void AddToPosition(double adjAmount) = 0; where LabVIEW is reading it as cpmAddToPosition() and lists it as broken. I'm thinking the issue is from it being a C++ DLL inside of a C DLL. Do you have any tips or suggestions for getting a C++ DLL to work with Labview? Quote Link to comment
JKSH Posted June 6, 2018 Report Share Posted June 6, 2018 (edited) 9 hours ago, AInvisibleNinja said: virtual void AddToPosition(double adjAmount) = 0; Ah. The wizard only understands C functions. virtual and = 0 are C++ concepts that don't exist in C. Furthermore, this looks like a member function of a class, which also doesn't exist in C. 9 hours ago, AInvisibleNinja said: I'm thinking the issue is from it being a C++ DLL inside of a C DLL. Do you have any tips or suggestions for getting a C++ DLL to work with Labview? You must create your own wrapper DLL. Your DLL must be written in C++, but the functions that you expose must be marked extern "C" -- see https://stackoverflow.com/questions/1041866/what-is-the-effect-of-extern-c-in-c If you have no prior C/C++ experience, I highly recommend you find someone in your company who does. Writing a wrapper DLL is not something that can be taught in one forum post. Edited June 6, 2018 by JKSH Quote Link to comment
AInvisibleNinja Posted June 6, 2018 Author Report Share Posted June 6, 2018 Thank you for all of your time and help. Yes, it is a member of a class so I'm seeing how difficult this will be. We will probably look for another motor so we don't have to work on that. Just out of curiosity though, do you have any good resources for writing DLL wrappers? Maybe books or something? I haven't been able to find anything, but I would like to read up on the issue in case we ever encounter it again. Quote Link to comment
smithd Posted June 6, 2018 Report Share Posted June 6, 2018 I dont know if theres a guide, but generally writing a wrapper that is (trivially) labview compatible means: Determining thread safety of the underlying code (and trying to keep things thread safe if possible -- the alternative is that every DLL call needs to run in the UI thread) Only exposing simple return values (void, numeric, pointer) -- don't try to return a struct by value Only exposing simple parameter values (string, numeric, string array, numeric array, or pointer) -- trying to pass a struct by value can be done, but you'll have to think about byte alignment on different platforms. Trying to keep things synchronous if possible. Any callbacks have to be part of the wrapper. Labview exposes two message mechanisms which can be called from C, firing an occurrence and firing off a user event. If your underlying library uses a callback mechanism to notify clients that an operation has completed, you would write a callback inside of your wrapper which fires the occurrence or generates the user event when the operation is complete. Presumably then the labview code would either have the data (as part of the event) or call the DLL to grab the resultant data. The program files/ni/labview/cintools directory contains various headers you can use to access some of the innards of labview, including the above. There used to be a help page on ni.com but google can no longer find it. Included in the tools are also the definitions of labview arrays and labview strings, which could make manipulation of large data sets easier/more efficient. 1 Quote Link to comment
JKSH Posted June 7, 2018 Report Share Posted June 7, 2018 I had a quick look at the ClearPath-SC website. It seems like they have a .NET API. If your application is for Windows only, you could use the .NET API directly inside LabVIEW without a wrapper DLL. 8 hours ago, AInvisibleNinja said: do you have any good resources for writing DLL wrappers? Maybe books or something? I haven't been able to find anything, but I would like to read up on the issue in case we ever encounter it again. At its core, it's just learning how to use C++ to write a DLL that is compatible with C programs. Once you know how to write such a DLL, apply the restrictions that @smithd mentioned to make it LabVIEW-compatible. Here, "Wrapper" simply describes the use-case for the DLL. LabVIEW calls your own custom DLL which in turn calls the ClearPath-SC DLL. Your custom DLL is called the "wrapper". 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.