Outputdebugstring, printf not work(Visual studio 2012, Windows 8) - c++

I'm using Visual studio 2012 on Windows 8.
I usually use OutputDebugString for logging, but recently it doesn't work.
I reinstall visual studio too, but it was same.
Now I can do logging with only fprintf!! It's really painful....
Anyone has solution about this problem?
-- my code --
#include <stdio.h>
#include <Windows.h>
int main()
{
OutputDebugString( L"hello world" );
printf("hello world\n");
return 0;
}
I made new project right now,
This project's printf is work well. But OutputDebugString still doesn't work.
And my cocos2dx project( yeah, i'm working on cocos2dx ), it's both printf and OutputDebugString doesn't work!!

Make sure your system debug print filter is set to allow all messages, typically done by setting the registry value HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Debug Print Filter to DWORD 0xFFFFFFFF.
See http://msdn.microsoft.com/en-us/library/windows/hardware/ff551519(v=vs.85).aspx for more.

Related

printf doesn't print any message from dll library

I have problem in printing messages from ".dll" library created in visual studio 2019.
I don't receive any errors or warnings. printf or std::cout just do nothing. Everything worked fine in visual studio 2010. I tried to compare project properties between vs2019 and vs2010 versions. But I didn't notice anything that may effect output.
Here is simple example that shows how I expect to receive messages from this library:
#define DLLReturnType __declspec(dllexport)
DLLReturnType int add3DArraysLib(int value)
{
printf("Received value - %d", value);
return value + 1;
}
My suggestion is to change your "SubSystem" to be Console (/SUBSYSTEM:CONSOLE) then to see the printf messages on Visual Studio Output window.
One more thing, #include <iostream> is necessary !
Property setting is here:

Visual Studio 2015 + libtcod - Unexpected exit

I am having an odd issue getting libtcod to work with Visual Studio 2015.
I have followed all the steps found on this blog post to get everything linked.
The problem is that during debugging or running it inside Visual Studio the application will always close at initRoot with exit code 1, no other information or errors.
Running the produced EXE outside of Visual Studio has no issues whatsoever - starts up and works as expected!
The only information I could find related to this was a forum post that turned ugly in 2012
I did make a modification to the blog post's code to include a setCustomFont as well, which did not change anything.
Does anyone have any ideas on what might be going on?
Code:
#include <cstdio>
#include "libtcod.hpp"
// Hide the console window
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
int main()
{
TCODConsole::setCustomFont("terminal12x12_gs_ro.png", TCOD_FONT_LAYOUT_ASCII_INROW | TCOD_FONT_TYPE_GRAYSCALE);
TCODConsole::initRoot(80, 50, "C++ libtcod tutorial");
TCODConsole::root->printEx(40, 25, TCOD_BKGND_NONE, TCOD_CENTER, "Hello world");
TCODConsole::flush();
TCODConsole::waitForKeypress(true);
return 0;
}
For anyone that stumbles upon this later, the above blog post is correct for setting up the vast majority of the application - if you run into the same issue I did (crashing / exiting in initRoot) make sure you have the terminal png in the source directory, this is what fixed it for me.

wchar and stdout in VC11

I've found a weird issue with outputting wide chars in Visual Studio 2012 which I've narrowed down to the following code.
#include <cstdio>
int main()
{
fputws(L"Hello World\n", stdout); // Throws Access Violation exception
}
When compiling this with Visual C++ 2012 it throws an "Unhandled exception", "Access violation reading location 0x00000064", somewhere inside fputws.
What I'm using to compile is with is the CLI version, just to rule out any settings in the IDE. I am opening the Visual Studio Command Prompt and using the following:
cl test.cpp
When using Visual Studio 2008 or Visual Studio 2010 it works well, writing out "Hello World".
But when using Visual Studio 2012, it crashes with the above mentioned error.
I have a hard time believing it's a compiler issue but rather something that's changed between the different versions of C++.
Another (funny) thing is that if I output a normal char first, like the code snippet below, it works just fine. So what I think is that it is an issue with uninitialized streams?
#include <cstdio>
int main()
{
fputs("", stdout);
fputws(L"Hello World\n", stdout); // Now this works.
}
Anyone got any ideas?
Edit:
The following, similar, functions works fine in VS2012:
std::wcout << L"Hello world" << std::endl;
wprintf(L"Hello world\n");
_putws(L"Hello\n", stdout);
putwchar(L'H');
Edit 2:
Just filed a bug report to microsoft.
I had this problem on a RTM VS2012 but didn't on VS2012 Update 1. After installing Update 1 on the problem system the error disappeared. Thanks to Mats for reporting this.

visual studio 2012 c++ hello world - iostream not working

I have an issue with Visual Studio's 2012. I am also using "Sams Teach Yourself C++ in One Hour a day, 7th edition".
After using google to find the "best" compilers for C++, Visual Studios seemed to be the tool of choice.
So I downloaded and installed Visual Studios 2012. The very first lesson in the book is (and tells me to run it as a console app by going to File > New > Project >Visual C++ > Win32 > Console Application )
#include <iostream>
int main()
{
std::cout << “Hello World!” << std::endl;
return 0;
}
which doesnt work, at all. it outputs an error message similiar to the following:
1>c:\users\nik\documents\visual studio
2012\projects\consoleapplication4\consoleapplication4\consoleapplication4.cpp(8):
error C2065: '“Hello' : undeclared identifier
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped =========="
(there is more lines similiar to the first, but its rather long)
However, after googling and watching a video on youtube the following code works (using File > New > Project >Visual C++ > General > Empty Project )
#include <iostream>
#include "conio.h"
using namespace std;
int main() {
cout << "Hello Nik" << endl;
_getch();
return 0;
}
Does Visual Studio's 2012 have a C++ compiler? or does it just have a visual c++ compiler (if thats even the issue, only reason I think it could be is I can see templates for Visual C++ but none for c++ by itself...) or do I need to download Visual Studio Express to download native c++ ??
Any help would be greatly appreciated as I am feeling some-what out of my depth here...
Thanks.
Besides aphostrophes you may need to disable precompiler headers in project properties.
They are turned on by default in VS2012. If you are not familiar with precompiled headers turn them off.
Right click on project (not solution)
Click properties.
Expand "Configuration properties"
Expand "C/C++"
Choose "Precompiled headers"
Set "Precompiled header" to "Not Using Precompiled Headers"
More information about precompiled headers and stdafx.h file at Wikipedia
The apostrophes you used are wrong:
“Hello World!”
should be
"Hello World!"
Notice even how SO recognizes the difference. You should at least type the code you see in the book instead of copying and pasting it. ;-)
The Win32 console application is actually quite different from the empty project. Win32 utilize a message (input) queue which you poll in a loop and your program respectively utilizes the Win32 API and performs certain operations.
The empty project is a bit less dependent on Win32 or anything that Windows provides in terms of API unless you make it dependent on it. This would be the simples hello world app in you empty project:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World" << endl;
return 0;
}
Just try this::
"Hello World!" instead of “Hello World!”.
The difference between
“Hello World!” and
"Hello Nik" is the apostrophe.
Aslo is the error persists than just check visual c++ library linker.
There is aslo definitely no need for conio.h
If your going to copy from a book at least copy it correctly.
Using namespace std;
would be pretty smart in this case.
In order to fix your error you have to delete std:: of std::cout and std::endl, and write using namespace std; underneath #include iostream and and change “ ” with " ".
#include <iostream>
using namespace std;
int main()
{
cout <<"Hello World" << endl;
return 0;
}
In Visual studio 2012
file>new projet>visual c++ (Project win32)>application settings(application console+Not Using Precompiled)>in right box in you Project (right click, add>new element>file c++).

Visual C++ err: RegGetValueA could not be located

Attempting to write a simple registry-check script in Visual Studio 2010, running on XP SP3 x86.
No errs are thrown on build, but on debug the program exits with the following error:
The procedure entry point RegGetValueA
could not be located in the dynamic
link library ADVAPI32.dll
Here is the entire code of the program.
// #define _WIN32_WINNT 0x0501
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
int main(int argc, char *argv[])
{
long reg = RegQueryValueEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", NULL,NULL,NULL,NULL);
// if (reg!=ERROR_SUCCESS) MessageBox(0, "Error Opening Registry Key", "Error", 0);
return 0;
}
The comments in the code above where added based on an answer by wmeyer.
When uncommented, the code does not exit with that error, but throws a different error:
Debugging information for Test5.exe
cannot be found or does not match.
Binary was not built with debug
information. Do you want to continue
debugging?
If I continue, the MessageBox pops up with "Error Opening Registry Key".
I have tried replacing the RegQueryValueEx function with the following three other methods, one at a time.
I KNOW THAT TWO OF THEM ARE VISTA ONLY, but I wanted to see if the error would be different.
It wasn't.
long reg = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_ALL_ACCESS, hKey);
// Vista+ PHKEY hKey;
long reg = RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", hKey);
long reg = RegGetValue(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", "", RRF_RT_ANY, NULL, NULL,NULL);
I've already lost hours trying to work out several other errors, such as "cannot convert parameter 1 from 'char' to 'LPCWSTR'" - which was solved by changing the configuration
and "Cannot find or open the PDB file", solved by changing the configuration.
So again, the question to be clear:
How do I deal with the error?
How did wmeyer's suggestion of adding a header to filter out Vista-only methods help, when the prog has no Vista methods to begin with? And why does the program still not work?
My computer definitely does have a advapi.dll file in Windows/syatem32.
EDIT:
Completely rewrote the question when the answers pointed out how unclear it was.
Originally I had assumed that Visual Studio 2010 is not backwards compatible with XP.
I've been forcefully told that is incorrect, but still can't get VS to work.
If you want your code to run in XP or an earlier system use RegQueryValueEx.
In any case, you should check the documentation first and then search Google. The Win32 API is very well documented, with details on retrieving data from the registry and supported OS information in every function's page, e.g. RegGetValue is supported in XP 64bit and later.
You should set _WIN32_WINNT to the Windows version you are targeting.
See here: http://msdn.microsoft.com/en-us/library/aa383745(v=vs.85).aspx#setting_winver_or__win32_winnt