Convert string to LPCSTR?maybe?

Hello guys i'm an other time here!

i have this code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "iostream"
#include "windows.h"
#include <msclr\marshal_cppstd.h>

namespace Downloadervc {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	using namespace std;
	using namespace msclr::interop;
//lot of shift...

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
	    
		System::String^ url;
		System::String^ path;
		url = this->textBox1->Text;
		path = this->textBox2->Text;
		std::string sUrl = marshal_as<std::string>(url);
		std::string sPath = marshal_as<std::string>(path);

		
		URLDownloadToFileA(NULL, sUrl.c_str(), sPath.c_str(),0, NULL);
		
	}


this code looks great but he gives me errors that i can't understand!
Why?
using visual studio 2015, CLR application with 1 form

i'm just learning winapi so i'm a little bit noob ahaha
Last edited on
There is an easier way to do it:
1
2
3
4
5
6
7
8
9
10
System::Void button1_Click(System::Object^ sender, System::EventArgs^  e) 
{
    System::String^ url;
    System::String^ path;
    url = this->textBox1->Text;
    path = this->textBox2->Text;
		
    System::Net::WebClient^ client = gcnew System::Net::WebClient;
    client->DownloadFile(url, path);
}

https://msdn.microsoft.com/en-us/library/system.net.webclient%28v=vs.100%29.aspx
Thanks! this way worked for me
but why my way didn't work?

EDIT

and for the download status? (i mean percentage)

EDIT 2

OMG That's a really slow download! Is it normal?
Last edited on
and for the download status? (i mean percentage)

No problem, the WebClient has a OnDownloadProgressChanged event.
https://msdn.microsoft.com/en-us/library/system.net.webclient.ondownloadprogresschanged%28v=vs.100%29.aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-2


OMG That's a really slow download! Is it normal?

It depends on the size of the file, the speed of your internet connection...
Topic archived. No new replies allowed.