Hi DSPc team,
I need to create a constructor to initialize external C/C++ libraries for my custom module. I’m looking for guidance on how to link and call this constructor within the class structure, ensuring it is called only once during initialization. Any advice or examples would be greatly appreciated!
Thanks in advance!
Monika V
12:10pm
Hi Monika,
Your custom module Visual Studio solution contains 2 projects.
<module>Lib
and
<module>DLL
You'll want to make sure that all of the header files that accompany your library are available to the module C code. The easiest way to accomplish this is to put them in the /include folder under your module's parent folder. If you wish to keep them somewhere else, then that path will need to be added to the "Lib" project's "Additional Include Directories".
To link your library into the project, go to the DLL project's properties "Linker Input" settings and add the library files to "Additional Dependencies". The libraries themselves should reside under the "Lib" folder, e.g. C:\<ModulePath>\Lib\VS2019\win32\debug. You may have to copy the folders into several places to match the build configurations (debug/release). Also check "Linker General" Additional Library directories in the event you wish to keep them somewhere else.
If you need to allocate memory to the library, or use any of the library API responses to determine how much memory to allocate, then add those lines to your InnerConstructor file.
Otherwise, you can put the library API initialization call into the Set() function switch statement corresponding to a Mask value of 0xFFFFFFFF.
Let me know if this helps or if you have any issues.
Thanks,
Gary
12:31pm
Hi Gary ,
Thanks for the response . I think you might understood the query in way wrong.
the query - > I'm currently working on developing a custom module and I've created a constructor to initialize some parameters default values used within my module. I need guidance on how to call this constructor within the class structure in c source file. Additionally, I want to ensure that the constructor is called only once during initialization.
Thanks
Monika.
12:43pm
Hi Monika,
If the goal is to initialize your module's internal parameters, then do this in the InnerSet.c function.
Place the code into the switch statement corresponding to a Mask value of 0xFFFFFFFF.
For an example, please see the example module code included with the Pro Edition of AWE Designer, e.g.
C:\DSP Concepts\AWE Designer 8.D.2.7 Pro\AWEModules\Source\Examples\Source\ModFaderExample.c
Thanks,
Gary
12:47am
Hi Gary,
Yes I understood your point .
1. Constructor can also be used to initialize the variables, memory allocations ..etc .
As per the above statement I have created a separate constructor function where I initialize parameters for my custom module. I want to use this constructor function as an argument in a class structure, meaning that while creating the class, I want to create and initialize the parameters. I need guidance on how to call this constructor within the class structure.
2. As you said If I use the
InnerSet.c
function to initialize parameters with default values, will it be called only once during initialization, or will it be called multiple times whenever the parameter values change?Thanks,
Monika V
12:49pm
Hi Monika,
Note that although we refer to functions in the module code as "constructors", this is C code, not C++. There are no real classes and no real constructors (as in C++) here. The supported methods for initializing modules are either at the end of the constructor function, or in the Set() function in switch(mask) case 0xFFFFFFFF. You can call an external function to do so if you like.
Typically your set() function will need a case statement in the switch(mask) block for each controllable parameter. case 0xFFFFFFFF is used specifically for module initialization purposes.
If you would like to confirm this, please see how to debug your DLL (i.e. to set a breakpoint within the Set() function) here:
Debugging Custom Modules
Thanks,
Gary
3:47am
Hi Gary ,
Thanks for the response. I have few more queries.
1. Could you kindly provide an example of the set function you explained and guide me on how to call it?
2. I have a structure defined in the ./include/example.h and I need to access this structure and its members within the set function to initialize them with specific values. Is it possible to access the structure inside the set function ?
If it is possible please share the example.
Thanks,
Monika V
11:57am
Hi Monika,
See this folder (referenced from our latest release, but they have not changed in some time so should also be in other recent releases).
C:\DSP Concepts\AWE Designer 8.2025.1 Pro\AWEModules\Source\Examples\Inner
Look for the Inner*_Set.c functions and compare that to the assembled module code.
e.g.
See how
"C:\DSP Concepts\AWE Designer 8.2025.1 Pro\AWEModules\Source\Examples\Inner\InnerFaderExample_Set.c"
relates to:
"C:\DSP Concepts\AWE Designer 8.2025.1 Pro\AWEModules\Source\Examples\Source\ModFaderExample.c"
To add a reference to a third party include file to your generated Module.c code, use the following approach in the module.m file:
% ----------------------------------------------------------------------
% Code generation details
% ----------------------------------------------------------------------
% this assumes that the include file is located in a folder where your Visual Studio project will find it.
% for simplicity just put all include files in the module's ./include folder.
awe_addcodemarker(M, 'hFileDefine', '#include "my-special-functions.h"');
% you can also add any other thing you like, line by line, by following this pattern:
awe_addcodemarker(M, 'hFileDefine', '#define whizbang 13');
% for example, you can define a struct in the matlab.m file:
awe_addcodemarker(M, 'hFileDefine', 'typedef struct {');
awe_addcodemarker(M, 'hFileDefine', ' float32 member_1;');
awe_addcodemarker(M, 'hFileDefine', ' float32 member_2;');
awe_addcodemarker(M, 'hFileDefine', '} my_Struct;');
% these lines will be added to the generated Module.h file which is included at the top of Module.c.
----------------------------------------
You do not have to call the Set() function. It will be called by the AWE Framework at the proper times.
Thanks,
Gary