Debug vs Release

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?R3JpZ3M=?=

    Debug vs Release

    Hello,

    After getting some posts on forums.microsof t.com but no solution I was asked
    to post over here. Hopefully someone here can help with my problem.

    I have a Windows Forms application written in C# via VS 2003. It does 100%
    of what it should while in Debug mode (running in the debugger as well as
    running the .exe from File Explorer.) However, there is one thing it does
    not do when compiled in Release mode (running in the debugger nor from the
    ..exe.) There is an external .dll I have to connect to, to do a screen scrape
    of an AS400 application. The linking of it is as follows:

    [DllImport("PCSH LL32.dll")] public static extern UInt32 hllapi(out UInt32
    Func, StringBuilder sbData, out UInt32 Length, out UInt32 RetC);

    Here is the actual code, less the constants, that get run:

    public static string ScrapeScreen(st ring sSessionID, int iPosition, int
    iLength, out UInt32 iReturnCode) {
    string sScreenText = "";

    try {
    iReturnCode = Connect(sSessio nID);
    MessageBox.Show ("Connection : " + iReturnCode.ToS tring());
    if(iReturnCode == HARC_SUCCESS) {
    iReturnCode = ReadScreen(iPos ition, iLength, out sScreenText);
    MessageBox.Show ("ReadScreen : " + iReturnCode.ToS tring());
    } // if we successfully connected to the session
    } catch(Exception e) {
    throw(e);
    } finally {
    iReturnCode = Disconnect(sSes sionID);
    MessageBox.Show ("Disconnect : " + iReturnCode.ToS tring());
    } // try-catch-finally

    return sScreenText;
    } // ScrapeScreen - Method

    public static UInt32 Connect(string sSessionID) {
    StringBuilder sbData = new StringBuilder(4 );

    sbData.Append(s SessionID);
    UInt32 rc = 0;
    UInt32 iFunction = HA_CONNECT_PS; // function code
    UInt32 iLength = 4; // length of data parameter
    return hllapi(out iFunction, sbData, out iLength, out rc);
    } // Connect - Method

    public static UInt32 ReadScreen(int iPosition, int len, out string
    sText) {
    StringBuilder sbData = new StringBuilder(3 000);

    UInt32 rc = (UInt32)iPositi on;
    UInt32 iFunction = HA_COPY_PS_TO_S TR;
    UInt32 iLength = (UInt32)len;
    UInt32 iReturnCode = hllapi(out iFunction, sbData, out iLength, out rc);
    sText = sbData.ToString (); // result
    return iReturnCode;
    } // ReadScreen - Method

    public static UInt32 Disconnect(stri ng sSessionID) {
    StringBuilder sbData = new StringBuilder(4 );
    sbData.Append(s SessionID);
    UInt32 rc = 0;
    UInt32 iFunction = HA_DISCONNECT_P S;
    UInt32 iLength = 4;
    return hllapi(out iFunction, sbData, out iLength, out rc);
    } // Disconnect - Method

    When I run in Debug mode it connects and gives me the correct return code of
    0 which = Success. However, when I run in Release mode I get a different
    return code of 10 which is Unsupported.

    There is no code difference between modes. I have no #debug or anything
    onther than the exact code. I have even tried swapping the values of
    "Enabled Unmanaged Debugging" since the PCSHLL32.dll is most likely writting
    in C++ by IBM.

    The only thing I can figure is perhaps a security difference between Debug
    and Release modes. Is this the case?

    Are there any other suggestions on how I can get this piece to work?

    Thanks in advance,
    Grigs
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Debug vs Release

    Grigs,

    Can you show the function signature in the header file for the hllapi
    function?


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Grigs" <Grigs@discussi ons.microsoft.c omwrote in message
    news:E4B92BA4-B146-430F-A71E-3B67ADAEB64E@mi crosoft.com...
    Hello,
    >
    After getting some posts on forums.microsof t.com but no solution I was
    asked
    to post over here. Hopefully someone here can help with my problem.
    >
    I have a Windows Forms application written in C# via VS 2003. It does
    100%
    of what it should while in Debug mode (running in the debugger as well as
    running the .exe from File Explorer.) However, there is one thing it does
    not do when compiled in Release mode (running in the debugger nor from the
    .exe.) There is an external .dll I have to connect to, to do a screen
    scrape
    of an AS400 application. The linking of it is as follows:
    >
    [DllImport("PCSH LL32.dll")] public static extern UInt32 hllapi(out UInt32
    Func, StringBuilder sbData, out UInt32 Length, out UInt32 RetC);
    >
    Here is the actual code, less the constants, that get run:
    >
    public static string ScrapeScreen(st ring sSessionID, int iPosition, int
    iLength, out UInt32 iReturnCode) {
    string sScreenText = "";
    >
    try {
    iReturnCode = Connect(sSessio nID);
    MessageBox.Show ("Connection : " + iReturnCode.ToS tring());
    if(iReturnCode == HARC_SUCCESS) {
    iReturnCode = ReadScreen(iPos ition, iLength, out sScreenText);
    MessageBox.Show ("ReadScreen : " + iReturnCode.ToS tring());
    } // if we successfully connected to the session
    } catch(Exception e) {
    throw(e);
    } finally {
    iReturnCode = Disconnect(sSes sionID);
    MessageBox.Show ("Disconnect : " + iReturnCode.ToS tring());
    } // try-catch-finally
    >
    return sScreenText;
    } // ScrapeScreen - Method
    >
    public static UInt32 Connect(string sSessionID) {
    StringBuilder sbData = new StringBuilder(4 );
    >
    sbData.Append(s SessionID);
    UInt32 rc = 0;
    UInt32 iFunction = HA_CONNECT_PS; // function code
    UInt32 iLength = 4; // length of data parameter
    return hllapi(out iFunction, sbData, out iLength, out rc);
    } // Connect - Method
    >
    public static UInt32 ReadScreen(int iPosition, int len, out string
    sText) {
    StringBuilder sbData = new StringBuilder(3 000);
    >
    UInt32 rc = (UInt32)iPositi on;
    UInt32 iFunction = HA_COPY_PS_TO_S TR;
    UInt32 iLength = (UInt32)len;
    UInt32 iReturnCode = hllapi(out iFunction, sbData, out iLength, out
    rc);
    sText = sbData.ToString (); // result
    return iReturnCode;
    } // ReadScreen - Method
    >
    public static UInt32 Disconnect(stri ng sSessionID) {
    StringBuilder sbData = new StringBuilder(4 );
    sbData.Append(s SessionID);
    UInt32 rc = 0;
    UInt32 iFunction = HA_DISCONNECT_P S;
    UInt32 iLength = 4;
    return hllapi(out iFunction, sbData, out iLength, out rc);
    } // Disconnect - Method
    >
    When I run in Debug mode it connects and gives me the correct return code
    of
    0 which = Success. However, when I run in Release mode I get a different
    return code of 10 which is Unsupported.
    >
    There is no code difference between modes. I have no #debug or anything
    onther than the exact code. I have even tried swapping the values of
    "Enabled Unmanaged Debugging" since the PCSHLL32.dll is most likely
    writting
    in C++ by IBM.
    >
    The only thing I can figure is perhaps a security difference between Debug
    and Release modes. Is this the case?
    >
    Are there any other suggestions on how I can get this piece to work?
    >
    Thanks in advance,
    Grigs

    Comment

    • =?Utf-8?B?R3JpZ3M=?=

      #3
      Re: Debug vs Release

      It was not in the original article that started this adventure but doing some
      searching on the internet I believe it is the following IBM C/C++:

      #include "hapi_c.h"
      int HFunc, HLen, HRc; // Function parameters
      char HBuff[1]; // Function parameters
      ....
      HFunc = HA_RESET_SYSTEM ; // Run EHLLAPI function
      HLen = 0;
      HRc = 0;
      hllapi(&Func, HBuff, &HLen, &HRc);
      if (HRc != 0) {
      // ... EHLLAPI access error
      }


      "Nicholas Paldino [.NET/C# MVP]" wrote:
      Grigs,
      >
      Can you show the function signature in the header file for the hllapi
      function?
      >
      >
      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m
      >

      Comment

      • Willy Denoyette [MVP]

        #4
        Re: Debug vs Release

        "Grigs" <Grigs@discussi ons.microsoft.c omwrote in message
        news:E4B92BA4-B146-430F-A71E-3B67ADAEB64E@mi crosoft.com...
        Hello,
        >
        After getting some posts on forums.microsof t.com but no solution I was asked
        to post over here. Hopefully someone here can help with my problem.
        >
        I have a Windows Forms application written in C# via VS 2003. It does 100%
        of what it should while in Debug mode (running in the debugger as well as
        running the .exe from File Explorer.) However, there is one thing it does
        not do when compiled in Release mode (running in the debugger nor from the
        .exe.) There is an external .dll I have to connect to, to do a screen scrape
        of an AS400 application. The linking of it is as follows:
        >
        [DllImport("PCSH LL32.dll")] public static extern UInt32 hllapi(out UInt32
        Func, StringBuilder sbData, out UInt32 Length, out UInt32 RetC);
        >
        Here is the actual code, less the constants, that get run:
        >
        public static string ScrapeScreen(st ring sSessionID, int iPosition, int
        iLength, out UInt32 iReturnCode) {
        string sScreenText = "";
        >
        try {
        iReturnCode = Connect(sSessio nID);
        MessageBox.Show ("Connection : " + iReturnCode.ToS tring());
        if(iReturnCode == HARC_SUCCESS) {
        iReturnCode = ReadScreen(iPos ition, iLength, out sScreenText);
        MessageBox.Show ("ReadScreen : " + iReturnCode.ToS tring());
        } // if we successfully connected to the session
        } catch(Exception e) {
        throw(e);
        } finally {
        iReturnCode = Disconnect(sSes sionID);
        MessageBox.Show ("Disconnect : " + iReturnCode.ToS tring());
        } // try-catch-finally
        >
        return sScreenText;
        } // ScrapeScreen - Method
        >
        public static UInt32 Connect(string sSessionID) {
        StringBuilder sbData = new StringBuilder(4 );
        >
        sbData.Append(s SessionID);
        UInt32 rc = 0;
        UInt32 iFunction = HA_CONNECT_PS; // function code
        UInt32 iLength = 4; // length of data parameter
        return hllapi(out iFunction, sbData, out iLength, out rc);
        } // Connect - Method
        >
        public static UInt32 ReadScreen(int iPosition, int len, out string
        sText) {
        StringBuilder sbData = new StringBuilder(3 000);
        >
        UInt32 rc = (UInt32)iPositi on;
        UInt32 iFunction = HA_COPY_PS_TO_S TR;
        UInt32 iLength = (UInt32)len;
        UInt32 iReturnCode = hllapi(out iFunction, sbData, out iLength, out rc);
        sText = sbData.ToString (); // result
        return iReturnCode;
        } // ReadScreen - Method
        >
        public static UInt32 Disconnect(stri ng sSessionID) {
        StringBuilder sbData = new StringBuilder(4 );
        sbData.Append(s SessionID);
        UInt32 rc = 0;
        UInt32 iFunction = HA_DISCONNECT_P S;
        UInt32 iLength = 4;
        return hllapi(out iFunction, sbData, out iLength, out rc);
        } // Disconnect - Method
        >
        When I run in Debug mode it connects and gives me the correct return code of
        0 which = Success. However, when I run in Release mode I get a different
        return code of 10 which is Unsupported.
        >
        There is no code difference between modes. I have no #debug or anything
        onther than the exact code. I have even tried swapping the values of
        "Enabled Unmanaged Debugging" since the PCSHLL32.dll is most likely writting
        in C++ by IBM.
        >
        The only thing I can figure is perhaps a security difference between Debug
        and Release modes. Is this the case?
        >
        Are there any other suggestions on how I can get this piece to work?
        >
        Thanks in advance,
        Grigs


        I can hardly believe your hllapi signature is correct, although I can't directly explain why
        it works in release mode.


        Consider the part of the code that performs the Connect...

        UInt32 rc = 0;
        UInt32 iFunction = HA_CONNECT_PS; // function code
        UInt32 iLength = 4; // length of data parameter
        return hllapi(out iFunction, sbData, out iLength, out rc);
        } // Connect - Method

        Here you pass a 'Function' code (HA_CONNECT_PS) as 'out' parameter, IMO this shouldn't be an
        out parameter. The same goes for the third parameter, here you pass the length of the Data
        parameter to the callee, this shouldn't be passed as out.
        Another thing you should check, is the data parameter, are you sure you need to pass a
        StringBuilder? I guess it's not, I suspect the API expects a void*.
        Also, you pass an hard coded value, here you have to make sure in your DllImport declaration
        that the data is passed ansi character encoded.

        Anyway if you need more help, you will have to post the C API declaration.

        Willy.

        Comment

        • Nicholas Paldino [.NET/C# MVP]

          #5
          Re: Debug vs Release

          Grigs,

          Can you include the COMPLETE function signature, with parameter names
          and types in the correct order, as well as return type.

          From what I can see here though, your signature that you use for
          P/Invoke in .NET is completely wrong. Based on just this, it should be:

          [DllImport("PCSH LL32.dll")]
          public static extern UInt32 hllapi(int HFunc, int HLen, int HRC, byte
          HBuff);

          However, I don't think this is right, because what you displayed is not
          what would be in the header file.

          --
          - Nicholas Paldino [.NET/C# MVP]
          - mvp@spam.guard. caspershouse.co m

          "Grigs" <Grigs@discussi ons.microsoft.c omwrote in message
          news:1488F7C7-A439-40B6-9129-4633528CC681@mi crosoft.com...
          It was not in the original article that started this adventure but doing
          some
          searching on the internet I believe it is the following IBM C/C++:
          >
          #include "hapi_c.h"
          int HFunc, HLen, HRc; // Function parameters
          char HBuff[1]; // Function parameters
          ...
          HFunc = HA_RESET_SYSTEM ; // Run EHLLAPI function
          HLen = 0;
          HRc = 0;
          hllapi(&Func, HBuff, &HLen, &HRc);
          if (HRc != 0) {
          // ... EHLLAPI access error
          }
          >
          >
          "Nicholas Paldino [.NET/C# MVP]" wrote:
          >
          >Grigs,
          >>
          > Can you show the function signature in the header file for the hllapi
          >function?
          >>
          >>
          >--
          > - Nicholas Paldino [.NET/C# MVP]
          > - mvp@spam.guard. caspershouse.co m
          >>
          >

          Comment

          • Willy Denoyette [MVP]

            #6
            Re: Debug vs Release

            "Grigs" <Grigs@discussi ons.microsoft.c omwrote in message
            news:1488F7C7-A439-40B6-9129-4633528CC681@mi crosoft.com...
            It was not in the original article that started this adventure but doing some
            searching on the internet I believe it is the following IBM C/C++:
            >
            #include "hapi_c.h"
            int HFunc, HLen, HRc; // Function parameters
            char HBuff[1]; // Function parameters
            ...
            HFunc = HA_RESET_SYSTEM ; // Run EHLLAPI function
            HLen = 0;
            HRc = 0;
            hllapi(&Func, HBuff, &HLen, &HRc);
            if (HRc != 0) {
            // ... EHLLAPI access error
            }
            >
            >
            "Nicholas Paldino [.NET/C# MVP]" wrote:
            >
            >Grigs,
            >>
            > Can you show the function signature in the header file for the hllapi
            >function?
            >>
            >>
            >--
            > - Nicholas Paldino [.NET/C# MVP]
            > - mvp@spam.guard. caspershouse.co m
            >>
            >

            O, the tool a look in the HLLAPI programmers guide, and here is what I discovered..

            [DllImport("PCSH LL32.dll")] public static extern UInt32 hllapi(ref UInt32
            Func, StringBuilder sbData, out UInt32 Length, out UInt32 RetC);

            In case of a "connect" call you only need to specify the 'function' and 'sessionId', like
            this:

            UInt32 rc = 0;
            UInt32 iFunction = HA_CONNECT_PS; // function code
            return hllapi(out iFunction, sbData, out iLength, out rc);
            } // Connect - Method

            Note that you should inspect the 'rc' value on return, the return value of the API is of
            little value.

            Willy.

            Comment

            • Willy Denoyette [MVP]

              #7
              Re: Debug vs Release

              "Willy Denoyette [MVP]" <willy.denoyett e@telenet.bewro te in message
              news:ON3X0EucHH A.4188@TK2MSFTN GP02.phx.gbl...
              "Grigs" <Grigs@discussi ons.microsoft.c omwrote in message
              news:1488F7C7-A439-40B6-9129-4633528CC681@mi crosoft.com...
              >It was not in the original article that started this adventure but doing some
              >searching on the internet I believe it is the following IBM C/C++:
              >>
              >#include "hapi_c.h"
              >int HFunc, HLen, HRc; // Function parameters
              >char HBuff[1]; // Function parameters
              >...
              >HFunc = HA_RESET_SYSTEM ; // Run EHLLAPI function
              >HLen = 0;
              >HRc = 0;
              >hllapi(&Func , HBuff, &HLen, &HRc);
              >if (HRc != 0) {
              >// ... EHLLAPI access error
              >}
              >>
              >>
              >"Nicholas Paldino [.NET/C# MVP]" wrote:
              >>
              >>Grigs,
              >>>
              >> Can you show the function signature in the header file for the hllapi
              >>function?
              >>>
              >>>
              >>--
              >> - Nicholas Paldino [.NET/C# MVP]
              >> - mvp@spam.guard. caspershouse.co m
              >>>
              >>
              >
              >
              O, the tool a look in the HLLAPI programmers guide, and here is what I discovered..
              >
              [DllImport("PCSH LL32.dll")] public static extern UInt32 hllapi(ref UInt32
              Func, StringBuilder sbData, out UInt32 Length, out UInt32 RetC);
              >
              In case of a "connect" call you only need to specify the 'function' and 'sessionId', like
              this:
              >
              UInt32 rc = 0;
              UInt32 iFunction = HA_CONNECT_PS; // function code
              return hllapi(out iFunction, sbData, out iLength, out rc);
              } // Connect - Method
              >
              Note that you should inspect the 'rc' value on return, the return value of the API is of
              little value.
              >
              Willy.
              >

              Bluetooth keyboard interferences.. .
              O, the tool a look in the HLLAPI ...
              should read:
              Ok, I took a look in the HLLAPI ...

              Willy.

              Comment

              • =?Utf-8?B?R3JpZ3M=?=

                #8
                Re: Debug vs Release

                I agree about the signature. I got the initial class from an article on
                CodeProject xxx.

                I wound up attempting to make some changes to the definition and at its
                current state it looks like this:

                [DllImport("PCSH LL32.dll")]
                public static extern int hllapi(out int Func, StringBuilder sbData, out
                int Length, out int RetC);

                I did try and make the Function not an out as well as the length. I tried
                one and then the other. I always got errors and not even the connection
                worked. I then tried to make the StringBuilder a string, a byte[] and a
                char[] with no luck each time.

                I guess I will pass this along to the C API feed.

                --
                Thanx,
                Grigs
                >
                I can hardly believe your hllapi signature is correct, although I can't directly explain why
                it works in release mode.
                >
                >
                Consider the part of the code that performs the Connect...
                >
                UInt32 rc = 0;
                UInt32 iFunction = HA_CONNECT_PS; // function code
                UInt32 iLength = 4; // length of data parameter
                return hllapi(out iFunction, sbData, out iLength, out rc);
                } // Connect - Method
                >
                Here you pass a 'Function' code (HA_CONNECT_PS) as 'out' parameter, IMO this shouldn't be an
                out parameter. The same goes for the third parameter, here you pass the length of the Data
                parameter to the callee, this shouldn't be passed as out.
                Another thing you should check, is the data parameter, are you sure you need to pass a
                StringBuilder? I guess it's not, I suspect the API expects a void*.
                Also, you pass an hard coded value, here you have to make sure in your DllImport declaration
                that the data is passed ansi character encoded.
                >
                Anyway if you need more help, you will have to post the C API declaration.
                >
                Willy.
                >
                >

                Comment

                Working...