Why BlockInput isn't working
#include <iostream>
#include <windows.h>
#include <winable.h>
int main() {
BlockInput(true);
Sleep(10000);
return 0;
}
and it simply doesn't block anything!
I can still do everything like I haven't even done that.what I also find weird is that MSDN sais that it should be declared in winuser.h and it is in Winable.h + I thought that winable.h is in windows.h but It's not, I had to include it seperatly >_>
If it helps my IDE is:
Code::Blocks 10.05 MinGW
EDIT: Actually I did the GetLastError() and it prints error 5 ERROR_ACCESS_DENIED
How may I get the access?
Run your code as an administrator. Right-click on the executable and click 'run as Administrator'.
Related
I am using Visual Studio Community 2017 to code c++. When I run the following code everything works fine.
#include "pch.h"
#include<Windows.h>
#include<Psapi.h>
#include <iostream>
#include <conio.h>
int main()
{
std::cout << "Really!! How do you do it?";
_getch();
}
But if I change the order of #includes by including psapi.h before Windows.h, compiler goes badass and throws 198 errors at me, which surprisingly(maybe only to me) includes Identifier "BOOL" is undefined.
Why is this happening?
Since Psapi.h's include tree is trivial, I'm going to exemplify. Everything relies on VStudio 2015 (Community) (v14.0.25431.01 Update 3) and Windows Kits 8.1 (? funny, because v10 is there too) files (with default env vars and preprocessor definitions):
BOOL is defined in minwindef.h (#157: typedef int BOOL;)
Psapi.h only includes one file (#27: #include <winapifamily.h>)
winapifamily.h doesn't include any other file
So, when reaching Psapi.h (#87: BOOL WINAPI EnumProcesses (...), the compiler doesn't know anything about BOOL, so it complains.
Windows.h includes minwindef.h (indirectly, via windef.h), and that's why it works when you include it before Psapi.h.
Personally, I think it's a bug in Psapi.h, since it's not self contained, but there might be a good reason (that I'm not aware of) for that. Anyway, if this is indeed a bug, it wouldn't be MS's 1st one :)
#include <Windows.h>
#include <WinSock2.h>
// main present just for rigorosity's sake
int main() {
return 0;
}
to answer the question, I know this is DATED but the issues persist today. You need the following:
#include "stdafx.h"
#include <stdbool.h>
#include <Windows.h>
#include <stdlib.h>
#include <psapi.h>
After stdlib.h was included, the errors were gone.
I installed Codeblocks on my Windows 10 computer. To check that everything works fine, I first compiled the simple C program
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello world!\n");
return 0;
}
That works without problem but when I try the C++ equivalent:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return(0);
}
Then the "command prompt" window opens but no output is shown. I can see in taskmanager that the program is running but as said without any visible output. I also tried running the program directly from the command line but with the same effect. Anyone any ideas?
I found the issue. There was still an older version of MinGW installed in a different folder. I deleted all instances of MinGW, and codeblocks as well. Adter I reinstalled codeblocks everything worked as it should.
This Guy solved similar problem with Codeblocks.
Remove the following Global compiler setting:
-Wl,-subsystem,windows
I want to open an additional program with c++ on XCode.
It is Firefox.
But if I make
Shell Execute("file://localhost/Applications/Firefox.app");
There is an error 'ShellExecute' was not declared in this scope
In other forum there was a clue to include windows.h and shellapi.h
#include <shellapi.h>
#include <windows.h>
but that makes other errors
shellapi.h: No such file or directory
windows.h: No such file or directory
What should I do? I want to open frefox with c++ in XCode on Mac?
Try running this in Terminal to open Firefox:
open -a Firefox http://www.ibm.com
If that does what you want, you need to wrap it in system() like this:
#include <cstdlib>
#include <fstream>
#include <iostream>
int main()
{
std::system("open -a Firefox");
}
ShellExecute() is only available through the Windows API. You don't have a Windows system.
You can simply use the (more portable) system() function, or one of the exec() functions available on POSIX compliant systems.
I tried the same with chrome and I had to set it in inverted commas:
int main() {
system("open -a 'Google Chrome'");
return 0;
}
with the apostrophe it worked!
code blocks 16.01 can't find headers.
I write some c++ code:
#include <iostream>
.....
int main()
{
...
}
it can be compiled without any errors or warnings, and run perfectly. But when I right-click the iostream then choose open iostream, it says that "Not found: iostream"
why? how to solve this problem?
I finally found that it's a matter of setting.
We should set the path of compiler as "...\codeblocks\MinGW\" rather than "...\codeblocks\MinGW\bin\". At meantime we should add an environment variable which is "...\codeblocks\MinGW\bin"
You're using int main function. In other words, it is waiting for a return of an integer. You can also solve this by just using void main function.
Error: cannot open source file "GL/glew.h"
I have the following code :
//Include GLEW
#include <GL/glew.h>
//Include GLFW
#include <GLFW/glfw3.h>
//Include the standard C++ headers
#include <stdio.h>
#include <stdlib.h>
//Define an error callback
static void error_callback(int error, const char* description)
{
...
I took from there: http://www.41post.com/5178/programming/opengl-configuring-glfw-and-glew-in-visual-cplusplus-express#part4
In order to have a somewhat portable solution, before I even started Visual Studio 2013 I created two System Environment Variable in windows.
GLEW=C:\Install\Development\C++\Framework\glew-1.10.0-win32\glew-1.10.0
GLFW=C:\Install\Development\C++\Framework\glfw-3.0.4.bin.WIN32\glfw-3.0.4.bin.WIN32
So in my project I could for instance write a additional include folder as: %GLEW%\include
As I said, it builds fine and runs fine as well.
Yet, not having intellisense behave properly is really annoying.
How to fix it?
My syntax was actually wrong, you cant use global environment variable in VS using %<name>% but you have to use $(%<name>).
Wherever I wrote %GLEW%\include I should have $(GLEW)\include.
It's working fine now.
Though I'm completely clueless why it built.
This post: https://stackoverflow.com/a/11543754/910813 got me to remind that.