int i ;
DWORD dw ;
String^ Source = "c:\\Program\\test.exe" ;
String^ Destination = "c:\\Program Files" ; // move to program Files Folder
//pin_ptr<const wchar_t> WSource = PtrToStringChars(Source);
// pin_ptr<const wchar_t> WDestination = PtrToStringChars(Destination);
i = MoveFileEx(L"c:\\Program Files\\Program\\Test.exe",L"c:\\Program Files",MOVEFILE_REPLACE_EXISTING) ;
dw = GetLastError() ;
return 0;
The status dw is valued as 5 , when i run the program.
Whats the error
Type in command prompt net helpmsg 5. This will show you the meaning of the error.
In my system it is: "Access is denied.".
Just a hint: why second parameter is not a file path?
Error code 5 is Access Denied. Please check if you have enough permissions for destination directory.
BOOL WINAPI MoveFileEx(
__in LPCTSTR lpExistingFileName,
__in_opt LPCTSTR lpNewFileName,
__in DWORD dwFlags
);
MOVEFILE_REPLACE_EXISTING -- This value cannot be used if lpNewFileName or lpExistingFileName names a directory.
In your case the destination is "C:\Program files" a directory. So it fails.
Error 5 is Access Denied. This error may occur if
you do not have the right to write in the destination directory
you do not have the right to overwrite an existing file with the same name in the destination directory.
I think you are in the second case: the file you want to overwrite is locked. This it is an executable, it may be running.
Related
FILE * file;
file = fopen(argv[2] , "r");
float val;
if (file) {
while (fscanf(file, "%s", str)!=EOF){
val = atof(str);
root = insert(root, val);
}
fclose(file);
}else{
exit(1);
}
That is a section of the code I have right now. Im trying to change it so that it will read from stdin instead of from the command line. For example running the program would be "./a.out x < file.txt" instead of "./a.out x file.txt".
Instead of using fopen() to open a file, use the fdopen() call to obtain a FILE * that sits on top of the file descriptor for standard input. That's file descriptor 0, or you can use the literal STDIN_FILENO from the unistd.h header if you want to make your program easier for someone to read. It will look like this:
file = fdopen(STDIN_FILENO, "r");
The rest of your program stays the same.
I am making a program that uses winhttp library. To handle various exceptions, I have created a header file. The error is thrown by using GetLastError() function which is passed to the exception class as DWORD variable. But I want to print the description of error and not just the error number. I tried using FormatMessage function, its working for error 6 but not for others viz error 12002. I am using it like:
WinHttpException(DWORD error)
{
LPTSTR lpszFunction = "Function";
LPVOID lpMsgBuf;
LPVOID lpDisplayBuf;
DWORD dw = error;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );
// Display the error message and exit the process
lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,
(lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)lpszFunction) + 40) * sizeof(TCHAR));
StringCchPrintf((LPTSTR)lpDisplayBuf,
LocalSize(lpDisplayBuf) / sizeof(TCHAR),
TEXT("%s failed with error %d: %s"),
lpszFunction, dw, lpMsgBuf);
MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK);
m_message = boost::lexical_cast<std::string>(lpDisplayBuf);
}
I got this code from this Microsoft link.. Is there any other way to do that? Or what arguments should i use in FormatMessage function to make this work?
Thanks in advance.
WinHTTP error messages are contained in the winhttp.dll module and FormatMessage() function allows you to retrieve them using FORMAT_MESSAGE_FROM_HMODULE flag (as per FormatMessage() documentation):
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_HMODULE |
FORMAT_MESSAGE_IGNORE_INSERTS,
GetModuleHandle(TEXT("winhttp.dll")),
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPTSTR>(&lpMsgBuf),
0, NULL);
I had read this page , http://llvm.org/docs/WritingAnLLVMPass.html
And i can do the example of the Hello.so completely.
Now i just want to make a .so file that can be called by opt and read my IR file name as input argument. And after i commit it , it will output the name of the file.
I had tried several methods before , but i still don't know how to do it....
I hope i can do it like this.
opt -load ../Debug+Asserts/lib/xxxx.so -flag < llvm.ll > /dev/null
when i press ENTER , it will output the name of the file -> "llvm.ll"
Can anyone help me write this simple program , i am going to optimize the llvm IR as my semester project , and now i stuck here ... help me , thanks ~
Can you tell me the code in detail , this doesn't work for me
using namespace llvm;
namespace {
struct Hello : public ModulePass {
static char ID;
Hello() : ModulePass(ID) {}
virtual bool runOnModule(Module &M) {
dbgs() << M.getModuleIdentifier() << "\n";
return false;
}
};
}
char Hello::ID = 0;
static RegisterPass<Hello> X("hello", "Hello World Pass", false, false);
~
Your question could really be simplified to "how can I access the name of the current .ll file from within an LLVM pass". You don't need to "parse LLVM IR" or anything like that - when an LLVM pass is being ran it is already way past the parsing phase.
In any case, I'm not aware of any surefire way to get the filename from an LLVM module, but you can encode that information when you prepare the .ll file. For example, set the module id to be the filename via ; ModuleID = 'llvm.ll', then retrieve it by writing a module pass and invoking getModuleIdentifier to get the string. Then you could just print it out, e.g.
bool runOnModule(Module& M) {
dbgs() << M.getModuleIdentifier() << "\n";
return false;
}
Alternatively, use metadata.
I'm trying to run Bash commands from my Cocoa APP. And receive the output. I'm executing all that commands, with Admin Privilege.
How to get output from Admin Priveleges bash script, called from Cocoa?
I guess I need FILE * type to store output, but I don't know how to use it.
What is FILE * type? And how should I use it?
FILE * is a C type and it hasn't got anything to do with Cocoa. It is a handle for an opened file. Here is an example:
#include <stdio.h>
int main () {
FILE *file;
file = fopen("myfile.txt", "w"); // open file
if (!file) { // file couldn't be opened
return 1;
}
fputs("fopen example", file); // write to file
fclose(file);
return 0;
}
In Cocoa, you should normally use NSString's and NSData's writeToURL:atomically:encoding:error: and writeToURL:atomically: methods, respectively.
FILE is an ANSI C structure is used for file handling. fopen function return a file pointer. This pointer, points to a structure that contains information about the file, such as the location of a buffer, the current character position in the buffer, whether the file is being read or written, and whether errors or end of file have occurred. Users don't need to know the details, because the definitions obtained from stdio.h include a structure declaration called FILE. The only declaration needed for a file pointer is exemplified by
FILE *fp;
FILE *fopen(char *name, char *mode);
This says that fp is a pointer to a FILE, and fopen returns a pointer to a FILE. Notice that
FILE is a type name, like int, not a structure tag; it is defined with a typedef.
#include <stdio.h>
int main()
{
FILE * pFile;
char buffer [100];
pFile = fopen ("myfile.txt" , "r");
if (pFile == NULL) perror ("Error opening file");
else
{
while ( ! feof (pFile) )
{
if ( fgets (buffer , 100 , pFile) != NULL )
fputs (buffer , stdout);
}
fclose (pFile);
}
return 0;
}
This example reads the content of a text file called myfile.txt and sends it to the standard output stream.
CoInitialize(NULL);
GCalender::IGCalenderSync* pGCalender;
HRESULT hr = CoCreateInstance(__uuidof(GCalender::GCalenderSyncHelper),NULL,
CLSCTX_INPROC_SERVER,__uuidof(GCalender::IGCalenderSync),(void**)&pGCalender);
GCalender::GenericEvent HUGEP *pDeletedEvents;
GCalender::GenericEvent HUGEP *pUpdatedEvents;
GCalender::GenericEvent HUGEP *pNewEvents;
SAFEARRAY* deletedEvents, *updatedEvents, *newEvents;
pGCalender->GetAllEvents(&deletedEvents, &updatedEvents, &newEvents);
hr = SafeArrayAccessData(newEvents, (void HUGEP* FAR*)&pNewEvents);
SafeArrayUnaccessData(newEvents);
hr = SafeArrayAccessData(deletedEvents, (void HUGEP* FAR*)&pDeletedEvents);
SafeArrayUnaccessData(deletedEvents);
hr = SafeArrayAccessData(updatedEvents, (void HUGEP* FAR*)&pUpdatedEvents);
SafeArrayUnaccessData(updatedEvents);
CoUninitialize();
in the above code the HR value is 0X8007002 ( system cannot find the file specified)
How to resolve this.
That happens if the COM server for the class id you passed into CoCreateInstance() is registered, but for whatever reason the .dll file or one of its dependencies can't be found. Your best bet is Process Monitor utility - it will let you see what file exactly is missing.