Pelles C forum

C language => Beginner questions => Topic started by: hotdone on August 25, 2010, 05:40:05 PM

Title: POLINK: fatal error: Access is denied.
Post by: hotdone on August 25, 2010, 05:40:05 PM
I compiled below codes then i got error called
Building for.exe.
POLINK: fatal error: Access is denied.
*** Error code: 1 ***
Done.

code i compiled is
#include<stdio.h>
int main()
{
FILE *fp;
char c;
fp=fopen("myfile.txt","r+");
if(fp!=NULL)
c=getc(fp);
while(c!=EOF)
{
printf("%c",c);
c=getc(fp);
}
fclose(fp);
return 0;
} ::)
Title: Re: POLINK: fatal error: Access is denied.
Post by: Stefan Pendl on August 25, 2010, 06:06:19 PM
Which Windows version are you running on?

Where did you save your project to?
Title: Re: POLINK: fatal error: Access is denied.
Post by: DMac on August 25, 2010, 06:12:13 PM
I sometimes get an error like this if I run code from the IDE and then edit the source and try to execute the code again.

Make sure that an instance of the console application is not already running before recompiling and testing it.
Title: Re: POLINK: fatal error: Access is denied.
Post by: CommonTater on August 26, 2010, 07:39:26 PM
I get that message a lot...
It's almost always because the program I'm working on is running.
Title: Re: POLINK: fatal error: Access is denied.
Post by: TimoVJL on August 27, 2010, 11:03:26 PM
Cruel way to stop process.
Add this program to Tools menu with Arguments: $(TargetPath)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tlhelp32.h> // CreateToolhelp32Snapshot()

TCHAR szAppName[] = "ProcKill";

#pragma lib "psapi.lib"

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
HANDLE hSnapShot;
HANDLE hProcess;
PROCESSENTRY32 pEntry;
TCHAR szTmp[260];

if (!*lpszCmdLine) {
MessageBox(0, "Usage: ProcKill.exe <file>", szAppName, MB_OK);
return 1;
}

hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapShot) {
pEntry.dwSize = sizeof(pEntry);
if (Process32First(hSnapShot, &pEntry)) {
do {
wsprintf(szTmp, "%d %s", pEntry.th32ProcessID, pEntry.szExeFile);
if (!lstrcmpi(pEntry.szExeFile, lpszCmdLine)) {
// found it
if (MessageBox(0, pEntry.szExeFile, szAppName, MB_OKCANCEL) == IDOK) {
hProcess = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, pEntry.th32ProcessID);
if (hProcess) {
TerminateProcess(hProcess, 0);
CloseHandle(hProcess);
}
}
}
} while (Process32Next(hSnapShot, &pEntry));
}
CloseHandle(hSnapShot);
}
return 0;
}

This code try to close it first normally with WM_CLOSE
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tlhelp32.h> // CreateToolhelp32Snapshot()

TCHAR szAppName[] = "ProcKill";

#pragma lib "psapi.lib"

BOOL CALLBACK TerminateAppEnum(HWND hwnd, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
HANDLE hSnapShot;
HANDLE hProcess;
PROCESSENTRY32 pEntry;
TCHAR szTmp[260];

if (!*lpszCmdLine) {
MessageBox(0, "Usage: ProcKill.exe <file>", szAppName, MB_OK);
return 1;
}

hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapShot) {
pEntry.dwSize = sizeof(pEntry);
if (Process32First(hSnapShot, &pEntry)) {
do {
wsprintf(szTmp, "%d %s", pEntry.th32ProcessID, pEntry.szExeFile);
if (!lstrcmpi(pEntry.szExeFile, lpszCmdLine)) {
// found it
if (MessageBox(0, pEntry.szExeFile, szAppName, MB_OKCANCEL) == IDOK) {
EnumWindows((WNDENUMPROC)TerminateAppEnum, (LPARAM) pEntry.th32ProcessID) ;
hProcess = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, pEntry.th32ProcessID);
if (hProcess) {
if(WaitForSingleObject(hProcess, 1000)!=WAIT_OBJECT_0)
TerminateProcess(hProcess, 0);
CloseHandle(hProcess);
}
}
}
} while (Process32Next(hSnapShot, &pEntry));
}
CloseHandle(hSnapShot);
}
return 0;
}

BOOL CALLBACK TerminateAppEnum(HWND hwnd, LPARAM lParam)
{
DWORD dwID;

GetWindowThreadProcessId(hwnd, &dwID);
if (dwID == (DWORD)lParam) {
PostMessage(hwnd, WM_CLOSE, 0, 0);
}
return TRUE;
}
Title: Re: POLINK: fatal error: Access is denied.
Post by: CommonTater on August 28, 2010, 01:35:36 AM
Or you could use FindWindow using the window title and sent it WM_Close

Title: Re: POLINK: fatal error: Access is denied.
Post by: hotdone on August 28, 2010, 03:08:15 PM
Quote from: Stefan Pendl on August 25, 2010, 06:06:19 PM
Which Windows version are you running on?

Where did you save your project to?

i am using windows seven.. i saved it on desktop ...
Title: Re: POLINK: fatal error: Access is denied.
Post by: TimoVJL on August 28, 2010, 03:41:41 PM
What is actually in this line:

QuoteBuilding for.exe

You can tick Verbose build from Project options... to see that polink.exe commandline.