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;
} ::)
Which Windows version are you running on?
Where did you save your project to?
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.
I get that message a lot...
It's almost always because the program I'm working on is running.
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;
}
Or you could use FindWindow using the window title and sent it WM_Close
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 ...
What is actually in this line:
QuoteBuilding for.exe
You can tick Verbose build from Project options... to see that polink.exe commandline.