RasNotifyConnection rpoblem - Programmer

This is a discussion on RasNotifyConnection rpoblem - Programmer ; Hi, Can someone please tell me if I have anthing wrong with this. If I have it in debug mode and run it (VC++) I get a debug error: The valuse of the ESP was not properly saved across a ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: RasNotifyConnection rpoblem

  1. RasNotifyConnection rpoblem

    Hi,

    Can someone please tell me if I have anthing wrong with this.
    If I have it in debug mode and run it (VC++) I get a debug error:
    The valuse of the ESP was not properly saved across a funstion call.

    Then it gives an error and forces me to terminate it.

    If I debug it line by line, it says "Unhandled exception in MailProx.exe
    Access violation."

    Any ideas?

    Main.h
    typedef DWORD (*RasNoti)(HRASCONN, HANDLE, DWORD);

    Main.cpp
    RasNoti RasNotify;

    hinstModule = LoadLibrary("rasapi32.dll");

    RasNotify = (RasNoti) GetProcAddress(hinstModule ,
    "RasConnectionNotificationA");

    hRasNotiConnect = CreateEvent(NULL, false, false, NULL);
    ConnLooph = CreateThread(NULL, NULL, WaitLoop, (LPVOID)hRasNotiConnect,
    NULL, &ConnLooptid);
    (RasNotify)((HRASCONN) INVALID_HANDLE_VALUE, hRasNotiConnect, 1);


    WaitLoop (lpVOID Bla)
    WaitForSingleObject (hRasNotiConnect, INFINITE)
    //Do stuff
    Return
    }



  2. Re: RasNotifyConnection rpoblem

    Ben,

    The problem is that your typedef'd declaration for function
    "RasNoti" is not declared with the APIENTRY macro as is required.
    Here is the prototype from the Microsoft RAS.H header:

    DWORD APIENTRY RasConnectionNotificationA( HRASCONN, HANDLE, DWORD );

    If you track down APIENTRY, you'll find that it maps to __stdcall.
    This means that the the called function pops the parameters off of the
    stack instead of the default (callee pops the stack). Because you're
    implicitly declaring your function as __cdecl, your function is not
    cleaning up the stack.

    See also: "PASCAL" calling convention.

    Good luck,
    Integral Concepts, Inc.
    Les Matheson
    http://www.ivsds.com


    "Ben" wrote in message news:<403c786b$0$22503$5a62ac22@freenews.iinet.net.au>...
    > Hi,
    >
    > Can someone please tell me if I have anthing wrong with this.
    > If I have it in debug mode and run it (VC++) I get a debug error:
    > The valuse of the ESP was not properly saved across a funstion call.
    >
    > Then it gives an error and forces me to terminate it.
    >
    > If I debug it line by line, it says "Unhandled exception in MailProx.exe
    > Access violation."
    >
    > Any ideas?
    >
    > Main.h
    > typedef DWORD (*RasNoti)(HRASCONN, HANDLE, DWORD);
    >
    > Main.cpp
    > RasNoti RasNotify;
    >
    > hinstModule = LoadLibrary("rasapi32.dll");
    >
    > RasNotify = (RasNoti) GetProcAddress(hinstModule ,
    > "RasConnectionNotificationA");
    >
    > hRasNotiConnect = CreateEvent(NULL, false, false, NULL);
    > ConnLooph = CreateThread(NULL, NULL, WaitLoop, (LPVOID)hRasNotiConnect,
    > NULL, &ConnLooptid);
    > (RasNotify)((HRASCONN) INVALID_HANDLE_VALUE, hRasNotiConnect, 1);
    >
    >
    > WaitLoop (lpVOID Bla)
    > WaitForSingleObject (hRasNotiConnect, INFINITE)
    > //Do stuff
    > Return
    > }


  3. Re: RasNotifyConnection rpoblem

    Thankyou

    "Les Matheson" wrote in message
    news:c3cdfd62.0402291942.311372c6@posting.google.c om...
    > Ben,
    >
    > The problem is that your typedef'd declaration for function
    > "RasNoti" is not declared with the APIENTRY macro as is required.
    > Here is the prototype from the Microsoft RAS.H header:
    >
    > DWORD APIENTRY RasConnectionNotificationA( HRASCONN, HANDLE, DWORD );
    >
    > If you track down APIENTRY, you'll find that it maps to __stdcall.
    > This means that the the called function pops the parameters off of the
    > stack instead of the default (callee pops the stack). Because you're
    > implicitly declaring your function as __cdecl, your function is not
    > cleaning up the stack.
    >
    > See also: "PASCAL" calling convention.
    >
    > Good luck,
    > Integral Concepts, Inc.
    > Les Matheson
    > http://www.ivsds.com
    >
    >
    > "Ben" wrote in message

    news:<403c786b$0$22503$5a62ac22@freenews.iinet.net.au>...
    > > Hi,
    > >
    > > Can someone please tell me if I have anthing wrong with this.
    > > If I have it in debug mode and run it (VC++) I get a debug error:
    > > The valuse of the ESP was not properly saved across a funstion call.
    > >
    > > Then it gives an error and forces me to terminate it.
    > >
    > > If I debug it line by line, it says "Unhandled exception in MailProx.exe
    > > Access violation."
    > >
    > > Any ideas?
    > >
    > > Main.h
    > > typedef DWORD (*RasNoti)(HRASCONN, HANDLE, DWORD);
    > >
    > > Main.cpp
    > > RasNoti RasNotify;
    > >
    > > hinstModule = LoadLibrary("rasapi32.dll");
    > >
    > > RasNotify = (RasNoti) GetProcAddress(hinstModule ,
    > > "RasConnectionNotificationA");
    > >
    > > hRasNotiConnect = CreateEvent(NULL, false, false, NULL);
    > > ConnLooph = CreateThread(NULL, NULL, WaitLoop,

    (LPVOID)hRasNotiConnect,
    > > NULL, &ConnLooptid);
    > > (RasNotify)((HRASCONN) INVALID_HANDLE_VALUE, hRasNotiConnect, 1);
    > >
    > >
    > > WaitLoop (lpVOID Bla)
    > > WaitForSingleObject (hRasNotiConnect, INFINITE)
    > > //Do stuff
    > > Return
    > > }




+ Reply to Thread