C++ API / function help
Results 1 to 5 of 5

Thread: C++ API / function help

  1. #1
    Senior Member
    Join Date
    Apr 2005
    Location
    USA
    Posts
    422

    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!

  2. #2
    Jaded Network Admin nebulus200's Avatar
    Join Date
    Jun 2002
    Posts
    1,356
    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...
    There is only one constant, one universal, it is the only real truth: causality. Action. Reaction. Cause and effect...There is no escape from it, we are forever slaves to it. Our only hope, our only peace is to understand it, to understand the 'why'. 'Why' is what separates us from them, you from me. 'Why' is the only real social power, without it you are powerless.

    (Merovingian - Matrix Reloaded)

  3. #3
    Senior Member
    Join Date
    Apr 2005
    Location
    USA
    Posts
    422
    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

  4. #4
    Senior Member
    Join Date
    Mar 2004
    Posts
    557
    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
    Code:
    myHRESULT == S_OK
    .

    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
    If the only tool you have is a hammer, you tend to see every problem as a nail.
    (Abraham Maslow, Psychologist, 1908-70)

  5. #5
    Senior Member
    Join Date
    Apr 2005
    Location
    USA
    Posts
    422
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 Security News

     Patches

       Security Trends

         How-To

           Buying Guides