It seems a bit "sketchy" that you seem to be asking these security related questions too often, that too they tend to ask for practical questions. I sincerely hope it is not Malwares you are programming.
On topic, there are several DNS\Internet related functions you can hijack\hook in order to redirect\block websites. There are several functions you need to hook in order to succeed with your criteria, are LSP
based hooks, they stand for Layered Socket Providers and are much more lower than most functions such as the ones most Website-Re-directors\Blockers hooks, therefore it will provide more ease of usage and will reduce the chances of it being unhooked and competing. The LSP
functions are WSPSend()
and more and hooking these functions will perform at lower level.
The most common and easiest based hook to create is DnsQuery_W()
(Unicode) although this will only work on one browser, not telling because I wish you do a bit of research on you own.
There are many Internet-based functions you need to hook before all of the web-browsers will be at your proper control.
Do be aware that Browsers like Google Chrome are extremely protected and will deny and access to its components and it makes it ever so hard to hook into it, every time I do an Ring3 level injection (obvious) the Google Chrome's Sand Box is triggered instantaneously and it is almost impossible to do it but some have managed.
How AV's such as Avast managed to block are by it hooking networking function at kernel level therefore it does not need any injecting into foreign processes therefore its hooks it places are system-wide.
I am guessing you are working at User-mode, therefore you need to inject the hook into foreign processes via usage of DLL (Dynamic Link Libraries) files, Code Injection , Windows Hook function which forces all processes to load a DLL.
files is a very bad idea keeping in mind almost every "good" AV, always protect it and monitor it, and making changes to it is going to end up in termination of your software besides it will be detected before even running.