New to Windows programming - help!

This is a discussion on New to Windows programming - help! within the Windows Programming forums, part of the Platform Specific Boards category; I'm following a simple tutorial (the adrianxw.dk one) to list the files in a directory. The code is this: Code: ...

  1. #1
    Registered User Sharke's Avatar
    Join Date
    Jun 2008
    Location
    NYC
    Posts
    303

    New to Windows programming - help!

    I'm following a simple tutorial (the adrianxw.dk one) to list the files in a directory. The code is this:

    Code:
    #include <windows.h> 
    #include <iostream> 
    using namespace std;
    
    int main()
    {
        HANDLE hFind;
        WIN32_FIND_DATA FindData;
    
        cout << "A very basic FindFirst/Next demo.\n" << endl;
    
    // Find the first file
    
        hFind = FindFirstFile("C:\\Windows\\*.exe", &FindData);
        cout << FindData.cFileName << endl;
    
    // Look for more
    
        while (FindNextFile(hFind, &FindData))
        {
            cout << FindData.cFileName << endl;
        }
    
    // Close the file handle
    
        FindClose(hFind);
    
        return 0;
    }
    However when I try to compile it using Visual C++ Express, I'm given the following error:

    Code:
     error C2664: 'FindFirstFileW' : cannot convert parameter 1 from 'const char [17]' to 'LPCWSTR'
    Can someone please explain what's going wrong?

  2. #2
    Registered User Sharke's Avatar
    Join Date
    Jun 2008
    Location
    NYC
    Posts
    303
    OK so I did the obvious and cast the string argument to a LPCWSTR and it compiles OK...except that when I run it, all it prints is a single address in hex, instead of file names. How can I get this to work?
    Last edited by Sharke; 04-27-2009 at 10:42 PM.

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    LPCWSTR is a wide character string. Either you need to undefine unicode or else precede all string literals with 'L', eg:

    FindFirstFile(L"C:\\Windows\\*.exe", &FindData);
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    Registered User Sharke's Avatar
    Join Date
    Jun 2008
    Location
    NYC
    Posts
    303
    Quote Originally Posted by Sebastiani View Post
    LPCWSTR is a wide character string. Either you need to undefine unicode or else precede all string literals with 'L', eg:

    FindFirstFile(L"C:\\Windows\\*.exe", &FindData);
    Do you know how to disable unicode in VC++ Express? I did this a while ago but I can't seem to find the option again.

  5. #5
    Registered User Sharke's Avatar
    Join Date
    Jun 2008
    Location
    NYC
    Posts
    303
    False alarm. I found and disabled unicode and the program is working....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Windows 98/2000 programming in Windows XP
    By Bill83 in forum Windows Programming
    Replies: 3
    Last Post: 07-22-2005, 02:16 PM
  2. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 05:48 PM
  3. dual boot Win XP, win 2000
    By Micko in forum Tech Board
    Replies: 6
    Last Post: 05-30-2005, 02:55 PM
  4. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 12:19 AM
  5. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 05:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21