G
Guest
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
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