scanf_s doesn't work visual studio - scanf

#include <windows.h>
#include <stdio.h>
#define WIN32_LEAN_AND_MEAN
vis studio 2017,
doesn't matter what i do,
int main(){
char c = 's';
scanf_s(" %c", &c, 1);
}
simple program, changing scanf_s line to
scanf_s("%c", &c, 1);
again to,
scanf_s("%1c", &c, 1);
etc nothing works I get a debug error
scanf_s(" %1c", &c, sizeof(c));
again, error, I don't know what the problem is
scanf_s("%c",&c);
it brings me to this line in debugger:
{
return __stdio_common_vfscanf(
_CRT_INTERNAL_LOCAL_SCANF_OPTIONS | _CRT_INTERNAL_SCANF_SECURECRT,
_Stream, _Format, _Locale, _ArgList);
}
#endif

I created a new project and it fixed the problem

Related

Is there any way to disable Screen Capture/Screen Recording Flutter win32 app

I am trying to secure my application, Is there any way of disabling screen capture in win32 application.
Flutter for windows
Thanks in advance
Output I desire
I figured out how to disable screen capture in Flutter Windows Application
API Reference: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowdisplayaffinity
Navigate to Project/windows/runner/main.cpp
Add the below code in wWinMain method:
//DISABLE SCREEN
HWND code =window.GetHandle();
SetWindowDisplayAffinity(code, 0x00000011);
main.cpp:
#include <flutter/dart_project.h>
#include <flutter/flutter_view_controller.h>
#include <windows.h>
#include "flutter_window.h"
#include "utils.h"
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
_In_ wchar_t *command_line, _In_ int show_command) {
// Attach to console when present (e.g., 'flutter run') or create a
// new console when running with a debugger.
if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
CreateAndAttachConsole();
}
// Initialize COM, so that it is available for use in the library and/or
// plugins.
::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
flutter::DartProject project(L"data");
std::vector<std::string> command_line_arguments =
GetCommandLineArguments();
project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
FlutterWindow window(project);
Win32Window::Point origin(10, 10);
Win32Window::Size size(1280, 720);
if (!window.CreateAndShow(L"windows_app", origin, size)) {
return EXIT_FAILURE;
}
//DISABLE SCREEN
HWND code =window.GetHandle();
SetWindowDisplayAffinity(code, 0x00000011);
window.SetQuitOnClose(true);
::MSG msg;
while (::GetMessage(&msg, nullptr, 0, 0)) {
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
::CoUninitialize();
return EXIT_SUCCESS;
}

Why can I not print non-ASCII characters to the console in curses mode?

Please consider this simple snippet:
#include <stdio.h>
#include <curses.h>
#include <stdlib.h>
#include <stdbool.h>
#include <signal.h>
void cleanup(int signal)
{
endwin();
exit(0);
}
int main()
{
initscr();
struct sigaction cleanup_action = { .sa_handler = cleanup, .sa_flags = 0 };
sigfillset(&cleanup_action.sa_mask);
sigaction(SIGINT, &cleanup_action, NULL);
cbreak();
keypad(stdscr, TRUE);
noecho();
mvaddstr(2, 2, "🧱");
mvaddstr(2, 3, "🧱");
mvaddstr(2, 4, "🧱");
mvaddstr(3, 2, "⬜");
mvaddstr(3, 2, "⚾");
mvaddstr(3, 4, "⬜");
refresh();
while(true) getch();
return 0;
}
(No, I'm not certain that my clean-up on exit is correct, but that's not the point.)
Why are the emojis not being printed out?
When I run this program this is what I see:
���~_��
�~��~\
I don't understand this because according to POSIX specification:
addnstr, addstr, mvaddnstr, mvaddstr, mvwaddnstr, mvwaddstr waddnstr, waddstr - add a string of multi-byte characters without rendition to a window and advance cursor
"MULTI-BYTE" they say! So I guess this should print out correctly! I'm not limited to ASCII!
Also, I guess my terminal can handle these characters. This is because as opposed to curses.h, stdio.h is able to print them correctly:
#include <stdio.h>
int main()
{
printf("🧱⬜⚾\n");
return 0;
}
This prints out:
🧱⬜⚾
How can I print emojis with curses.h?

Learning GUI programming with GTK+3

I am new to GUI programming. I recently installed Gtk+3 version on Linux. But, when I typed following code:
#include <gtk/gtk.h>
#include <stdio.h>
static int count = 0;
void button_clicked(GtkWidget *button, gpointer data)
{
printf(“%s pressed %d time(s) \n”, (char *) data, ++count);
}
int main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *button;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
button = gtk_button_new_with_label(“Hello World!”);
gtk_container_add(GTK_CONTAINER(window), button);
g_signal_connect(GTK_OBJECT (button), “clicked”,
GTK_SIGNAL_FUNC (button_clicked),
“Button 1”);
gtk_widget_show(button);
gtk_widget_show(window);
gtk_main ();
return 0;
}
To run this code I used this command: $ gcc gtk1.c –o gtk1 pkg-config --cflags --libs gtk+-3.0
but I had error like this
undefined reference to GTK_OBJECT;
undefined reference to GTK_SIGNAL_FUNC;
This is because your code sample is for an old version of GTK+ 2. GTK_OBJECT was deprecated in the late GTK+ 2.x versions, and finally removed in GTK+ 3. Same for GTK_SIGNAL_FUNC. Both have been moved to the GObject library, where they now stand as G_OBJECT and G_CALLBACK.
To avoid using outdated code, just get started with the code samples from the GTK+ 3 documentation.

Is there a way to catch a STATUS_STACK_BUFFER_OVERRUN error programmatically?

We have some C code that is throwing a STATUS_STACK_BUFFER_OVERRUN error (0xC0000409) once in a while. I can reproduce that error using the C code below. I'm using Visual Studio 2013 Update 4 on Windows 7, and I'm compiling with the /EHa and /GS flags. However, I have been unable to catch the error programmatically. The code never enters my __except block; instead, Visual Studio pops up a few dialog boxes informing me of the stack corruption. I realize that once this error occurs, the state of the program is in doubt; I'm merely trying to capture the error in hopes of locating where it is occurring in our production code. Is there a way to handle this error programmatically?
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#pragma warning(disable: 4996) // strcpy
void vulnerable(const char* str)
{
char buffer[10];
strcpy(buffer, str); // overrun the buffer
}
int main()
{
__try
{
char large_buffer[] = "This string is longer than 10 characters.";
vulnerable(large_buffer);
}
__except (GetExceptionCode() == STATUS_STACK_BUFFER_OVERRUN)
{
printf("error"); // never getting here
}
}

The moment I add glew.h in my code glut related errors start appearing

I am new to C/C++ environment setup. Right now I am using Eclipse IDE. Below are the steps I have followed
After installing MinGW and running basic HelloWorld, C program
1) Copied glew32.dll and glut32.dll to "C:\MinGW\bin"
2) Copied gl.h, glew.h, glu.h and glut.h to "C:\MinGW\include\GL"
3) Copied glew32.lib, glut32.lib and OPENGL32.LIB to "C:\MinGW\lib"
4) In Project->properties->C/C++ Build->Settings->Tool Settings->MinGW C Linker->Libraries(-l) added "glew32", "glut32","glu32" and "opengl32"
5) Copied below code
Compiles properly.
The moment I uncomment the first line, ie glew.h, glut related compile errors (added below) appear, Can any one tell me where I am going wrong during setup?
//#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glut.h>
void changeViewport(int w, int h)
{
glViewport(0, 0, w, h);
}
void render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(800, 600);
glutCreateWindow("Pinnen is the best");
glutReshapeFunc(changeViewport);
glutDisplayFunc(render);
glutMainLoop();
return 0;
}
Description Resource Path Location Type
undefined reference to `__glutCreateMenuWithExit' OpenGL line 549, external location: c:\mingw\include\GL\glut.h C/C++ Problem
undefined reference to `__glutCreateWindowWithExit' OpenGL line 503, external location: c:\mingw\include\GL\glut.h C/C++ Problem
undefined reference to `__glutInitWithExit' OpenGL line 486, external location: c:\mingw\include\GL\glut.h C/C++ Problem
undefined reference to `glutDisplayFunc' OpenGL.c /OpenGL/src line 25 C/C++ Problem
undefined reference to `glutInitDisplayMode' OpenGL.c /OpenGL/src line 21 C/C++ Problem
//ignore
From glew webpage [delete gl include] :
Using GLEW as a shared library
in your program:
#include <GL/glew.h>
#include <GL/glut.h>
<gl, glu, and glut functionality is available here>
or:
#include <GL/glew.h>
<gl and glu functionality is available here>
Remember to link your project with glew32.lib, glu32.lib, and opengl32.lib on Windows and libGLEW.so, libGLU.so, and libGL.so on Unix (-lGLEW -lGLU -lGL).
It is important to keep in mind that glew.h includes neither windows.h nor gl.h. Also, GLEW will warn you by issuing a preprocessor error in case you have included gl.h, glext.h, or glATI.h before glew.h.