what's the purpose of the following about UNREFERENCED_PARAMETER? - windows

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
what's the purpose of UNREFERENCED_PARAMETER here?

It just suppresses a compiler warning about two parameters being unused in the function.
The macro itself is probably just defined as
#define UNREFERENCED_PARAMETER(x) (x)
so it references its argument but does nothing with it.

Related

Basic Win32 C programming

I'm trying to display the command line arguments.
This is my current code.
#include "windows.h"
int _stdcall WinMain ( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpszCmdline,
int nCmdShow )
{
MessageBox ( 0, lpszCmdLine,L"Title",0);
return ( 0 ) ;
}
I'm getting different characters in application.
What changes should I do in order to display the command line arguments in application window?
Since lpszCmdline is LPSTR, (ASCII, not UNICODE), the first option would be using the ASCII version of MessageBox(), but since UNICODE is the standard, I would suggest using the UNICODE version of win32 entry point. See the code below:
#include "windows.h"
int _stdcall wWinMain ( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpszCmdline,
int nCmdShow )
{
MessageBox ( 0, lpszCmdLine,L"Title",0);
return ( 0 ) ;
}
Further more, to convert the command line to an argv style array of strings, call the CommandLineToArgvW function.

What was the idea behind RunDLL?

Why was RunDLL and later RunDLL32 conceived? What is the purpose of their existence? So as to bypass the task manager?
https://support.microsoft.com/en-us/kb/164787
The article states that RunDLL still requires a particular method header for a candidate entry point:
16-bit DLL:
void FAR PASCAL __loadds
EntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);
32-bit DLL:
void CALLBACK
EntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);
What is the purpose of using a RunDLL entry point rather than a main entry point as in a regular executable file?

Error 42: Symbol Undefined _CreateWindowW#44 when trying to register non existing windows function binding

I try to write simple show_window function but that which uses wide chars, there are no examples anywhere in D of that, only I could find windows creation that uses narrow-string and try now to rewrite that (I know bad english). So I'm failing even at proper registering unicode winapi bindings.
import core.runtime;
import core.sys.windows.windows;
import std.c.windows.windows;
pragma(lib, "gdi32.lib");
pragma(lib, "user32.lib");
struct WNDCLASSW { UINT style; WNDPROC lpfnWndProc; int cbClsExtra; int cbWndExtra; HINSTANCE hInstance; HICON hIcon; HCURSOR hCursor; HBRUSH hbrBackground; LPCWSTR lpszMenuName; LPCWSTR lpszClassName; }
extern(Windows) HWND CreateWindowW(LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam );
extern(Windows)
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow) {
HWND hWnd = CreateWindowW("wndClassName",
"window caption", WS_SYSMENU | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, HWND_DESKTOP, null, hInstance, null);
return 0;
}
and that produces:
Error 42: Symbol Undefined _CreateWindowW#44
Modern versions of Windows do not implement CreateWindow(). It is an ancient winapi function that dates from the 1980s and has been replaced by CreateWindowEx(). In the WinUser.h SDK header, CreateWindowW is a macro that actually calls CreateWindowExW(), passing 0 for the extra dwExStyle argument.
You must use CreateWindowExW() instead.

How to hide the console window in a Win32 project using Visual Studio 2010

I need to create an exe application with no console window or (any other window) during the start up of the application.
I tried the below for this:
Using Visual Studio 2010, created a Win32 Console Application as an Empty Project.
Added a header file "stdafx.h" to the project
Added a cpp file to the project and added the below code.
The project settings are visual stduio default.
#include "stdafx.h"
#include <windows.h>
#include "TlHelp32.h"
#include <iostream>
#include <string>
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
return 0;
}
The above code compiles good.
But if I change the Character Set to "Use Unicode Character Set", I am getting the following compilation error.
error C2731: 'WinMain' : function cannot be overloaded
I am building the application on a Windows 7 64 bit computer and Visual Studio Build platform as x64.
Thanks in advance for your help.
Yes, when you build with UNICODE in effect then the entrypoint takes a Unicode string for the command line argument. So that requires a different declaration:
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPWSTR lpCmdLine, int nShowCmd)
Or you can use #include <tchar.h> so it works either way, not much point to it these days:
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
Create Windows service instead console app.
In Visual Studio, create a new "EMPTY Project". Add a new source file named "main.cpp". Use the following template (assumes you want to build with Unicode):
/************
main.cpp
************/
#define UNICODE 1
#include <windows.h>
int APIENTRY wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPWSTR lpCmdLine, int nShowCmd)
{
// Process Return Codes
const int SUCCESS=0, FAILURE=1;
return SUCCESS;
}

OpenGL ES Tutorial - 'Winmain': function cannot be overloaded

I'm trying to learn OpenGL ES with the "OpenGL ES Training Course" (An OpenGL ES tutorial). I use OPENGL-ES 1.1 WINDOWS PC EMULATION with visual studio 2010. I'm trying to compile the 'hello triangle' program and get an error:
'WinMain': function cannot be overloaded
EDIT: I have only one definition of WinMain in the project: The one in the 'hello triangle' source code (which I didn't write).
Could anyone tell me what's going on?
It sounds like you have two definitions of WinMain, or perhaps a prototype and a definition that disagree.
I had the problem too. It showed that I have overloaded the function:
My old text:
#include "windows.h"
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, long lpCmdLine, int nCmdShow)
{
}
and my new text:
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
With the new text it works
Try
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
// Your Code.
}
Instead Of
int WinMain(){
// Your Code.
}

Resources