// Automatically generated C++ file on Tue Apr 8 18:57:36 2025 // // To build with Digital Mars C++ Compiler: // // dmc -mn -WD warningmsg.cpp kernel32.lib #include extern "C" __declspec(dllexport) int (*Display)(const char *format, ...) = 0; // works like printf() extern "C" __declspec(dllexport) const double *DegreesC = 0; // pointer to current circuit temperature extern "C" __declspec(dllexport) const int *StepNumber = 0; // pointer to current step number extern "C" __declspec(dllexport) const int *NumberSteps = 0; // pointer to estimated number of steps extern "C" __declspec(dllexport) const char* const *InstanceName = 0; // pointer to address of instance name extern "C" __declspec(dllexport) const char *QUX = 0; // path to QUX.exe extern "C" __declspec(dllexport) const bool *ForKeeps = 0; // pointer to whether being evaluated non-hypothetically extern "C" __declspec(dllexport) const bool *HoldICs = 0; // pointer to whether instance initial conditions are being held extern "C" __declspec(dllexport) int (*DFFT)(struct sComplex *u, bool inv, unsigned int N, double scale) = 0; // discrete Fast Fourier function 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 in struct sWARNINGMSG { // declare the structure here wrnTrue; }; extern "C" __declspec(dllexport) void warningmsg(struct sWARNINGMSG **opaque, double t, union uData *data) { double in = data[0].d; // input double Vmax = data[1].d; // input parameter if(!*opaque) { *opaque = (struct sWARNINGMSG *) malloc(sizeof(struct sWARNINGMSG)); bzero(*opaque, sizeof(struct sWARNINGMSG)); } struct sWARNINGMSG *inst = *opaque; // Implement module evaluation code here: if (!inst->wrnTrue & in > Vmax){ Display("Warning V(in) > Vmax at t = %fs\n",t); inst->wrnTrue = 1; } } extern "C" __declspec(dllexport) double MaxExtStepSize(struct sWARNINGMSG *inst, double t) { return 1e308; // implement a good choice of max timestep size that depends on struct sWARNINGMSG } extern "C" __declspec(dllexport) void Trunc(struct sWARNINGMSG *inst, double t, union uData *data, double *timestep) { // limit the timestep to a tolerance if the circuit causes a change in struct sWARNINGMSG const double ttol = 1e-9; // 1ns default tolerance if(*timestep > ttol) { struct sWARNINGMSG tmp = *inst; warningmsg(&(&tmp), t, data); // if(tmp != *inst) // implement a meaningful way to detect if the state has changed // *timestep = ttol; } } extern "C" __declspec(dllexport) void Destroy(struct sWARNINGMSG *inst) { free(inst); }