Pages

Tuesday 12 June 2012

13 Things to keep in mind before using DLL in Delphi

Keep in mind the following tips when writing your DLL:

1. Make sure you use the proper calling convention (C or stdcall).

2. Know the correct order of the arguments passed to the function.

3. NEVER resize arrays or concatenate strings using the arguments passed directly to a function.

4. Remember, the parameters you pass are LabVIEW data. Changing array or string sizes may result in a crash by overwriting other data stored in LabVIEW memory. You MAY resize arrays or concatenate strings if you pass a LabVIEW Array Handle or LabVIEW String Handle and are using the Visual C++ compiler or Symantec compiler to compile your DLL.

5. When passing strings to a function, remember to select the correct type of string to pass . C or Pascal or LabVIEW string Handle.

6. Remember, Pascal strings are limited to 255 characters in length.

7. Remember, C strings are NULL terminated. If your DLL function returns numeric data in a binary string format (for example, via GPIB or the serial port), it may return NULL values as part of the data string. In such cases, passing arrays of short (8-bit) integers is most reliable.

8. If you are working with arrays or strings of data, ALWAYS pass a buffer or array that is large enough to hold any results placed in the buffer by the function unless you are passing them as LabVIEW handles, in which case you can resize them using CIN functions under Visual C++ or Symantec compiler.

9. Remember to list DLL functions in the EXPORTS section of the module definition file if you are using _stdcall.

10. Remember to list DLL functions that other applications call in the module definition file EXPORTS section or to include the _declspec (dllexport) keyword in the function declaration.

11. If you use a C++ compiler, remember to export functions with the extern .C.{} statement in your header file in order to prevent name mangling.

12. If you are writing your own DLL, you should not recompile a DLL while the DLL is loaded into memory by another application (for example, your VI). Before recompiling a DLL, make sure that all applications making use of the DLL are unloaded from memory. This ensures that the DLL itself is not loaded into memory. You may fail to rebuild correctly if you forget this and your compiler does not warn you.

13. Test your DLLs with another program to ensure that the function (and the DLL) behave correctly. Testing it with the debugger of your compiler or a simple C program in which you can call a function in a DLL will help you identify whether possible difficulties are inherent to the DLL or LabVIEW related.

No comments:

Post a Comment

About the Author

I have more than 10 years of experience in IT industry. Linkedin Profile

I am currently messing up with neural networks in deep learning. I am learning Python, TensorFlow and Keras.

Author: I am an author of a book on deep learning.

Quiz: I run an online quiz on machine learning and deep learning.