473,512 Members | 15,089 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Debug vs Release

Hello,

After getting some posts on forums.microsoft.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("PCSHLL32.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(string sSessionID, int iPosition, int
iLength, out UInt32 iReturnCode) {
string sScreenText = "";

try {
iReturnCode = Connect(sSessionID);
MessageBox.Show("Connection: " + iReturnCode.ToString());
if(iReturnCode == HARC_SUCCESS) {
iReturnCode = ReadScreen(iPosition, iLength, out sScreenText);
MessageBox.Show("ReadScreen: " + iReturnCode.ToString());
} // if we successfully connected to the session
} catch(Exception e) {
throw(e);
} finally {
iReturnCode = Disconnect(sSessionID);
MessageBox.Show("Disconnect: " + iReturnCode.ToString());
} // try-catch-finally

return sScreenText;
} // ScrapeScreen - Method

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

sbData.Append(sSessionID);
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(3000);

UInt32 rc = (UInt32)iPosition;
UInt32 iFunction = HA_COPY_PS_TO_STR;
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(string sSessionID) {
StringBuilder sbData = new StringBuilder(4);
sbData.Append(sSessionID);
UInt32 rc = 0;
UInt32 iFunction = HA_DISCONNECT_PS;
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
Mar 30 '07 #1
7 3043
Grigs,

Can you show the function signature in the header file for the hllapi
function?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Grigs" <Gr***@discussions.microsoft.comwrote in message
news:E4**********************************@microsof t.com...
Hello,

After getting some posts on forums.microsoft.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("PCSHLL32.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(string sSessionID, int iPosition, int
iLength, out UInt32 iReturnCode) {
string sScreenText = "";

try {
iReturnCode = Connect(sSessionID);
MessageBox.Show("Connection: " + iReturnCode.ToString());
if(iReturnCode == HARC_SUCCESS) {
iReturnCode = ReadScreen(iPosition, iLength, out sScreenText);
MessageBox.Show("ReadScreen: " + iReturnCode.ToString());
} // if we successfully connected to the session
} catch(Exception e) {
throw(e);
} finally {
iReturnCode = Disconnect(sSessionID);
MessageBox.Show("Disconnect: " + iReturnCode.ToString());
} // try-catch-finally

return sScreenText;
} // ScrapeScreen - Method

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

sbData.Append(sSessionID);
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(3000);

UInt32 rc = (UInt32)iPosition;
UInt32 iFunction = HA_COPY_PS_TO_STR;
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(string sSessionID) {
StringBuilder sbData = new StringBuilder(4);
sbData.Append(sSessionID);
UInt32 rc = 0;
UInt32 iFunction = HA_DISCONNECT_PS;
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

Mar 30 '07 #2
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]
- mv*@spam.guard.caspershouse.com
Mar 30 '07 #3
"Grigs" <Gr***@discussions.microsoft.comwrote in message
news:E4**********************************@microsof t.com...
Hello,

After getting some posts on forums.microsoft.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("PCSHLL32.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(string sSessionID, int iPosition, int
iLength, out UInt32 iReturnCode) {
string sScreenText = "";

try {
iReturnCode = Connect(sSessionID);
MessageBox.Show("Connection: " + iReturnCode.ToString());
if(iReturnCode == HARC_SUCCESS) {
iReturnCode = ReadScreen(iPosition, iLength, out sScreenText);
MessageBox.Show("ReadScreen: " + iReturnCode.ToString());
} // if we successfully connected to the session
} catch(Exception e) {
throw(e);
} finally {
iReturnCode = Disconnect(sSessionID);
MessageBox.Show("Disconnect: " + iReturnCode.ToString());
} // try-catch-finally

return sScreenText;
} // ScrapeScreen - Method

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

sbData.Append(sSessionID);
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(3000);

UInt32 rc = (UInt32)iPosition;
UInt32 iFunction = HA_COPY_PS_TO_STR;
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(string sSessionID) {
StringBuilder sbData = new StringBuilder(4);
sbData.Append(sSessionID);
UInt32 rc = 0;
UInt32 iFunction = HA_DISCONNECT_PS;
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.

Mar 30 '07 #4
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("PCSHLL32.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]
- mv*@spam.guard.caspershouse.com

"Grigs" <Gr***@discussions.microsoft.comwrote in message
news:14**********************************@microsof t.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]
- mv*@spam.guard.caspershouse.com

Mar 30 '07 #5
"Grigs" <Gr***@discussions.microsoft.comwrote in message
news:14**********************************@microsof t.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]
- mv*@spam.guard.caspershouse.com

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

[DllImport("PCSHLL32.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.

Mar 30 '07 #6
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:ON**************@TK2MSFTNGP02.phx.gbl...
"Grigs" <Gr***@discussions.microsoft.comwrote in message
news:14**********************************@microsof t.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]
- mv*@spam.guard.caspershouse.com


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

[DllImport("PCSHLL32.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.

Mar 30 '07 #7
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("PCSHLL32.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.

Mar 30 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2883
by: Srinivasa Rao | last post by:
I have read in one article that when we compile the application in release mode, all the debug classes and properties will be automatically removed from the code. I tried to implement this thing by...
9
1985
by: dee | last post by:
Hi I'm about to upload my site and I have switched to release version. Is that enough or do I still need to disable <compilation defaultLanguage="vb" debug="true" /> the debug="true" in the .pdb...
3
2177
by: | last post by:
Since I need to dotfuscate my exe file anyway, does it make any difference if I use Debug or Release versions. Would a Debug version be easier to decompile/study/reverse engineer than a Release...
1
1967
by: Epetruk | last post by:
Hello, In VS2003, I used to have two solutions - a debug and release solution. Each solution had a webservice project and several other class library projects. The webservice project...
2
2359
by: Epetruk | last post by:
Hello, I have a problem where an application I am working on throws an OutOfMemoryException when I run it in Release mode, whereas it doesn't do this when I am running in Debug. The...
6
9119
by: Andrew Rowley | last post by:
I am having trouble getting debug and release builds to work properly with project references using C++ .NET and Visual Studio 2003. I created a test solution, with a basic Windows form C++...
3
15501
by: Bob Johnson | last post by:
It is my understanding - and please correct me if I'm wrong - that when building a project in debug mode, I can deploy the .pdb file along with the ..exe and thereby have access to the specific...
3
1964
by: TBass | last post by:
Hello, Is there a way to get Visual Studio 2003 look to one directory for debug version dlls when set to DEBUG and then to another directory where I store the release version of a dll when set...
2
2684
by: Dave Johansen | last post by:
I just converted a solution from Visual Studio 2003 to Visual Studio 2005 and the Debug mode seems to be running just fine, but the Release mode crashes on the following code: std::ifstream...
3
3362
by: =?Utf-8?B?bG10dGFn?= | last post by:
We have developed a number of different applications (ASP.NET web site, Windows services, DLLs, Windows forms, etc.) in C# 2.0. We have developed and unit tested all these applications/components...
0
7371
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5676
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5077
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1583
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.