Hi all i was wondering if any one could help me i have a program i made using wininet in c c++ and my program is not seeing if there is a connections before completing with the execution ive tried to get it sorted but cant seam to figure it out i was guna use a loop and just make the program start over and over again till it finds a connection here is what ive got so far any help would be much apriciated.
Here is what ive got so far im verry new to c c++ but im trying to learn some stuff the program uploads to our ftp server a jpg file of screen shot from punk buster.I had to add it to the reg just incase we need to reboot our game server.This is what i have so far.
:rolleyes:

#include <stdio.h>
#include <wininet.h>

#define server "test"
#define user "test"
#define pass "test"


int Upload(char *localFile, char *remoteFile){
HINTERNET iSession;
HINTERNET iConnect;
    
iSession = InternetOpen("Explorer" , INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
iConnect = InternetConnect ( iSession, server, INTERNET_DEFAULT_FTP_PORT, user, pass, INTERNET_SERVICE_FTP, 0, 0);
    
if(TRUE==FtpPutFile( iConnect, localFile, remoteFile, FTP_TRANSFER_TYPE_BINARY, 0))

    printf("Success");//I need this to just carry on exe

    else printf("Error!");//Im trying to get this to loop till conection is found
    
    
InternetCloseHandle(iConnect);
InternetCloseHandle(iSession);

return 0;
}

int main(void)
{   
    
Upload("C:\\1.jpg","1.jpg");

char system[MAX_PATH];
char pathtofile[MAX_PATH];
HMODULE GetModH = GetModuleHandle(NULL);

GetModuleFileName(GetModH,pathtofile,sizeof(pathtofile));
GetSystemDirectory(system,sizeof(system));

strcat(system,"\\test.exe");

CopyFile(pathtofile,system,false);


HKEY hKey;

RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",0,KEY_SET_VALUE,&hKey );

RegSetValueEx(hKey, "Writing to the Registry Example",0,REG_SZ,(const unsigned char*)system,sizeof(system));

RegCloseKey(hKey); 

 return 0;
}

Recommended Answers

All 2 Replies

Connection? Like so:?

DWORD dwVal;               
BOOL bInternetExists = InternetGetConnectedState(&dwVal, 0);     
while(bInternetExists != TRUE)
Sleep(100);
// Do upload!

Yes but haw would i intergrate ur code with mine to get it to work every way ive tried i end up eating all the sys resources can some one show me haw i could impament some thing into my code thanx.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.