// Automatically generated C++ file on Wed Mar 27 09:18:19 2024 // // To build with Digital Mars C++ Compiler: // // dmc -mn -WD derivativedll.cpp kernel32.lib #include union uData { bool b; char c; unsigned char uc; short s; unsigned short us; int i; unsigned int ui; float f; double d; long long int i64; unsigned long long int ui64; char *str; unsigned char *bytes; }; // int DllMain() must exist and return 1 for a process to load the .DLL // See https://docs.microsoft.com/en-us/windows/win32/dlls/dllmain for more information. int __stdcall DllMain(void *module, unsigned int reason, void *reserved) { return 1; } void bzero(void *ptr, unsigned int count) { unsigned char *first = (unsigned char *) ptr; unsigned char *last = first + count; while(first < last) *first++ = '\0'; } // #undef pin names lest they collide with names in any header file(s) you might include. #undef x #undef dx struct sDERIVATIVEDLL { // declare the structure here double lastT; double lastx; }; extern "C" __declspec(dllexport) void derivativedll(struct sDERIVATIVEDLL **opaque, double t, union uData *data) { double x = data[0].d; // input double &dx = data[1].d; // output if(!*opaque) { *opaque = (struct sDERIVATIVEDLL *) malloc(sizeof(struct sDERIVATIVEDLL)); bzero(*opaque, sizeof(struct sDERIVATIVEDLL)); } struct sDERIVATIVEDLL *inst = *opaque; // Implement module evaluation code here: double Ts = t - inst->lastT; dx = (x - inst->lastx)/Ts; inst->lastT = t; inst->lastx = x; } extern "C" __declspec(dllexport) void Destroy(struct sDERIVATIVEDLL *inst) { free(inst); }