1

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;

}
talonmies
  • 70,661
  • 34
  • 192
  • 269
  • 4
    ***I don't receive any errors or warnings. printf or std::cout just do nothing*** Is your application a console or windows application? if you are using a windows GUI application and don't have a console printf and couts will not be seen. – drescherjm Jun 02 '20 at 18:37
  • 1
    Hi, it would help enormously if you could show the code you expect to respond and the code that calls it. – adrianmcmenamin Jun 02 '20 at 18:39
  • 1
    I wrote this answer years ago about creating a console in a GUI application: [https://stackoverflow.com/questions/13840942/visual-studio-2012-c-standard-output/13841522#13841522](https://stackoverflow.com/questions/13840942/visual-studio-2012-c-standard-output/13841522#13841522) – drescherjm Jun 02 '20 at 18:41
  • 1
    It's CUDA 10.2 Runtime that builds Dynamic-link library(DLL) – Andriy Buchynskyy Jun 02 '20 at 18:41
  • I expect your application has a GUI and not a console – drescherjm Jun 02 '20 at 18:41
  • This library functionality called from application that uses GUI and already open console – Andriy Buchynskyy Jun 02 '20 at 18:43
  • For me this feature has always worked on native c++ regardless of the version of Visual Studio I have used from the 1990s to today using VS2019. I don't know any steps to tell you to use to debug the situation other than using breakpoints and verify that the code in your DLL is running as you expect. – drescherjm Jun 02 '20 at 18:53
  • 2
    @AndriyBuchynskyy Does `printf` work if called from the main app code, and is the main app using the CRT at all? – dxiv Jun 02 '20 at 19:52
  • @dxiv Yes, main app code uses CRT and printf works fine there – Andriy Buchynskyy Jun 03 '20 at 11:41
  • @AndriyBuchynskyy That's odd. I'd check that the file descriptor returned by `fileno(stdout)` is the same when called from the main app vs. the DLL, and I'd also check the return value of the `printf` call in the DLL. Other than that, it sounds like a candidate for step by step debugging down to the metal. – dxiv Jun 03 '20 at 16:44

1 Answers1

0

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: enter image description here

Mou
  • 145
  • 1
  • 6