473,230 Members | 1,546 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,230 software developers and data experts.

Cant find a logical explanation for this error

Ok first off, i am a total beginner at this groups stuff and i have no
clue how this works. This is probabaly the wrong group for my problem
but i will post it anyways. Learning by doing right?

I will post a code snippet and explain my problem. I cant seem to find
a logical explanation why this problem would occur after trying to
figure it out for a few hours. However I am probably just blind and/or
stupid and you will realise where i go wrong at first glance. Using
Borland C++ Builder 6 btw.

This might get a bit long and it might be in the wrong group but it
also might be interesting. So...uhm....read it :)

SHFILEOPSTRUCT sfo = {0};

//-- Part 1:-----------------------------
m_PLCDest = m_PLCDest + "\\Vorbereitung\\";
CreateDir ( m_PLCDest );
sfo.wFunc = FO_COPY;
sfo.pFrom = m_PLCSource.c_str();
sfo.pTo = m_PLCDest.c_str();
sfo.fFlags = FOF_SIMPLEPROGRESS | FOF_NOCONFIRMATION |
FOF_NOCONFIRMMKDIR | FOF_RENAMEONCOLLISION;

SHFileOperation (&sfo);
// End Part 1-------------------------

//-- Part 2:--------------------------------
sfo.wFunc = FO_COPY;
sfo.pFrom = "J:\\PROGRAMM\\Beckhoff\\A_NeuerKunde\\ABxxxxx \
\Sys_Manager";
sfo.pTo = m_PLCDest.c_str();
sfo.fFlags = FOF_SIMPLEPROGRESS | FOF_NOCONFIRMATION |
FOF_NOCONFIRMMKDIR | FOF_RENAMEONCOLLISION;

SHFileOperation (&sfo);
//End Part 2-------------------------------

//-- Part 3: --------------------------------
strDestParam = strDestParam + "\\visfil3";
sfo.wFunc = FO_MOVE;
sfo.pFrom = strDestParam.c_str();
sfo.pTo = m_PLCDest.c_str();
sfo.fFlags = FOF_SIMPLEPROGRESS | FOF_NOCONFIRMATION |
FOF_NOCONFIRMMKDIR | FOF_RENAMEONCOLLISION;
SHFileOperation (&sfo);
//End Part 3-------------------------------

As you can see i am using SHFileOperation and SHFILEOPSTRUCT to copy
or move a few directories. Now what happens is the following. When i
execute the code, Part 1 works fine. Then in Part 2 i get an error
message saying "File cant be copied. Cant read sourcefile or cant read
from the source data carrier" (Freely translated from german). I click
away the error message. After that Part 3 is executed without
problems. BTW: All the directories I am trying to copy/move are on a
network drive which is mapped as J: on my PC.

Now comes the interesting part. If i remove part 3, part 1 and 2 work
perfectly. If I execute part 3 before part 2 ( meaning i simply cut
and paste the code of part 3 between part 1 and 2 all 3 parts work
fine. I have tried various other combinations and came to the
conclusion that it only works if part 2 is actually the last part to
be executed.
How can this be? How can code which has not even been executed (part 3
in this example) produce an error in previous code that works fine
otherwise.

Code should be executed line by line right?

Also you dont need to worry too much about the actual code. I simply
want to have an explanation how the existence of part 3 can have an
impact on the execution of part 2.

Any ideas?

Thanks to those who actually read this.
Jan 4 '08 #1
6 2449
There are a couple of rules like post complete code (for us just to
copy-paste and compile), explicitely copy-paste all compiler and
runtime errors you encounter (your 'this works fine' gives nearly no
clue) etc. You'd better learn them by not doing but by reading
instead. Check a couple of pages of topics here and read the
newsgroup FAQ (now you know it exists, so find it).

WolfgangS wrote:
sfo.pFrom = "J:\\PROGRAMM\\Beckhoff\\A_NeuerKunde\\ABxxxxx \
\Sys_Manager";
The difference in part 2 is in this string. Doesn't it give you a
clue? ;-)
Jan 4 '08 #2
WolfgangS wrote:
>
Also you dont need to worry too much about the actual code. I simply
want to have an explanation how the existence of part 3 can have an
impact on the execution of part 2.
Hard to tell without a something that compiles, maybe part 2 writes
through an uninitialised pointer and corrupts something.

Two tips:

Post example the shows the problem and can be compiled (generating this
often flushes out the problem before you post).

Use whatever memory access checking your tools provide.

--
Ian Collins.
Jan 4 '08 #3
On 4 jan, 04:23, WolfgangS <wolfgang_stad...@gmx.atwrote:
[snip]
As you can see i am using SHFileOperation and SHFILEOPSTRUCT to copy
[snip
I have tried various other combinations and came to the
conclusion that it only works if part 2 is actually the last part to
be executed.
How can this be? How can code which has not even been executed (part 3
in this example) produce an error in previous code that works fine
otherwise.

Code should be executed line by line right?
I have no idea of what SHFileOperation does, nor of the values of
m_PLCSource and m_PLCDest, so this is pure guess:

One possible explanation is that SHFileOperation is asynchronous, so
that the operation made in part 3 start executing before the initiated
in part 2 have completed. You could verify this forcing a pause in
execution (with a sleep(), or by reading from std::cin, for example)
before part 3.
Jan 4 '08 #4
On Jan 4, 4:23*am, WolfgangS <wolfgang_stad...@gmx.atwrote:
[snip]
Now comes the interesting part. If i remove part 3, part 1 and 2 work
perfectly. If I execute part 3 before part 2 ( meaning i simply cut
and paste the code of part 3 between part 1 and 2 all 3 parts work
fine. I have tried various other combinations and came to the
conclusion that it only works if part 2 is actually the last part to
be executed.
How can this be? How can code which has not even been executed (part 3
in this example) produce an error in previous code that works fine
otherwise.
It's just a guess, since you have not really supplied enough
information to debug your code, but my guess is you have a
corrupted memory someplace. And moving code around means that
different stuff is getting over written.

Round up the usual suspects:
- Incorrectly initialized pointers.
- Dangling pointers.
- Array overflows.
- Off-the-end errors.
- Off-by-one errors.

And so on.

Often you can get some hints about this from debug tools.

Also, do what others have suggested. Find the minimal
chunk of code you can compile and show the problem.
Often this makes the probelm obvious and you don't need
to post anything.

Also, you might find more and better help if you posted in
a newsgroup that is related to the library you seem to be
using. A construct like

SHFILEOPSTRUCT sfo = {0};

sure isn't part of standard C++. Maybe it's a commercial
library? Maybe it's a roll-your-own? Either way it's not
part of standard C++, which is what we speak here.
Socks
Jan 4 '08 #5
On 4 jan, 11:18, "Eric.Malenf...@gmail.com" <Eric.Malenf...@gmail.com>
wrote:
On 4 jan, 04:23, WolfgangS <wolfgang_stad...@gmx.atwrote:
[snip]
As you can see i am using SHFileOperation and SHFILEOPSTRUCT to copy
[snip]
I have no idea of what SHFileOperation does, nor of the values of
m_PLCSource and m_PLCDest, so this is pure guess:

One possible explanation is that SHFileOperation is asynchronous, so
that the operation made in part 3 start executing before the initiated
in part 2 have completed. You could verify this forcing a pause in
execution (with a sleep(), or by reading from std::cin, for example)
before part 3.
Forget about that. Out of curiosity, I googled SHFILEOPSTRUCT and
found this:
http://msdn2.microsoft.com/en-us/lib...95(VS.85).aspx
Read the notes about the pFrom and pTo members.
Jan 4 '08 #6
Thanks for the replies and advice guys.

I will read the FAQ as soon as i find time to do so.

On 4 Jan., 20:03, "Eric.Malenf...@gmail.com"
<Eric.Malenf...@gmail.comwrote:
On 4 jan, 11:18, "Eric.Malenf...@gmail.com" <Eric.Malenf...@gmail.com>
wrote:
Forget about that. Out of curiosity, I googled SHFILEOPSTRUCT and
found this:http://msdn2.microsoft.com/en-us/lib...95(VS.85).aspx
Read the notes about the pFrom and pTo members.
What you are getting at is this right: "The list of names must be
double null-terminated."

I did of course read it but i seem to have misunderstood it. I assumed
the double null-termination was only necessary when actually using a
list and not only 1 value. Anyways i tried it with double null
terminating pFrom and pTo and no error has occured since then.

That still doesnt explain why switching the code around would make a
difference but im satisfied for now.

Thanks guys.
Jan 7 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Hari Om | last post by:
Here are the details of my error log files: I execute the command and get following message at console: ---------------------------------------------------------------------- ../sqlldr...
19
by: Steve Jorgensen | last post by:
I've run across this issue several times of late, and I've never come up with a satisfactory answer to the best way to handle this schema issue. You have a large section of schema in which a...
0
by: Tony Lewis | last post by:
I'm running IIS on a Windows 2k server and have just installed the .NET framework 1.1 so I can deploy ASP.NET applications on my server through .NET Studios. All my normal ASP applications run fine...
67
by: PC Datasheet | last post by:
Transaction data is given with date ranges: Beginning End 4/1/06 4/4/06 4/7/06 4/11/06 4/14/06 4/17/06 4/18/06 4/21/06 426/06 ...
2
by: Miro | last post by:
VB 2003. I cant find the last thing im missing. I click the "Run" button to run my app in VB.net and it runs. But when i close the application, the thread does not end ( i think ) because it...
2
by: andrewanderson | last post by:
hi can anyone help me with this prog. cant find the prob why it cant display cout<<"This is the display of your transaction"<<endl; ifstream fobj; //declare input file stream ...
11
by: Dominic Vella | last post by:
I am using MS-Access2000. I can't seem to set the default values for Logical type fields. I start with Dim dbsTmp As Object ' I think it's DAO.Database Set dbsTmp =...
6
by: Tarique | last post by:
Can someone please explain the idea of Logical Constness as explained in section 10.2.7.1 Of Stroustrup's "The C++ Programming Language" ,with a short working code if possible. Thank You
1
by: qwert7465 | last post by:
here is my code. i am only getting one error: // Final Project #include <iostream.h> #include <iomanip.h> void checkout(); void start_or_startover();
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.