The error message says it all - you're trying to execute a privileged instruction. In this case it's the instructions to read or write I/O ports. These are things that only kernel mode code can do to protect the system.
Some nice people on the interwebs have written device drivers which handle the processor exceptions caused by user mode programs and then actually do the reads and writes for you. These drivers are generally packaged as DLLs with the driver embedded as a resource. When the DLL loads it extracts the driver and installs it. So all you have to do is link your code with the packaging DLL, run your code as administrator and then there's a chance it might start working.
Here's[
^] one driver/DLL package that might do what you want with some decent docs. I've never tested this one so I can't warrant it's use - the one I used several years ago has annoyingly disapeared from the interwebs.
Good luck!
PS: For anyone having trouble with the above link have a look
here[
^] instead.