473,769 Members | 4,985 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help needed with this code

48 New Member
Hi all,

I am presently working with folder and would like to find out the number of files in that particular directory.
But I am getting the following error:

error C2664: 'FindFirstFileW ' : cannot convert parameter 1 from 'const char *' to 'LPCWSTR'

the code is as follows:
Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #define _WIN32_WINNT 0x0400
  3. #include <windows.h>
  4. #include <stdio.h>
  5. #include <string>
  6. using namespace std;
  7.  
  8. int main(int argc, char *argv[])
  9. {
  10. WIN32_FIND_DATA FindFileData;
  11. HANDLE hFind;
  12.  
  13. string str1 = "abc.txt";
  14.  
  15. printf ("Target file is %s.\n", str1.c_str());
  16. hFind = FindFirstFile(str1.c_str(), &FindFileData);
  17. if (hFind == INVALID_HANDLE_VALUE)
  18. {
  19. printf ("Invalid File Handle. GetLastError reports %d\n", GetLastError());
  20. return (0);
  21. }
  22. else
  23. {
  24. printf ("The first file found is %s\n", FindFileData.cFileName);
  25. FindClose(hFind);
  26. return (1);
  27. }
  28. }
any help is appreciated!

Thanks!!
Aug 7 '07 #1
2 1760
Darryl
86 New Member
It's because you are compiling in Unicode but passing an ANSI string to your function. Use a wstring instead. and wrap your literals in TEXT("your string")

Other suggestions if you really want to make it Unicode neutral is:

1. use TCHAR.H

2. create a neutral string type like this: typedef tstring basic_string<TC HAR>;

3. use int _tmain(INT argc, _TCHAR **argv instead of int main...
Aug 7 '07 #2
sicarie
4,677 Recognized Expert Moderator Specialist
And please have a look at the Posting Guidelines in the meantime. Thanks!
Aug 7 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

28
3306
by: stu_gots | last post by:
I have been losing sleep over this puzzle, and I'm convinced my train of thought is heading in the wrong direction. It is difficult to explain my circumstances, so I will present an identical make-believe challenge in order to avoid confusing the issue further. Suppose I was hosting a dinner and I wanted to invite exactly 12 guests from my neighborhood. I'm really picky about that... I have 12 chairs besides my own, and I want them all...
7
1762
by: Tina | last post by:
I have an asp project that has 144 aspx/ascx pages, most with large code-behind files. Recently my dev box has been straining and taking long times to reneder the pages in the dev environment. After addding another Crystal report, vs.net will no longer build the project - it just goes away - no message no nothing. My other dev box will build it but won't run it in debug. I ran a vs.net repair but it still does the same thing. vs.net...
10
14857
by: Mae Lim | last post by:
Dear all, I'm new to C# WebServices. I compile the WebService project it return no errors "Build: 1 succeeded, 0 failed, 0 skipped". Basically I have 2 WebMethod, when I try to invoke the first method it is working fine. Then when I try to invoke the second method it return me an error, Just In-Time Debugging, with error message "An exception 'System.StackOverflowException' has occurred in WebServices"
5
1228
by: Buchwald | last post by:
hello group, I have a long (large) script that shows a random picture when a webpage is refreshed. It's long because i have a lot of pictures: 246 Here is some code: ----------------------------------------------------------------------------------------------- <!-- image1="smallpics/001-smallpic.jpg"
3
2417
by: Kitana907 | last post by:
Hi- I'm attempting to write a module that uses and updates info from two tables and does the following: Opens the recordset of a table called "tblstoreinv" If the Needed Field in the tblstoreinv table is null and is less than the DCOH field from the tbldcinv then: The Shipped Field in the tblstoreinv table equals the Needed Field and the DCOH field from tbldcinv = DCOH - Shipped Else If Needed from tblstoreinv is > DCOH from tbldcinv,...
4
2970
by: perryschon | last post by:
Can someone please help me out with the Visual Basic source code needed that allows configuration and usage of comm ports in any PC? I am constructing an asynchronous serial communication RS-232 circuit which will include serial cables (transmitter and receiver) connected from one pc to another pc with a 9-pin null modem in between. The VB program will be used to input the data and the output will appear on the remote PC. I need help in...
5
2012
by: justbovo | last post by:
Hello, My name is Justin. I am working on a part of a Find Memory module for a program. Here's how it works.. I enter '13' at the main menu which branches out to my Find Memory module. I ask the user how much Memory is needed and saved it as 'Needed_Memory_Amount '. Then I run thru a couple of loops to see what I can do. Either I find a spot for the memory on the 'FixedBlockTable', or I must give them a spot on the 'MemoryWaitTable'.
3
7072
by: cwoll | last post by:
Hi I need help. I have a ms access 2003 database that I would like to upgrade to ms access 2007. The first time I opened I had to fix a few references it wanted a DAO2535.TLB file witch I gave it, and a utility.mda file witch I think i gave it. The instructions on Microsoft's web sight were not very clear where to put the utility.mda so I am not sure if I have it at the right place. The Database does not ask for it anymore. I have...
1
13743
by: Tom | last post by:
First, I posted a similar request for help in another group and now don't find the posting. Problem with my newsreader perhaps ... but apologies if this appears as a cross posting. My code is inconsistent in the detection of a vertical scrollbar. This involves situations when less than the client area is needed to hold the small amount of data. The inconsistency is when adjusting the panel size within or just below the bottom row....
32
2792
by: =?Utf-8?B?U2l2?= | last post by:
I have a form that I programmatically generate some check boxes and labels on. Later on when I want to draw the form with different data I want to clear the previously created items and then put some new ones on. In my code I am doing the following: For Each ctrl In tpMain.Controls If TypeOf (ctrl) Is CheckBox Then If ctrl.Name.StartsWith("chkS") Then ctrl.Visible = False
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7408
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.