/* DLL2.C, This DLL is for use with the MAIN2 example. */ /* Please refer to the MK2_FC.BAT file for instructions on */ /* building this example */ /* This example demonstrates tricky' interfaces between */ /* DLL and MAIN, using CHARACTER and COMPLEX data types */ #include #define DLL_PROCESS_DETACH 0 #define DLL_PROCESS_ATTACH 1 typedef struct { float real; float imaginary; } cmplx; typedef struct { double real; double imaginary; } cmplx_dbl; #if defined(BCPP) int _stdcall _export DLL2(cmplx *cx1, cmplx *cx2, cmplx_dbl *dcx1, cmplx_dbl *dcx2, char *ch1, char *ch2, long len1, long len2); int _stdcall _export DLL2(cmplx *cx1, cmplx *cx2, cmplx_dbl *dcx1, cmplx_dbl *dcx2, char *ch1, char *ch2, long len1, long len2) #else _declspec(dllexport) int _stdcall DLL2(cmplx *cx1, cmplx *cx2, cmplx_dbl *dcx1, cmplx_dbl *dcx2, char *ch1, char *ch2, long len1, long len2); _declspec(dllexport) int _stdcall DLL2(cmplx *cx1, cmplx *cx2, cmplx_dbl *dcx1, cmplx_dbl *dcx2, char *ch1, char *ch2, long len1, long len2) #endif { /* ** COMPLEX variables are passed as a structure ** CHARACTER variables are passed as a char pointer and length. All ** lengths are appended to the end of the argument list, in the order ** of the appearance of their affiliated char pointer in the argument ** list. */ int ido, ido2; cx1->real = 1.23; cx1->imaginary = 3.21; dcx1->real = 3.23; dcx1->imaginary = 1.21; for (ido = 0; ido < len1; ido++) { ch1[ido] = 'a' + ido; } for (ido = 0; ido < 10; ido++) { cx2[ido].real = 6.78 + ido; cx2[ido].imaginary = 9.87 + ido; dcx2[ido].real = 67.89L + ido; dcx2[ido].imaginary = 98.76L + ido; for (ido2 = 0; ido2 < len2; ido2++) { ch2[ido*len2+ido2] = 'k' + ido2 + 1 + ido + 1; } } return (9999); } unsigned long __stdcall DllEntryPoint(void *hDll, unsigned long Reason, void *Reserved) { if (Reason == DLL_PROCESS_ATTACH) { /*perform DLL initialization tasks here*/ } return (1); }