Introduction to CMac: 09. Calling user-written dll
Multi-Edit CMac has the ability to call external user-written routines that are in a Dynamic Link Library (DLL). You can write your code using any language, such as C++. (I don't explain how to create a dll here.)
Add an import statement to your CMac code, then you can call your external user-written routine.
Attached here is a simple example. The attached .zip file contains:
testmydll.s— CMac macro which calls routine set_all in filetestdll.dlltestdll.dll— Compiled Dynamic Link Library containing routine set_alltestdll.cpp— Source code fortestdll.dllstdafx.h— Another source file that was automatically generated by my Microsoft Visual C++ 6.0 which does just about nothing but I include it here for completeness.testdll.txt— (This text)
INSTALLING "TESTDLL.DLL"
- Exit Multi-Edit. This forces Multi-Edit to unload any previous
testdll.dllfile it might have loaded so you can replace it. - Copy the file
testdll.dllto your Multi-Edit folder (e.g.C:\Program Files\Multi-Edit) replacing any previous version oftestdll.dll - Restart Multi-Edit. It will now load the new
testdll.dllfile when you first call it.
TESTING
- Open
testmydll.sin Multi-Edit. - Compile the code.
- Run the testall macro.
String a will be changed to “EFGH” Integer i will be set to 8 (i = i + BUFLEN + 2) [BUFLEN being the second parameter passed in the call to set_all()].
See file testdll.cpp for the code.
Note how the second parameter, BUFLEN, is passed by value, and the third parameter i is passed by reference (pointer). I did this just to demonstrate the two ways.