Hi,

I'm new to APIs. Got the code below to compile (with 3 warnings C4129) but it won't output to the designated path. I created the txt file ahead of time, nqquotes.txt, but after the code compiles, that file stays empty.

Thanks for your help,
TR

#include "stdafx.h"
#include <tchar.h>
#include <urlmon.h>
#include <iostream>
using namespace std;
#pragma comment(lib, "urlmon.lib")

int main()
{
    cout << "downloading NQ data from Quandl...";
    HRESULT hr = URLDownloadToFile 
        ( NULL, _T("https://www.quandl.com/api/v1/datasets/CME/NQH2015.csv"),_T("C:\users\my documents\visual studio 2008\projects\nq data\nqquotes.txt"), 0, NULL);

cout << "Done!" << endl;

    system("PAUSE");
}

Recommended Answers

All 4 Replies

First thing you do is check the the value of hr.

Thank you Suzie.

You mean checking as in something like this?

if (hr == S_OK) ?

You mean checking as in something like this?

if (hr == S_OK) ?

Yes.

The main problem with your code is that the szFileName in URLDownloadToFile is invalid.
"C:\users\my documents\visual studio 2008\projects\nq data\nqquotes.txt"
should be either
"C:\\users\\my documents\\visual studio 2008\\projects\\nq data\\nqquotes.txt"
or
"C:/users/my documents/visual studio 2008/projects/nq data/nqquotes.txt"

It's also not necessary to pre-create the text file. If URLDownloadToFile is successful then the text file will be created.

Thank you Nullptr, that worked perfect.

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.