Develop FTP client with Indy9_09
- Program structure diagram and description
Roger yang
Programming
The right side of the dashed line in the figure is the DLL of various FTP functions, and the left side is called the DLL application in a multi-threaded manner. InstgetFileDllMain is an instance of a DLL, and the form contains a TIDFTP control, which is not displayed, just use the container of the TIDFTP control.
DllInterface is responsible for maintaining the interface between DLL, using the loadLibrary method in its constructor to load the DLL and get the function pointer of all DLL all interface functions. Such a DLL interface function is mapped to the members of the DllInterface.
GetFileThread is an instance of downloading a task thread class.
Due to how many times the LoadLibrary the same DLL in the application, this DLL is loaded in the same memory space. So, load the same DLL in each working thread, and you cannot get a plurality of mutually independent DLL instances.
Working method is to create 10 InstgetFileDllMain instances in a DLL for multi-threaded calls. Creating 10 instances means simultaneously supporting 10 working threads for FTP download operations. An InstgetFileDllMain instance is used multiple times in its life cycle, and it will be initialized each time the call. After the call is over, the instance instance of the InstgetFileDllmain does not release, but waiting to be used by other threads. These 10 InstgetFileMain instances are released only when the entire DLL instance is released.
A global DLLINTERFACE instance is created at the beginning of the application, and then an instance of a getFileThread thread class will be created for each additional download task. The download file method of the Dllinterface global instance is called in the threaded thread function. This method has been bound to the download file method in the DLL. When the method is called, there is a key parameter is the thread number, the thread number corresponds to 10 InstgetFileMAIN instances in the DLL. This ensures that each download task thread uses an INSTGETFILLLMAIN instance independent in the DLL and does not interfere with each other.