-
C++ API / function help
Hi, I'm kind of new to C++, but not to programming in general. I'm trying to run a program that will download a file, but I'm getting errors at lines 9 and 12.
Code:
#include <iostream>
#include <string>
#include <windows.h>
int Url(LPCTSTR szURL, LPCTSTR szFileName){
HRESULT URLDownloadToFile(
LPUNKNOWN pCaller,
LPCTSTR szURL,//URL
LPCTSTR szFileName,//Save file
DWORD 0,/ERROR 1
LPBINDSTATUSCALLBACK lpfnCB
);
if (HRESULT == "S_OK") {//ERROR 2
return 1;
}
}
int WINAPI
WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR pszCmdLine, int iCmdShow)
{
int n = Url("http://google.com/","g.html");
return 0;
}
I'm just trying to simplify the API to get used to using functions. Any help would be appreciated!
-
Line 9, a comment is '//' not '/' :)
Line 11, I would suspect you have some kind of type mismatch, would have probably been helpful if you posted the errors...
-
ok, thanks for the quick reply! I added that slash in after, so that was a type-o on my part, sorry.
..mmm.. ig it was line 12, sorry.
9 expected `,' or `...' before numeric constant
12 expected primary-expression before '==' token
-
Hi
Check the declaration of the URLDownloadToFile-Function[1].
Code:
HRESULT URLDownloadToFile( LPUNKNOWN pCaller,
LPCTSTR szURL,
LPCTSTR szFileName,
DWORD dwReserved,
LPBINDSTATUSCALLBACK lpfnCB
);
dwReserved has to be zero.
If you wish to call URLDownloadToFile from within URL(),
you have to pass parameters to URLDownloadToFile, like
Code:
HRESULT myHRESULT;
myHRESULT=URLDownloadToFile(NULL,szURL,szFileName,0,NULL);
You also have to declare variables, like myHRESULT of type
HRESULT, such that the variable can store the HRESULT returned
by the function URLDownloadToFile. I have set pCaller and lpfnCB
to NULL, since we want to make this as simple as possible.
Furthermore, you cannot compare a variable-type with content,
as in HRESULT == "S_OK". You have to compare a variable with content,
like
.
Then, S_OK is a representant of a constant value, not a string.
You may have a look at a C/C++ tutorial[2,3]. Invest one hour
to understand differences between function decalarations and
function calls.
Good luck :)
[1] http://msdn.microsoft.com/library/de...loadtofile.asp
[2] http://www.antionline.com/showthread...hreadid=263493
[3] http://www.antionline.com/showthread...hreadid=264033
-
Quote:
Originally posted here by sec_ware
dwReserved has to be zero.
I did put it in as zero and removed it from being passed into the function, and I also removed the ones that would be NULL. So all I would have to do is pass the URL and the file name, because the others are already taken care of...or at least thats what I was trying to do. That is why the URL function has only:
(LPCTSTR szURL, LPCTSTR szFileName)
because thats all it needs that would change anything. So why isn't what I'm trying to do working?