Try to debug code without optimizations to see where the real problem is.
And is filename valid ?
EDIT:
There is no difference in parameters:
Have to execute as admin.
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#pragma comment(lib, "user32.lib")
//WINBASEAPI HANDLE WINAPI CreateFileA(LPCSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE);
void __cdecl WinMainCRTStartup(void)
{
char *szDev = "\\\\.\\PhysicalDrive0";
char *pMsg;
HANDLE hFile = CreateFileA(szDev, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if (hFile != (HANDLE)-1) pMsg = "OK";
else pMsg = "FAIL";
CloseHandle(hFile);
char szTmp[100];
wsprintf(szTmp, "%s: %s %Xh, %Xh, %Xh", pMsg, szDev, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, OPEN_EXISTING);
MessageBox(0,szTmp,"Result",0);
ExitProcess(0);
}