Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
January 7th, 2013, 12:16 PM
 speedbooster
Contributing User

Join Date: Jun 2005
Posts: 225
Time spent in forums: 2 Days 7 h 14 m 9 sec
Reputation Power: 0
Copy files from SMB using Win32

HI, I'm trying to copy files from "\\ip\folder\file.txt" to "c:\file.txt".

I do not want to use any high-level APIs, not even from MS. I want to keep it to the lowest abstraction level possible at Win32 API.

Sincerely,
speedbooster

#2
January 7th, 2013, 03:44 PM
 mitakeet
I'm Baaaaaaack!

Join Date: Jul 2003
Location: Maryland
Posts: 5,538
Time spent in forums: 2 Weeks 4 Days 2 h 38 m 46 sec
Reputation Power: 243
If you are copying from a network drive, as appears to be the case, then you will have to be authenticated which means you have to work through APIs (unless you want to attempt to recreate teh arcane crypto framework used to talk to the remote drive), almost certainly OS dependent APIs (meaning even if they are third-party, they are running in kernel space). I would be suprised if you get much help here, we tend to focus on ANSI programming. Also, for all practical purposes, what you are asking is language independent. Devshed should have some forums better suited for your question.
__________________

My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
Free code: http://sol-biotech.com/code/.
Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.

It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
--Me, I just made it up

The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
--George Bernard Shaw

#3
January 7th, 2013, 03:57 PM
 speedbooster
Contributing User

Join Date: Jun 2005
Posts: 225
Time spent in forums: 2 Days 7 h 14 m 9 sec
Reputation Power: 0

anyways, i have opened the connection and mapped the network share with correct login to z: drive. I need to copy files now. Looking for function. i don't want to use system()

#4
January 8th, 2013, 11:28 AM
 speedbooster
Contributing User

Join Date: Jun 2005
Posts: 225
Time spent in forums: 2 Days 7 h 14 m 9 sec
Reputation Power: 0
who the heck's void pointer?!

I know what I am talking about over here !! I'm an old member, though not much active.

#5
January 8th, 2013, 11:31 AM
 mitakeet
I'm Baaaaaaack!

Join Date: Jul 2003
Location: Maryland
Posts: 5,538
Time spent in forums: 2 Weeks 4 Days 2 h 38 m 46 sec
Reputation Power: 243
Right, so you should realize that he is commenting on Nancy's useless post.

#6
January 8th, 2013, 11:39 AM
 Scorpions4ever
Banned ;)

Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,536
Time spent in forums: 2 Months 3 Days 6 h 2 m 28 sec
Reputation Power: 4106
Quote:
 Originally Posted by speedbooster thanks, perhaps im asking about windows programming? anyways, i have opened the connection and mapped the network share with correct login to z: drive. I need to copy files now. Looking for function. i don't want to use system()

Use CopyFile() or CopyFileEx() perhaps.
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

#7
January 8th, 2013, 01:27 PM
 speedbooster
Contributing User

Join Date: Jun 2005
Posts: 225
Time spent in forums: 2 Days 7 h 14 m 9 sec
Reputation Power: 0
Oh, thanks mitakeet.
@scorpion4ever, yeah i m doing that now. thanks a lot : )

#8
January 8th, 2013, 01:32 PM
 speedbooster
Contributing User

Join Date: Jun 2005
Posts: 225
Time spent in forums: 2 Days 7 h 14 m 9 sec
Reputation Power: 0
i have a question actually. When i open \\ip in the start menu or 'run' in xp, it doesn't 'map' the network path to a drive, but i can still use it. explorer shows '\\ip\path\to\directory\whatever\' in address bar.

'net use' command also shows a 'connection??'
How come I'm using the resource without mapping?

Is it possible to do with win32 as well? Like with CopyFile ? With CopyFile(), I am currently 'mapping' the path to a drive and then copying. But I'd like something like I've mentioned to be done in my C++ program.

#9
January 8th, 2013, 03:30 PM
 Scorpions4ever
Banned ;)

Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,536
Time spent in forums: 2 Months 3 Days 6 h 2 m 28 sec
Reputation Power: 4106
If you look at the docs, it says that CopyFile() can also accept "\\ip\path\to\directory\whatever\" type strings.

#10
January 10th, 2013, 12:24 PM
 speedbooster
Contributing User

Join Date: Jun 2005
Posts: 225
Time spent in forums: 2 Days 7 h 14 m 9 sec
Reputation Power: 0
hmmm, i think it was returning 66 or 85 error. Perhaps i need to kill all SMB connections with net command ....

Anyways, I got another problem. I'm trying to launch Internet explorer and open a page in it. Its working, but the ExecWB function in IWebBrowser2 is giving access violations.

Code:
Unhandled exception at 0x7338C9F1 in file.exe: 0xC0000005: Access violation executing location: 0x00000000

It goes away if I remove the line. The line is:
Code:
pWBApp->ExecWB(OLECMDID_SAVE, OLECMDEXECOPT_DODEFAULT, NULL, NULL);

// i also tried

pWBApp->ExecWB(OLECMDID_NEW, OLECMDEXECOPT_DODEFAULT, NULL, NULL);


Reference: http://msdn.microsoft.com/en-us/lib...v=vs.85%29.aspx

#11
January 10th, 2013, 12:55 PM
 salem
Contributed User

Join Date: Jun 2005
Posts: 4,261
Time spent in forums: 2 Months 4 Weeks 1 Day 15 h 9 m 6 sec
Reputation Power: 1827
> Access violation executing location: 0x00000000
You tried to call NULL!

> pWBApp->ExecWB(OLECMDID_SAVE, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
It would seem that the ExecWB member is not set up at all.

> It goes away if I remove the line.
Actually, I would recommend you get familiar with using the debugger.

Find out where ExecWB "should" have been initialised, and put a breakpoint on it. Investigate WHY it isn't being set up - did you miss an init call somewhere - read the documentation.

Random hacking of adding and commenting out lines of code is voodoo programming

> hmmm, i think it was returning 66 or 85 error.
Don't think - KNOW!
Trust me, you'll find yourself rapidly shunned if we spend effort looking into those two values, and you show up tomorrow saying "sorry, my bad - it was 42".
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

#12
January 10th, 2013, 01:57 PM
 speedbooster
Contributing User

Join Date: Jun 2005
Posts: 225
Time spent in forums: 2 Days 7 h 14 m 9 sec
Reputation Power: 0
i was getting both 66 and 85, trying different things. But i got it to work anyhow.

you think i didn't read the docs before asking? Here is the 'extensive' documentation from MS:

http://msdn.microsoft.com/en-us/lib...v=vs.85%29.aspx

#13
January 10th, 2013, 02:37 PM
 salem
Contributed User

Join Date: Jun 2005
Posts: 4,261
Time spent in forums: 2 Months 4 Weeks 1 Day 15 h 9 m 6 sec
Reputation Power: 1827
I'm confused....
Quote:
 I do not want to use any high-level APIs, not even from MS. I want to keep it to the lowest abstraction level possible at Win32 API.

IWebBrowser2 et al seem anything but the lowest level API's.

You'd be surprised how often it turns out to be true.
Kudos to you for being exceptional.

#14
January 10th, 2013, 02:44 PM
 speedbooster
Contributing User

Join Date: Jun 2005
Posts: 225
Time spent in forums: 2 Days 7 h 14 m 9 sec
Reputation Power: 0
thanks, well.... the lowest i could compromise was the IWB2 interface.... I would've gone to TCP/IP but the firewall pop-ups are unreasonable.

btw, im lazy when it comes to creating new posts. I could search for hours on google, but creating a 'New Thread' is usually a hassle for me : D

So, any idea on the problem? One guy on MSDN forum suggests pWBApp is NULL, I tried
> if (pWBApp == nullptr)
and it returns false.

and i did add breakpoints, although there's little point of it because there is nothing like 'initializing' the ExecWB()

Last edited by speedbooster : January 10th, 2013 at 02:46 PM.

#15
January 10th, 2013, 02:49 PM
 speedbooster
Contributing User

Join Date: Jun 2005
Posts: 225
Time spent in forums: 2 Days 7 h 14 m 9 sec
Reputation Power: 0
i was wondering, is there any way to evaluate a method for nullity?

> if (pWBApp->ExecWB())

won't compile, asking for arguments. If I put in the arguments, its the same story.....

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Copy files from SMB using Win32