ANTICHAT.XYZ    VIDEO.ANTICHAT.XYZ    НОВЫЕ СООБЩЕНИЯ    ФОРУМ  
Баннер 1   Баннер 2
Antichat снова доступен.
Форум Antichat (Античат) возвращается и снова открыт для пользователей. Здесь обсуждаются безопасность, программирование, технологии и многое другое. Сообщество снова собирается вместе.
Новый адрес: forum.antichat.xyz
Вернуться   Форум АНТИЧАТ > Оффтоп > Forum for discussion of ANTICHAT
   
 
 
Опции темы Поиск в этой теме Опции просмотра

10 tips & tricks for C/C++ windows programming with Visual C++ 6.0
  #1  
Старый 30.05.2006, 17:11
Аватар для Dracula4ever
Dracula4ever
Постоянный
Регистрация: 08.05.2006
Сообщений: 559
Провел на форуме:
1593567

Репутация: 354


Отправить сообщение для Dracula4ever с помощью ICQ Отправить сообщение для Dracula4ever с помощью AIM Отправить сообщение для Dracula4ever с помощью Yahoo
Post 10 tips & tricks for C/C++ windows programming with Visual C++ 6.0

1)Hiding a console window-
in order to hide a console window, just add the following line to your source code:
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )

2)Having smaller exe- by adding this line:
#pragma comment(linker, "/OPT:NOWIN98")
you can significantly resize your exe size.
But, the cache is that it won't run smoothly on windows 98 OS.
So, you should use this option only when you compile applications that will be used only on windows NT.

3)Using windows hooks without an external DLL:
Installing windows hooks is a powerfull ability, that can be exploited for maliciousness purpose.
It seems like the MSDN attemps to "hide" the ability to install hooks without using external dll from the developers.
So, in order to install global windows hook, we need to export function from a dll, we can solve this by simply adding this:
__declspec(dllexport)
before the function's definition.

4) Share data between a few different instances of the program:

By adding this section to your code, you can share data between a few instances of your program:

#pragma data_seg(".SHARED")
int shared=0;//variables that will be shared
#pragma data_seg()
#pragma comment(linker, "/section:.SHARED,RWS")

5) Creating an edit box that accepts only numbers:
In order to preform this action, you need to change the window's procedure.
This action can be preformed by a technique called "Windows subclassing", you can find more information about this technique here:
http://www.codeproject.com/dialog/messagehandling4.asp

6) Extract the file name from a path:
for this sake, there is no need to parse anything by yourself.
you can simply use the _splitpath() functions, that splits path into a few parts, the drive, the
directory, the file name and the file's extension.

7) Link library:
You can link library inside your source code by using this piece of code:
#pragma comment(lib, "libname.lib");

8) Displaying an error message:
in order to display error message by it's error code, you can use the following function:

void PrintError(DWORD error)
{
LPVOID buff;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,error,
MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR)& buff,0,0);
printf("%s",buff);
}

9) Create a console window in a windows application:
for the purpose of creating a console windows in a windows application, and refferring all input and output to it, you can use the following piece of code:

AllocConsole();
freopen("conin$", "r", stdin); //console input buffer
freopen("conout$", "w", stdout);//console output buffer
freopen("conout$", "w", stderr); //console error device

10) How to assure that only one instance of the application is running at a time:
You can create a kernel object(mutex for example) and check if it is already
exists.
See the following code for example:

char name[]="objectname1331"
HANDLE hKernel;

hKernel = CreateMutex(NULL, FALSE,
name);

if (GetLastError() == ERROR_ALREADY_EXISTS)
{
exit(0);
}
 
Ответить с цитированием
 



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Определиние Ip Dimann Болталка 18 09.06.2008 01:06
Поиск Microsoft Visual C++ 6.0 [alg0n Разное - Покупка, продажа, обмен 0 30.05.2006 11:29
Windows Vista - "Новые возможности" от Microsoft Hitman_2 Мировые новости 0 28.03.2006 01:31
Microsoft заделала многочисленные дыры в Windows DRON-ANARCHY Мировые новости 3 13.10.2005 16:15



Здесь присутствуют: 1 (пользователей: 0 , гостей: 1)
 


Быстрый переход




ANTICHAT.XYZ