Yep, you want to use either xclip, as mentioned above, or xsel, which does pretty much the same thing. I prefer xsel myself because it seems to do a more reliable job in some cases.
But in this case, with either one you'll simply want to output the "primary" selection (which is the default value) to the script. You don't even need to use a variable; you can output it straight to the command itself.
gvim "$(xsel -o)"
gvim "$(xclip -o)"
Indeed, in most cases you don't even need a script. You can create a simple menu shortcut and put this line directly in the shortcut command line. Do note that if you don't have a proper filename in the selection buffer, gvim will still open up anyway.