How to retrieve network parameters?

IpHlpApi provides a pretty useful function called GetNetworkParams. Helps in retrieving hostname, domain name, and dns server info. This is how we use this API. Code snippet taken from MSDN, modified a bit… [sourcecode language=’cpp’]#include “iphlpapi.h” #pragma comment( lib, “iphlpapi.lib” ) void PrintNetworkParams() {    FIXED_INFO*       pFixedInfo  = 0;    ULONG             ulOutBufLen = 0;    […]
Continue reading…

 

The “res” protocol!

Did you know that you can display HTML files from your exe or dll in an HTML control or in a browser using the “res” protocol which means resource protocol. Here is a demo… Displays a page from Google’s toolbar dll provided Google toolbar is installed on your computer in the given path. Paste these […]
Continue reading…

 

Easiest way to get plenty of information about a file!

We all need the easiest right! 😉 Well this is too easy, it’s already done for us by MFC. There is a structure called CFileStatus which holds plenty of information related to a file, for eg: it’s creation, modification, and access time, along with size of file, attribute of a file and absolute file name […]
Continue reading…

 

Displaying “Properties window” for any file!

Right click on any file in windows and select properties, you will see a tabbed properties window pop up. Ever wondered how to do this programmatically on any file that you choose… Here is a demo… [sourcecode language=”cpp”]#include <afxwin.h> #include <afxdlgs.h> // CFileDialog int main() {    // initialize MFC and print an error on […]
Continue reading…

 

Changing IP Address of a machine!

To change ip address of a machine use SetAdapterIpAddress. It’s an undocumented API found in iphlpapi.dll. Function signature is as follows… [sourcecode language=’cpp’]DWORD SetAdapterIpAddress( char *pszAdapGUID,                            DWORD dwDHCP,                            DWORD dwIP,                            DWORD dwMask,                            DWORD dwGateway );[/sourcecode] Look here for a demo, it’s in Russian but code is in english 😉
Continue reading…

 

How to get color of a pixel from any Bitmap?

It’s easy to get color of a pixel from a bitmap. Here is a function which does this… [sourcecode language=’cpp’]#include #include // Returns Pixel color from bitmap COLORREF GetPixelValueFromBitmap( const int x, const int y, CBitmap& bmp ) { // DC for desktop CDC dcDesktop; dcDesktop.Attach( ::GetDC( GetDesktopWindow() )); // Create a DC compatible with […]
Continue reading…