NO

Author Topic: CreateFileA Fails in Pelles 9.0  (Read 197 times)

Offline gordonk@atlantic.net

  • Member
  • *
  • Posts: 2
CreateFileA Fails in Pelles 9.0
« on: September 11, 2019, 09:55:42 pm »
I developed a project using Pelles C 7.0.
The project uses serveral windows APIs.
The project works just fine as a 32bit app on a 64 bit machne runing Windows 7.

One of these window api calls is CreateFileA.

I compled the app using Pelles 9.0 and converted when asked, to 9.0.
I made no changes to the app or options except to select 32bit or 64bit.

The app no longer works.

This function is to return a device handle which it does with no
problem in the app developed with 7.0 but will not do so in the
app developed under 9.0.  This is true whether compled as a 32bit or 64bit.

Any thoughts or suggestions?

I noticed that CreateFileA is defined in winbase.h in 7.0 and in fileapi.h in 9.0.

Offline bitcoin

  • Member
  • *
  • Posts: 70
Re: CreateFileA Fails in Pelles 9.0
« Reply #1 on: September 12, 2019, 05:19:14 am »
Can you tell , what error you got?
How it "no works"?
What thing you open (file,drive,pipe)?

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1866
Re: CreateFileA Fails in Pelles 9.0
« Reply #2 on: September 12, 2019, 08:02:10 am »
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.
Code: [Select]
#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);
}

« Last Edit: September 13, 2019, 12:04:20 pm by TimoVJL »
May the source be with you

Offline gordonk@atlantic.net

  • Member
  • *
  • Posts: 2
Re: CreateFileA Fails in Pelles 9.0
« Reply #3 on: September 12, 2019, 04:42:50 pm »
I did debug with optimization off.
I am attempting to access a physical drive.
File name supplied was \\.\PhysicalDriven where n is the number of the drive.
Tried all physical drives on the system.
The function returns INVALID_HANDLE_VALUE in all cases.

Keep in mind that this is a direct export from a app developed using PellesC 7.0  with no changes in code that works with not problem on the same system.

Offline bitcoin

  • Member
  • *
  • Posts: 70
Re: CreateFileA Fails in Pelles 9.0
« Reply #4 on: September 13, 2019, 03:34:42 am »
Can you give two binaries, from Pelles 7 and 9? Only with 1 call of api, if you don't want to show us all code.


Offline gordonk@atlantic.net

  • Member
  • *
  • Posts: 2
Re: CreateFileA Fails in Pelles 9.0
« Reply #5 on: September 16, 2019, 08:31:55 pm »
Thanks for your responses.
Don't mind at all showing the code but problem solved.
(TimoVJL did it with the comment about execute as admin)
It was the security level.