Develop FTP client with Indy9_03
- Method for creating and dynamically calling DLL in BCB
Roger yang
1. Create a DLL: 1. Create a DLL framework according to DLL Wizard. Source Type Select C Select Use VCL and Multi Threaded 2. Due to the Sprintf, add two header files #include
4 while the interface functions implemented int __stdcall dlltest (char * strTmp, long lTmp, int iTmp) {int iRtn; char strDebugString [4096]; memset (strDebugString, 0, sizeof (strDebugString)); sprintf (strDebugString, "strTmp = [% s] ", strTmp); OutputDebugString (strDebugString); memset (strDebugString, 0, sizeof (strDebugString)); sprintf (strDebugString," lTmp = [% ld] ", lTmp); OutputDebugString (strDebugString); memset ( strDebugString, 0, sizeof (strDebugString)); sprintf (strDebugString, "iTmp = [% d]", iTmp); OutputDebugString (strDebugString); iRtn = iTmp 1000; return iRtn;} 2. dynamic call DLL: 1. the Compiled good .dll file COPY to the directory where the project is located. 2. Declaration of the private member of the class file Hinstance Dllinst; int (__stdcall * dlltest) (CHAR *, long, int); / * DLL interface function function pointer * / 3. Dynamically call the interface function of the DLL in the button event: char strparam [4096]; long lparam = 1000; int ip ARAM = 2000; IRTN = 0; OutputdebugString ("Application Start"); Dllinst = NULL; / * Loads the specified DLL file * / dllinst = loadingLibrary ("dlltest.dll"); if (dllinst == null) {showMessage ("LoadLibrary [DLLTEST.DLL] FAILED!"); Return;} / * Set function pointer * / dlltest = (int (__stdcall *) (CHAR *, long, int)) getProcaddress (Dllinst, "DLLTEST"); if (DLLTEST == Null) {ShowMessage ("Obtain Function Pointer Failed"); Return;} Strcpy (StrParam, "This is the value of strparam"); IRTN =