### Thread: Copy files from SMB using Win32

1. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2005
Posts
227
Rep 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. 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.
3. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2005
Posts
227
Rep 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. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2005
Posts
227
Rep 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. Right, so you should realize that he is commenting on Nancy's useless post.
6. Originally Posted by speedbooster

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.
7. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2005
Posts
227
Rep Power
0
Oh, thanks mitakeet.
@scorpion4ever, yeah i m doing that now. thanks a lot : )
8. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2005
Posts
227
Rep 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. If you look at the docs, it says that CopyFile() can also accept "\\ip\path\to\directory\whatever\" type strings.
10. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2005
Posts
227
Rep 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/libr...=vs.85%29.aspx
11. > 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".
12. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2005
Posts
227
Rep 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/libr...=vs.85%29.aspx
13. I'm confused....
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. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2005
Posts
227
Rep 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 01:46 PM.
15. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2005
Posts
227
Rep 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.....