TedCopple Posted February 17, 2011 Share Posted February 17, 2011 I need a little help here. I have a function currently that allows me to send data to a php script from my C++ application. How can I do the opposite? C++ Code below to send data to the php script: void SendData() { char* Navigate = new char[500]; memset(( void* )Navigate, 0, 500); char* Version = "Version 1.0"; sprintf(Navigate, "MYSITE.COM/GetData.php?v=%s", Version); SendFunction(Navigate); } DWORD SendFunction(char* link) { char* szURL = link; HINTERNET hSession; HINTERNET hRequest; hSession = InternetOpen( // Make internet connection. "Microsoft Internet Explorer", // agent INTERNET_OPEN_TYPE_PRECONFIG, // access NULL, NULL, 0); // defaults if(hSession) { hRequest = InternetOpenUrl( // Make connection to desired page. hSession, // session handle link, // URL to access NULL, 0, 0, 0); // defaults } if(hRequest) { bool bResult = HttpSendRequest(hRequest, NULL, 0, NULL, 0); } InternetCloseHandle(hSession); return 0; } php script that receives the data from the C++ application: <? $f=fopen('FILE','a'); fwrite($f,$_GET['v'] \n); fclose($f); ?> This just simply sends the char* Version = "Version 1.0" text to the php script witch _GETs it and writes it to a file. Simple and impractical, however I just wanted to get something rolling. It works fine, now I need to do the opposite. I need to do exactly what this function does, but flip it around!. I want store a value in the php script, and get that value with my C++ application, and then log it out. Any help here please!? php script for what I want to do: <?php $dbhost = 'MyHost'; $dbuser = 'MyUserName'; $dbpass = 'MyPassword'; mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'MyDB'; mysql_select_db($dbname); $query = mysql_query("SELECT * FROM AppVersion"); while($row = mysql_fetch_array($query)) { $version = $row['Version Info']; } ?> I need to query the php script from my C++ application and retrieve the value of $version. How can I setup the php script to export that value $version for the C++ app and use the WinInet funcs to retrieve it? Note: I am just trying to get a feel for how all of this works right now, so none of this really has a practical use at the moment, but is helping me progress in my overall goal, so it will be very helpful to get this worked out. Quote Link to comment Share on other sites More sharing options...
btherl Posted February 17, 2011 Share Posted February 17, 2011 It really depends on what you want to do. The simplest way is to have your C++ script make another request, have your php script print out the data and then you look at the data you get back from the http request. Quote Link to comment Share on other sites More sharing options...
TedCopple Posted February 17, 2011 Author Share Posted February 17, 2011 It really depends on what you want to do. The simplest way is to have your C++ script make another request, have your php script print out the data and then you look at the data you get back from the http request. Yea thats what I am trying to figure out how to do now. I am trying to use InternetQueryDataAvailable and InternetReadFile to get the data I printed out with my php script. I simply echoed the data that I want at the end of my .php script. Here is what I have tried in C++ to get that data, but is not working right: HINTERNET hSession; HINTERNET http; HINTERNET hRequest; bool bResult; hSession = InternetOpen( // Make internet connection. "Microsoft Internet Explorer", // agent INTERNET_OPEN_TYPE_PRECONFIG, // access NULL, NULL, 0); // defaults if(hSession) { http = InternetConnect(hSession, "MYSITE", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); } if(http) { hRequest = HttpOpenRequest(http, "GET", "/Version.php", NULL, NULL, NULL, INTERNET_FLAG_RELOAD, 0); } if(hRequest) { bool bResult = HttpSendRequest(hRequest, NULL, 0, NULL, 0); } if(bResult) { DWORD getquerydata; InternetQueryDataAvailable(hRequest, &getquerydata, 0, 0); DWORD dwBYTEsRead; LPCSTR buffer; buffer = new char[getquerydata]; InternetReadFile(hRequest, (LPVOID)buffer, getquerydata, &dwBYTEsRead); } InternetCloseHandle(hSession); Quote Link to comment Share on other sites More sharing options...
btherl Posted February 18, 2011 Share Posted February 18, 2011 I think you would be better off asking on a C++ forum. Quote Link to comment Share on other sites More sharing options...
TedCopple Posted February 18, 2011 Author Share Posted February 18, 2011 I think you would be better off asking on a C++ forum. Hey, thanks for trying to help. I figured out the issue and have it working now. It really helped out a lot re-creating the project in a console app to test with. Using cout allowed to me see some things that my logs were not showing and I figured out why the buffer was not being filled with the correct data. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.