473,378 Members | 1,321 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

using SHFileOperation to create a file

Hi all
I am tring to copy a file.The code is as below

int _tmain(int argc, _TCHAR* argv[])
{

string s3,s4;

s3="C:\\test\\to";
s4="C:\\test\\from\\sam.txt";
LPCTSTR ptr=s3.c_str();
LPCTSTR ptr1=s4.c_str();


SHFILEOPSTRUCT s = { 0 };
//s.hwnd = m_hWnd;
s.wFunc = FO_COPY;
s.pTo =ptr;
s.pFrom =ptr1;
s.fFlags = FOF_SILENT;
int i =SHFileOperation( &s );

return 0;
}

The return value of SHFileOperation is 1026.

It works fine if i assign the string directly
say like
s.pTo ="C:\\test\\to ";

I need to convert the string to LPCTSTR
How can correct the above code

Cheers,
Sam
Mar 10 '08 #1
1 3207
weaknessforcats
9,208 Expert Mod 8TB
You ned to use your TCHAR mappings thourghout your code:
s.pTo ="C:\\test\\to ";

I need to convert the string to LPCTSTR
That is:
Expand|Select|Wrap|Line Numbers
  1. s.pTo =TEXT("C:\\test\\to ");
  2.  
  3.  
Now you have your LPCTSTR.

You need to fix the other places in your code.

Now, you cannot use the C++ string object out in public like this:
string s3,s4;
because it has to be a wstring when you have your Unicode switch set.

I recommend a macro:
Expand|Select|Wrap|Line Numbers
  1. #ifdef _UNICCODE
  2. typedef wstring  tcharstring;
  3. #else
  4. typedef string  tcharstring;
  5. #endif
  6.  
and then define you strings as:
Expand|Select|Wrap|Line Numbers
  1. tcharstring s3,s4;
  2.  
Remember, you can have no explicit types that change between ASCII and UNICODE.
Mar 11 '08 #2

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

Similar topics

1
by: mt | last post by:
How can i use the "SHFileOperation" with vb.net. i use the below code; but i get the error " Object reference not set to an instance of an object" please advise (and can i use this api for...
0
by: avishay | last post by:
Hi All, I want to use SHFileOperation using Python and Win32 extentions, in order to move a file to the trash can. The function itself can be accessed by importing win32com.shell.shell. However, I...
3
by: Christian Blackburn | last post by:
Hi Gang, I would like to have my program use the built in Move and Copy Dialogs that are used by Windows Explorer/My Computer. Thanks in Advance, Christian Blackburn
3
by: Lespaul36 | last post by:
I know that this is the API to use..is there a way to use it to delete an entire directory instead of just a file?
2
by: Lespaul36 | last post by:
Is there a way to use shfileoperation to delete an entire folder instead of just the files?
14
by: Just Me | last post by:
Can anyone fix the code below? I need to set pTo to NULL and pFrom to a fullfilepath followed by two NULLs Below Filename is a string With FileOperation ..wFunc = FO_DELETE ..pFrom =...
2
by: RichardF | last post by:
I have a simple function to copy a file. If I call this with the following paramerters... psFrom = C:\12345678901234567890.abc psTo = C:\12345678901234567890.xyz.abc The TO file ends up...
0
by: =?Utf-8?B?TkVXMi5ORVQ=?= | last post by:
I have a .NET component (VC++) with native C++ at it's core. The native C++ code makes a call to SHFileOperation to delete a directory and it's contents. When I host the .NET component in a VB...
7
by: MLH | last post by:
If I'm using the following in a procedure... DoCmd.GoToRecord acDataForm, "FormName", acNext, 4 .... how can I recognize the EOF condition? Using GoToRecord, I find myself lost when trying to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.