/* main2.c, This is a main program unit for use with the */ /* DLL2 DLL. Please refer to the MK2_CF.BAT */ /* file for instruction on building this example */ /* This example demonstrates 'simple' interfaces between */ /* DLL and MAIN, using intrinsic data types */ #include #include #include #include #include #include #include #include #include #include #include #define _X86_ #include "windows.h" HANDLE _stdin_handle; HANDLE _stdout_handle; HANDLE _stderr_handle; typedef struct { float real; float imaginary; } cmplx; typedef struct { double real; double imaginary; } cmplx_dbl; /* ** Prototype for DLL. Note the need for the __stdcall ** also, note that everything is passed by reference */ int _stdcall DLL2(cmplx *cx1, cmplx *cx2, cmplx_dbl *dcx1, cmplx_dbl *dcx2, char *ch1, char *ch2, long len1, long len2); int WINAPI WinMain() { #define len1 5L #define len2 8L cmplx cx1, cx2[10]; cmplx_dbl dcx1, dcx2[10]; char ch1[len1+1],ch2[len2*10+1]; /*note that the char strings must have space for null terminators for C*/ int ido, jdo; int result; result = DLL2(&cx1, cx2, &dcx1, dcx2, ch1, ch2, len1, len2); if (result != 9999) { MessageBox(0, "", "Failed result", MB_OK | MB_SETFOREGROUND | MB_APPLMODAL); } if (fabs(cx1.real - 1.23) > .1) { MessageBox(0, "", "failed cx1-real", MB_OK | MB_SETFOREGROUND | MB_APPLMODAL); } if (fabs(cx1.imaginary - 3.21) > .1) { MessageBox(0, "", "failed cx1-imag", MB_OK | MB_SETFOREGROUND | MB_APPLMODAL); } if (fabs(dcx1.real - 3.23) > .1) { MessageBox(0, "", "failed dcx1-real", MB_OK | MB_SETFOREGROUND | MB_APPLMODAL); } if (fabs(dcx1.imaginary - 1.21) > .1) { MessageBox(0, "", "failed dcx1-imag", MB_OK | MB_SETFOREGROUND | MB_APPLMODAL); } for (jdo = 0; jdo < len1; jdo++) { if (ch1[jdo] != ('a' + jdo)) { MessageBox(0, "", "failed ch1", MB_OK | MB_SETFOREGROUND | MB_APPLMODAL); } } for (ido = 0; ido < 10; ido++) { if (fabs(cx2[ido].real - (6.78 + ido + 1)) > .1) { MessageBox(0, "", "failed cx2-real", MB_OK | MB_SETFOREGROUND | MB_APPLMODAL); } if (fabs(cx2[ido].imaginary - (9.87+ido+1)) > .1) { MessageBox(0, "", "failed cx2-imag", MB_OK | MB_SETFOREGROUND | MB_APPLMODAL); } if (fabs(dcx2[ido].real - (67.89l+ido+1)) > .1) { MessageBox(0, "", "failed dcx2-real", MB_OK | MB_SETFOREGROUND | MB_APPLMODAL); } if (fabs(dcx2[ido].imaginary - (98.76l+ido+1)) > .1) { MessageBox(0, "", "failed dcx2-imag", MB_OK | MB_SETFOREGROUND | MB_APPLMODAL); } for (jdo = 0; jdo < len2; jdo++) { if (ch2[ido*len2+jdo] != ('k' + ido+1+ jdo+1)) { MessageBox(0, "", "failed ch2", MB_OK | MB_SETFOREGROUND | MB_APPLMODAL); } } } /* when we get this far, everything is working */ MessageBox(0, "", "Passed Example 2", MB_OK | MB_SETFOREGROUND | MB_APPLMODAL); return (0); }