Archived

This topic is now archived and is closed to further replies.

Dwiel

Multipule instances of a DLL

Recommended Posts

Hello, I am writing a program that uses ftplib to search and download files off of FTP servers. It has performed great as I have had no problems with it until now... I REALLY need to be able to download multipule files at once. It currently supports having multipule connections open at once, but not multipule transactions. I tried putting each FtpGet() call, which downloads a file from the server, into a new thread, to no avail. The new thread works correctly, but I still can not get multipule instances of FtpGet to run at one time... I even recompiled FtpLib so that the functions were not all prefixed with the static keyword. How can I run multipule instances of the same dll function at the same time? Preferably, I would be able to put it in its own thread so it doesn''t hold up the main code while it executes. Thanks a ton! P.S. The method I am currently using is to have the FtpLib.lib, FtpLib.dll, and ftplib.h files in the project directory, include the header, and use a #pragma comment(lib, "FTPLib") statement to include the dll. Thanks again! Dwiel

Share this post


Link to post
Share on other sites
Just for your guy''s info,

I just tried including the actual C source code for FtpLib and it still wont run multipule instances of the same function. I am not even using a dll anymore...

Does anyone know what would cause a function to be not be able to be run by two different threads at the same time?

How can I fix this?

Thanks!

Dwiel

Share this post


Link to post
Share on other sites
I have been examining the code for the library a lot (past couple of hours) and I believe that I have determined that the function send which is from the winsock.h file, is what is causing problems. The library itself, as I have checked very thouroughly, contains no gobals, so I doubt that it is the problem. Has anyone else had problems getting this function to runs in two different processes? There MUST be a way to allow two to happen at once because a million connections are made, maintaned, and trasfered over at the same time on nearly every computer that is connected to the inet...

I was thinking that I could always create a command line program that did the file transfers so that this function that doesn''t seem to be able to be called at the same time, will work. What would be the best to ''trick'' this function into thinking that two completely different apps are executing it? There must be a way?

Thank you Magmai for the help, it seems plenty of people are interested, but not too many people know the answer... Its nice of you to save me from bieng the only poster in my own thread

ANY help would be MUCH appreciated!

Dwiel

Share this post


Link to post
Share on other sites
There shouldn''t be a problem of doing multithreading on a dll, i did it and no problems EXCEPT that you must be a bit carefull with the vars itself.
I don''t know if ftplib is thread safe since i never worked with it so you should first of all check that in the lib documentation.
How are you creating your threads and from where? if is a dll then is called by an external program.

Share this post


Link to post
Share on other sites
I thought that I had read that ftplib was thread safe, but possibly not. I use the CreatThread/TerminateThread/CloseHandle functions. When you say that I must be careful with the vars theselves, what do you mean? Do you mean I should becareful to not give two functions the same pointer to data which it tries to modify and get goofy results? In this case, there are no common variables bieng passed to the functions.

If anyone has any other libraries that I could try, I would definatelty be willing to try them... this is the 3rd Library I have tried... they all seem to be lacking in one way or another. This one was the first that allowed multipule connections at once... still problems with multi-transactions though....

Thnanks

Share this post


Link to post
Share on other sites
quote:
Original post by Tazzel3D
I thought that I had read that ftplib was thread safe, but possibly not. I use the CreatThread/TerminateThread/CloseHandle functions. When you say that I must be careful with the vars theselves, what do you mean? Do you mean I should becareful to not give two functions the same pointer to data which it tries to modify and get goofy results? In this case, there are no common variables bieng passed to the functions.


Well there''s many possible sources of problems when doing multithreading things, i''ll assume you''re using vc6 or 7 since is the most common scenario.
1.check that in vc 6 there are issues with CreateThread and the c library, i think prefered method was _beginthread or _beginthreadex instead of the api but check carefully the msdn about it, also check if you''re linking with the multithread library or the single thread one (project settings, c/c++, category code generation, Use run time library...)
2. vars... is an issue, by default (please take this with a graint of salt and skepticism since i may not be 100% correct) dlls are apartment thread model, which means that each instance of your dll will NOT share variables but this applies for instances of the DLL between processes but not for instances of threads in your instance of the dll (i hope im not confusing you too much) so be sure you''re using vars properly (you can share variables between dll instances using apropiate storage attribs, cant recall exactly but is somewhat easy to find it out in the msdn, again do not confuse instances of dll with instances of threads on an instance of the dll), you must be carefull with *global* variables
3. you will very likely need to open a ftp connection from each thread to handle each download, here is where the multithreading support comes to the lib, if it cannot handle then you''re doomed and probably need another library

Share this post


Link to post
Share on other sites
here it is, at the very end of the CreateThread doc on the msdn....

>>A thread that uses functions from the C run-time libraries should use the beginthread and endthread C run-time functions for thread management rather than CreateThread and ExitThread. Failure to do so results in small memory leaks when ExitThread is called.

Share this post


Link to post
Share on other sites
Thank you matias suarez,

First of all, I would assume that I am not using the multithread libraries with VC6.0 because I have not explicitly done so. Could this, hopefully, be my problem? Currently, I am linking to: kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib mswsock.lib advapi32.lib user32.lib gdi32.lib comdlg32.lib

I do understand, in theory, what you were talking about with the threads, but with the combonation of the fact that the code, library, the I am debuging is not familiar, esp the socket programming part, AND the fact tha I have only done multithreading stuff on occassion, I am not really not really sure how to make sure that I am following all of your advise. I understand what you are saying, just not really sure hoe to apply it... maybe that makes sence... I think that I am going to quickly try to see if I can get WinInet to do what I want, because I would much rather just switch libraries than try to figure this out.

It seems that using WinInet will work... I just got it to download 2 files at once so I will probobly just switch up the libraries... as much as I hate giving up... This project, to download bootleg music from FTP servers, has already taken up way more time than I planned or planted to...

If you guys do have any more suggestions though, I would very happy to figure what is going on to make this not work.

Thanks for the help thus far!

Dwiel

Share this post


Link to post
Share on other sites
I have done some reaserch, and WinInet seems to be a workable solution, hopefully this will be the 4th and final try

I even got a progress bar thing working despite a comment I found on an MSDN article saying that if I used Ftp[Put/Get]File, it was impossible.

To anyone doing a search or not... using this thread for reference, you can use a callback function with data you get from the ''INTERNET_STATUS_RESPONSE_RECEIVED'' callback which is the # of bytes transfered...

Anyway, I would still like to know if anyone knows why the previous library wasn''t working, but it seems like a lost cause now.

Thanks for all of the guys!!! despite the fact that I didn''t end up using it directly

Dwiel

Share this post


Link to post
Share on other sites