c++ - Creating successfully console window but cout doesn't print anything on it ( visual studio enterprise 2015 ) -
i've created dynamic dll. interesting thing same code i'll build in visual studio 2010 works fine while building code on visual studio 2015, doesn't work.
#include <windows.h> #include <stdio.h> #include <fcntl.h> #include <io.h> #include <iostream> #include <fstream> #include <string> #include <vector> #define exp __declspec(dllexport) __stdcall using namespace std; void spgoconsole(int status); void exp ttest(int in) { spgoconsole(1); cout << "hello world!" << endl; } void spgoconsole(int status) { if (status == 0) { freeconsole(); return; } int hconhandle; long lstdhandle; console_screen_buffer_info coninfo; file *fp; allocconsole(); getconsolescreenbufferinfo(getstdhandle(std_output_handle), &coninfo); coninfo.dwsize.y = 1000; coninfo.dwsize.x = 1000; setconsolescreenbuffersize(getstdhandle(std_output_handle), coninfo.dwsize); lstdhandle = (long)getstdhandle(std_output_handle); hconhandle = _open_osfhandle(lstdhandle, _o_text); fp = _fdopen(hconhandle, "w"); *stdout = *fp; cout = fp; setvbuf(stdout, null, _ionbf, 0); lstdhandle = (long)getstdhandle(std_input_handle); hconhandle = _open_osfhandle(lstdhandle, _o_text); fp = _fdopen(hconhandle, "r"); *stdin = *fp; setvbuf(stdin, null, _ionbf, 0); lstdhandle = (long)getstdhandle(std_error_handle); hconhandle = _open_osfhandle(lstdhandle, _o_text); fp = _fdopen(hconhandle, "w"); *stde rr = *fp; setvbuf(stderr, null, _ionbf, 0); ios::sync_with_stdio(); }
i not using special settings in visual studio 2015. default.
if use:
allocconsole();
then first time program imports dll , calls ttest, doesn't print out second time calls ttest prints out hello world!.
then tried calling allocconsole 2x still didn't print until program called ttest again.
edit: appearst after second dll import while program running, starts print.
anyideas? thanks
Comments
Post a Comment