First of all, if you are a novice, I would recommend you to avoid sharing files between processes and duplication of any handles: 1) these related techniques are not very easy for understanding; 2) they are unsafe; 3) this is not a recommended practice; a recommended practices should maintain main feature of the processes — strong isolation between them, and breaking through this isolation is a questionable practice. It can be used probably in some really rare and sophisticated technology, if any.
Now, I don't see what could be the use of duplication of the handle you have obtained, because — how would you use it? The problem is the third parameter of your call to
dwShareMode == 0
. How can you use the handle's duplicate if you are not sharing the file? You need to use
FILE_SHARE_READ | FILE_SHARE_WRITE
. Read, everything is explained:
And them you can share the handler, either in this or a foreign process. You need to pass the original handle and a handle to a different process or obtain a handle of a foreign process, use it to duplicate a handle and pass a handle duplicate back to a foreign process. Everything is explained:
Now, how to communicate between processes is your problem, a separate one. This is called Inter-Process Communication
(IPC). You just need to learn about it; this is a separate big topic. You can use sockets, named pipes, shared memory and so on.
Before going into all of that, please re-read my first paragraph above and think is you really need it. Also, when asking questions, it's the best to start with explaining your purpose and your ultimate goals.