CreateFile in unmanaged code fails
Hi. I'm calling some legacy unmanaged code from a web service (but I can
duplicate the same problem from an IHttpModule). The unmanaged code calls
CreateFile to open an existing file. CreateFile always fails with LastError
== 5 (ERROR_ACCESS_DENIED).
If I try to call CreateFile directly from the web service, like this:
[DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr CreateFile(string lpFileName, uint
uint dwShareMode, IntPtr lpSecurityAttributes, uint
uint dwFlagsAndAttributes, IntPtr hTemplateFile);
IntPtr hFile = CreateFile( "c:\\tempdb\\file.txt",
This works fine.
Calling fopen() to open the file from the unmanaged code also works. Only
CreateFile in the unmanaged code fails.
I've tried adding the ASPNET user to the Administrators group. I've also
to the machine.config file.
Does anyone know why this particular scenario fails? I'm assuming it's a
permissions problem because of the ACCESS_DENIED error, but none of the
solutions for access problems are working, and it's strange that fopen() will
succeed when CreateFile() fails.
Anyone have any ideas?
|All times are GMT. The time now is 12:32 AM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.