Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 22:36

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



starting FTP Upload from DLL ?

Discussion on starting FTP Upload from DLL ? within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
XxharCs's Avatar
 
elite*gold: 34
Join Date: Apr 2011
Posts: 1,475
Received Thanks: 1,227
starting FTP Upload from DLL ?

hey

i made a dll which is saving ur own game progress in a file.

now i also want to upload that file on a ftp server when the dll detaches the process.

is it possible to upload files when the dll is getting detached ?
i made it like this but it seems to dont work (getting the error of FtpPutFile when it fails)

Code:
...
ofstream ofile;
ofstream f;
char dest[9999];
TCHAR NPath[MAX_PATH];
WIN32_FIND_DATA FindFileData;
HINTERNET hOpen, hConnection;

void upload(char *bla);

BOOL WINAPI DllMain ( HMODULE hDll, DWORD dwReason, LPVOID lpReserved )
{
...
...
case DLL_PROCESS_DETACH:

		if(ofile) 
		{ 
			GetCurrentDirectory(MAX_PATH, NPath);
			
			add_log("\n\n[Log Closed]"); 
			ofile.close();
			Sleep(500);

			FindFirstFile("./progress.txt", &FindFileData);
			
			sprintf_s(dest, "%s\\%s", NPath, FindFileData.cFileName);
                        MessageBox(NULL,  dest, "Test", NULL);
			upload(dest);
                        break;
		}
	}
	return TRUE;
}

...
...


void upload(char *filepath)
{


	hOpen = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);

	

	hConnection = InternetConnect(hOpen, "example.bplaced.net", INTERNET_DEFAULT_FTP_PORT,
		"usernameExample", "passwordExample", INTERNET_SERVICE_FTP, NULL, NULL);

	

	if(!(FtpPutFile(hConnection, filepath, "/progress.txt", FTP_TRANSFER_TYPE_BINARY, INTERNET_FLAG_PASSIVE))){

			
		f.open("./Fehler.txt", ios::app);
		f << GetLastError() << endl;
		f.close();
	}else{

		MessageBox(NULL, "Successfully uploaded !", "Ftp Upload", NULL);
	}

	InternetCloseHandle(hConnection);
	InternetCloseHandle(hOpen);
	

}
... => means that there is the other code, didnt want to upload the whole code because it´s a lot of code

i hope u can help me
XxharCs is offline  
Old 10/25/2012, 12:53   #2
 
elite*gold: 0
Join Date: Jun 2012
Posts: 187
Received Thanks: 58
It is possible in theory, but only when the process tries to detach your DLL without shutting down.
If your DLL is being detached because your process is shutting down, you cannot guarantee that the WinSock Libraries are still loaded, and you cannot load libraries from a DLL's DllMain() function. You should restructure your program/library not to make use of external functions inside of DllMain(), because that is a recipe for guaranteed disaster.
tnd0 is offline  
Thanks
1 User
Old 10/25/2012, 13:10   #3
 
XxharCs's Avatar
 
elite*gold: 34
Join Date: Apr 2011
Posts: 1,475
Received Thanks: 1,227
thanks for the answer

but is there some alternative way to do this in some same way ?
because i wanted, when the process is shuting down, to upload the file without starting an extra application to upload the file^^
XxharCs is offline  
Old 10/25/2012, 15:51   #4
 
elite*gold: 0
Join Date: Jun 2012
Posts: 187
Received Thanks: 58
catch the shutdown message with a windowhook or hook the shutdown procedure.
tnd0 is offline  
Thanks
1 User
Reply


Similar Threads Similar Threads
[Projekt] MineTube ~ Video Upload/Bilder Upload und mehr! Team Gesucht
03/23/2011 - Minecraft - 21 Replies
Hallo, Da ich nun seit längerem in der Minecraft Section unterwegs bin und auch so schon lange Erfahrung mit dem Spiel gemacht habe, bin ich zum Entschluss gekommen ein neues Projekt zu starten. Doch was für ein Projekt? Es geht darum, dass viele Minecraft Player, mit Lets Play, Shows und Tutorials anfangen. Dies finde ich natürlich super, aber wieso sollte alles in YouTube un CO untergehen (ausgenommen Gronkh ;) ). Nun gehe ich dazu über, das Projekt namens MineTube zu starten. Was...
Starting Npc
07/10/2010 - Kal Online - 9 Replies
Sup guys i need realll big help my friends - friend made a kal server and she cant find good Job change NPC / F1 menu / Starting NPC we both would be so happy if u could help us out sry if u think this is begging i have downloaded Repacks ( 21 GB worth ) looking for F1 menus but they dont seem to be any Oo :confused: Sry for wrong section if its wrong (P.s i did search all i find is job hacks :D and Merchant hacks)
Help with starting phx !!!!
11/22/2009 - Lin2 Exploits, Hacks, Bots, Tools & Macros - 1 Replies
i have this message :''The library inject.dll is absent or is blocked by other application'' can anyone explain me what does this mean? and how to fix this? i'm tryin' to use l2phx.3.4.1.82.english .. i tried on interlude and final ... no results... :) help?



All times are GMT +2. The time now is 22:36.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.