Coding the Custom Action DLL

Open the "StdAfx.h" file. Make the modification shown in bold below.

C++ Code

  1. /*
  2. stdafx.h : include file for standard system include files,
  3. or project Each Project you create represents a single Speech
  4. Driven Information System An Information System is a general
  5. term used to describe the product you are designing with this
  6. software. This could be any type of system in which you can give
  7. information to your callers, such as a Virtual Customer Service
  8. Center, a Virtual Technical Support Center, or a Virtual Help Desk..
  9. So, if you want to create three separate Information Systems, you
  10. will need to create three different Projects. specific include files
  11. that are used frequently, but are changed infrequently
  12. */
  13.  
  14. #if!defined (AFX_STDAFX_H__9748C1DE_4F89_11D6_B4F5_0002B3494C5D__INCLUDED_)
  15.  
  16. #define AFX_STDAFX_H__9748C1DE_4F89_11D6_B4F5_0002B3494C5D__INCLUDED_
  17.  
  18. #if _MSC_VER > 1000
  19.  
  20. #pragma once
  21.  
  22. #endif // _MSC_VER > 1000
  23.  
  24. // Insert your headers here
  25.  
  26. #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
  27.  
  28. #include <windows.h>
  29.  
  30. #include <lvca.h>
  31.  
  32. // TODO: reference additional headers your program requires here
  33.  
  34. // {{AFX_INSERT_LOCATION}}
  35.  
  36. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  37.  
  38. #endif // !defined(AFX_STDAFX_H__9748C1DE_4F89_11D6_B4F5_0002B3494C5D__INCLUDED_)

Open the document which contains the DLLMain function. Make the modification shown in bold below:

C++ Code

  1. // ca_test.cpp : Defines the entry point for the DLL application.
  2.  
  3. #include "stdafx.h"
  4. #include "cadll.h"
  5.  
  6. BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved )
  7. {
  8. switch (ul_reason_for_call)
  9. {
  10. case DLL_PROCESS_ATTACH:
  11. case DLL_THREAD_ATTACH:
  12. case DLL_THREAD_DETACH:
  13. case DLL_PROCESS_DETACH:
  14. break;
  15. }
  16. return TRUE;
  17. }
  18.  
  19. // This is an example of an exported function.
  20. CA_TEST_API BOOL WINAPI fnCallback( LONG message, HANDLE handle )
  21. {
  22. BOOL bReturn = FALSE ;
  23. switch ( message )
  24. {
  25. case CAMSG_POLL:
  26. bReturn = TRUE;
  27. break;
  28. default:
  29. }
  30.  
  31. return bReturn ;
  32. }

Open the CPP's header file. Make the modification shown below:

C++ Code

  1. /*
  2. The following ifdef block is the standard way of creating
  3. macros which make exporting from a DLL simpler. All files
  4. within this DLL are compiled with the CA_TEST_EXPORTS symbol
  5. defined on the command line. this symbol should not be defined
  6. on any project that uses this DLL. This way any other project
  7. whose source files include this file see CA_TEST_API functions
  8. as being imported from a DLL, whereas this DLL sees symbols
  9. defined with this macro as being exported.
  10. */
  11.  
  12. #ifdef CA_TEST_EXPORTS
  13.  
  14. #define CA_TEST_API __declspec(dllexport)
  15.  
  16. #else
  17.  
  18. #define CA_TEST_API __declspec(dllimport)
  19.  
  20. #endif
  21.  
  22. CA_TEST_API BOOL WINAPI fnCallback( LONG message, HANDLE handle );

Press F7 to build the DLL.

Additional Information

A note regarding the CA_TEST_EXPORTS and CA_TEST_API macro: these are arbitrary names used for resolving possible conflicts with exporting and importing functions and classes. You may use your own names so long as you are consistent. We recommend brushing up on the topics covered in "DLL Tasks" and the article "Mutual Imports" in the MSDN Library.

If you run Dependency Walker (depends.exe) and open up your Customj Action DLL, you will see an entry on one of the right-hand views: ?fnCallback@YGHJPAX@Z. This is the "decorated" name of your callback function and it is the name you will enter in the in the Designer if the designer does not recognize it. You do not have to use this opaque naming convention. Create a .def file and type in the following entries:

  • EXPORTS
  • fnCallback @1

Save the file and rebuild your DLL. If you open up your Custom Action DLL again you will now see that the entry is simply fnCallback which can be entered in the Designer.

Design Considerations:

The Engine is a multithreaded application, therefore, it is a good idea to make your DLL multithreaded and your callback function re-entrant. State data is managed through the LVCA_SetUserData and LVCA_GetUserData functions.

© 2012 LumenVox LLC. All rights reserved.