All content of a dll is always copied to the memory space of every program and so all the variables doesn't share the same value, if they haven't been given the same value that is. The #pragma data_seg(".hello") tells the compiler to register all the following code in the data segment called "Hello". The #pragma data_seg() tells the compiler that the current data segment has ended. The pragma comment(linker, "/section:.hello,rws") tells the compiler to use all the code in the "Hello" data segmnet as public code and share it between all applications that use this dll. In others words the g_hHkKeyboard variable has the same value in every program that uses this dll. This is often used in hook dlls becouse when other applications want to call the hook function (like ex. KeboardProc) they must have the same hook handle value to send the hook message to the next hook function in the hook chain. That is the part that makes hook apis more advanced all programs have to be able to call the hook function when they get the message that is hooked.
Code:
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
But if you remove that shared data segment only your application can call the hook function and makes the hole idea to use the hook in a dll pointless. I hope you understod all of that, if you didn't please ask more.