Skip to content

Instantly share code, notes, and snippets.

@loneicewolf
Last active July 27, 2023 16:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save loneicewolf/c588f95287c55454ef6a5c28e8babd30 to your computer and use it in GitHub Desktop.
Save loneicewolf/c588f95287c55454ef6a5c28e8babd30 to your computer and use it in GitHub Desktop.
A simple message box in Windows using C
// i686-w64-mingw32-gcc -o M msgbox.c
#include <stdio.h>
#include <windows.h>
int main(int argc, char *argv[]){
if(argc != 3){
printf("usage: %s MESSAGE TITLE",argv[0]);
}
// MessageBox function (winuser.h)
// Displays a modal dialog box that contains
// a system icon,
// a set of buttons,
// and a brief application-specific message,
/// such as status or error information.
/// The message box returns an integer value that indicates which button the user clicked.
// ref https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messagebox
MessageBox(
0, /* [in, optional] HWND hWnd, */
argv[2], /* [in, optional] LPCTSTR lpText, */
argv[1], /* [in, optional] LPCTSTR lpCaption, */
1 /* [in] UINT uType */
);
return 0;
}
@loneicewolf
Copy link
Author

loneicewolf commented Jul 14, 2022

running it on a windows 10 workstation( inside of Qubes )
msgbox_win10

@loneicewolf
Copy link
Author

image

C++ DLL

DllMain.cpp

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
//__declspec(dllexport) THING
__declspec(dllexport) BOOL APIENTRY DllMain(HMODULE hModule,
											DWORD ul_reason_for_call,
											LPVOID lpReserved
											)
{
	switch(ul_reason_for_call){
	
		case DLL_PROCESS_ATTACH:
			{
				//https://gist.github.com/loneicewolf/c588f95287c55454ef6a5c28e8babd30
				// loneicewolf/win_msgbox.c 
				MessageBox(
				0,       /*   [in, optional] HWND    hWnd,      */
				"TEXT", /*   [in, optional] LPCTSTR lpText,     */
				"TITLE", /*   [in, optional] LPCTSTR lpCaption, */
				1        /*   [in]           UINT    uType      */
				);
				break;
			}
		case DLL_PROCESS_DETACH:
			{
				break;
			}
		case DLL_THREAD_ATTACH:
			{
				break;
			}
		case DLL_THREAD_DETACH:
			{
				break;
			}
	
	}
	return TRUE;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment