Click here to Skip to main content
15,910,234 members
Home / Discussions / C#
   

C#

 
AnswerRe: Seriously silly sockets - please assist Pin
Jimmanuel21-Jul-10 10:34
Jimmanuel21-Jul-10 10:34 
GeneralRe: Seriously silly sockets - please assist Pin
GrenMeera22-Jul-10 5:11
GrenMeera22-Jul-10 5:11 
GeneralRe: Seriously silly sockets - please assist Pin
Jimmanuel22-Jul-10 7:26
Jimmanuel22-Jul-10 7:26 
AnswerRe: Seriously silly sockets - please assist Pin
LimitedAtonement21-Jul-10 10:42
LimitedAtonement21-Jul-10 10:42 
GeneralRe: Seriously silly sockets - please assist Pin
GrenMeera22-Jul-10 5:18
GrenMeera22-Jul-10 5:18 
GeneralRe: Seriously silly sockets - please assist Pin
jschell22-Jul-10 8:38
jschell22-Jul-10 8:38 
QuestionRe: Seriously silly sockets - please assist Pin
Jimmanuel22-Jul-10 9:20
Jimmanuel22-Jul-10 9:20 
QuestionOnly in Release config, SetWindowsHookEx throws error 80004005 Pin
LimitedAtonement21-Jul-10 9:36
LimitedAtonement21-Jul-10 9:36 
Dear Sirs,

I'm having a problem with SetWindowsHookEx. In Debug mode, no problem, in release, it throws. Here's the code:

namespace barcode
{
    public static class program
    {
        static void Main(string[] args)
        {
            _keyboard_delegate = Keyboard_Msg_Pump;
            _keyboard_hook_handle = SetWindowsHookEx(
                WH_KEYBOARD_LL,
                _keyboard_delegate,
                System.Runtime.InteropServices.Marshal.GetHINSTANCE(
                    System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0]),
                0);
            if (_keyboard_hook_handle == 0)
            {//this is failure...
                int errorCode = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
                throw new System.ComponentModel.Win32Exception(errorCode);
            }
        }

        private static int Keyboard_Msg_Pump(int nCode, System.Int32 wParam, System.IntPtr lParam)
        {
            return 12;
        }

        private static int _keyboard_hook_handle;
        private static HOOKPROC _keyboard_delegate;
        private delegate int HOOKPROC(int nCode, int wParam, System.IntPtr lParam);

        private const int WH_KEYBOARD_LL = 13;
        [System.Runtime.InteropServices.DllImport("user32.dll",
            CharSet=System.Runtime.InteropServices.CharSet.Auto, 
            CallingConvention=System.Runtime.InteropServices.CallingConvention.StdCall, 
            SetLastError=true)]
        private static extern int SetWindowsHookEx(
            int idHook,
            HOOKPROC lpfn,
            System.IntPtr hMod,
            int dwThreadId);
    }
}

If you get to line sixteen (right after the if statement in the Main proc), you have an error. Try stepping through this example and tell me if it works for you. If I'm in debug mode, it works for me, but if I'm in release (even with optimize code off, which I thought would make it just like DEBUG), it fails with inconsistent errors, sometimes it says "Operation completed successfully" sometimes it says "Access denied" and other things. Let me know if you can run it in Release, and how. If not, tell me what error you get.

JUST NOW, as I was writing this, I decided that it might be the setting, "Enable the VSHost" process. If it's off, it works. If it's on, no good. Does the VSHost run under lower authority than the user?? Let me know what you think.
In Christ,
Aaron Laws

http://ProCure.com

AnswerRe: Only in Release config, SetWindowsHookEx throws error 80004005 Pin
Dave Kreskowiak21-Jul-10 10:22
mveDave Kreskowiak21-Jul-10 10:22 
Question? : Operator Pin
I Believe In GOD21-Jul-10 7:00
I Believe In GOD21-Jul-10 7:00 
AnswerRe: ? : Operator PinPopular
harold aptroot21-Jul-10 7:02
harold aptroot21-Jul-10 7:02 
GeneralRe: ? : Operator Pin
I Believe In GOD21-Jul-10 7:06
I Believe In GOD21-Jul-10 7:06 
GeneralRe: ? : Operator Pin
harold aptroot21-Jul-10 7:13
harold aptroot21-Jul-10 7:13 
GeneralRe: ? : Operator Pin
I Believe In GOD21-Jul-10 7:12
I Believe In GOD21-Jul-10 7:12 
AnswerRe: ? : Operator Pin
Luc Pattyn21-Jul-10 7:02
sitebuilderLuc Pattyn21-Jul-10 7:02 
GeneralRe: ? : Operator Pin
I Believe In GOD21-Jul-10 7:10
I Believe In GOD21-Jul-10 7:10 
GeneralRe: ? : Operator Pin
Roger Wright21-Jul-10 7:54
professionalRoger Wright21-Jul-10 7:54 
GeneralRe: ? : Operator Pin
Luc Pattyn21-Jul-10 8:05
sitebuilderLuc Pattyn21-Jul-10 8:05 
GeneralRe: ? : Operator Pin
Roger Wright21-Jul-10 8:35
professionalRoger Wright21-Jul-10 8:35 
GeneralRe: ? : Operator Pin
Eddy Vluggen21-Jul-10 9:12
professionalEddy Vluggen21-Jul-10 9:12 
GeneralRe: ? : Operator Pin
dan!sh 21-Jul-10 9:18
professional dan!sh 21-Jul-10 9:18 
AnswerRe: ? : Operator Pin
dan!sh 21-Jul-10 9:24
professional dan!sh 21-Jul-10 9:24 
AnswerRe: ? : Operator Pin
yu-jian21-Jul-10 9:37
yu-jian21-Jul-10 9:37 
AnswerRe: ? : Operator Pin
brunoseixas22-Jul-10 5:24
brunoseixas22-Jul-10 5:24 
QuestionStopping Process Pin
anveshvm21-Jul-10 6:06
anveshvm21-Jul-10 6:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.