473,839 Members | 1,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange Error

Hi all,

I keep getting a strange error and can't pin it down. The message is:

This application has requested the Runtime to terminate it in an unusual
way.
Please contact the application's support team for more information.

However I'm not purposely requesting that the Runtime terminate in an
"unusual way." The line that is causing me headaches is:

wcscpy(data, MyCode.c_str()) ;

Where data and MyCode are defined as:

wchar_t data[256];
std::wstring AuthorCode;

The strange thing is that the program appears to be running fine in Visual
Studio, but generates the error message whenever I try to run it from the
command line. Putting a try...catch block around the line in question
doesn't help - it doesn't catch the exception. I have no idea what's
causing this...

Any ideas are appreciated!

Thanks!
Sep 12 '06 #1
11 2506
Just a guess for a starting point...

wcscpy is a wide character function, and its second parameter expects a
wide character string to copy from. In your example, you are using
c_str which is not a wide character function - it returns a string of 8
bit chars. wcscpy will attempt to combine every two bytes as a single
"character" in your input string. If you have an odd number of chars
in this string, wcscpy will attempt to access memory outside of the
string when it hits the last character, which may cause the crash?

Andy

B.T.W.

I'm having trouble accessing an unmanaged long from a managed class in
VC++.NET

When I do, the contents of the variable seem to be mangled. If I
access the same variable byte-by-byte, I get the correct value.
Regardless what I set the variable to, the value that is returned for a
long is always the same value. What's going on...can anyone help me?

A short version of the code follows:

//HEADER
namespace MyProgram
{

#pragma unmanaged
__nogc class unmanagedClass
{
public:unmanage dClass(); //CONSTRUCTOR

public: union{
struct {
long unmanagedLong; //UNMANAGED VARIABLE
} myData;
struct {
char bytes[4];
} b_myData;
} myUnion;
};
#pragma managed
public __gc class managedClass
{
public:managedC lass(); //CONSTRUCTOR
private: unmanagedClass __nogc *ptrUnmanagedCl ass; //PTR TO UNMANAGED
CLASS
public:System:: String* Get_unmanagedLo ng(); //METHOD TO GET
UNMANAGED VARIAHBLE
};
}

//CPP LISTING

//CONSTRUCTORS
MyProgram::unma nagedClass::unm anagedClass(){
unmanagedLong=1 536; //HEX #0600
}
MyProgram::mana gedClass::manag edClass(){
ptrUnmanagedCla ss=new unmanagedClass( );
}
System::String* MyProgram::mana gedClass::Get_u nmanagedLong(){
System::String *result;

//NEXT RETURNS CORRECT VALUE OF #0600
result=System:: String::Concat(

System::String: :Format("{0:x}" ,__box(ptrUnman agedClass->myUnion.b_myDa ta.bytes[0])),

System::String: :Format("{0:x}" ,__box(ptrUnman agedClass->myUnion.b_myDa ta.bytes[1])),

System::String: :Format("{0:x}" ,__box(ptrUnman agedClass->myUnion.b_myDa ta.bytes[2])),

System::String: :Format("{0:x}" ,__box(ptrUnman agedClass->myUnion.b_myDa ta.bytes[3])));

//NEXT RETURNS INCORRECT VALUE OF #73CB6A62
result=System:: String::Format( "{0:x}",__box(p trUnmanagedClas s->myUnion.myData .unmanagedLong) );

return(result);
}

Sep 12 '06 #2
Ray
Mike C# wrote:
However I'm not purposely requesting that the Runtime terminate in an
"unusual way." The line that is causing me headaches is:

wcscpy(data, MyCode.c_str()) ;
I'd suggest that you use wcscpy_s, which requires you to supply the
length of the destination string.
Where data and MyCode are defined as:

wchar_t data[256];
std::wstring AuthorCode;
My guess would be that your AuthorCode is longer than 256--I suggest you
step through your code, alternatively, cout the length of AuthorCode
just before you call wcscpy (again, wcscpy_s is a better alternative).
The strange thing is that the program appears to be running fine in Visual
Studio, but generates the error message whenever I try to run it from the
command line. Putting a try...catch block around the line in question
doesn't help - it doesn't catch the exception. I have no idea what's
causing this...
Yeah, wcscpy will just trample the end of the destination string over
without any exception. Try using wcscpy_s, and check for ERANGE (to find
out whether the size is too small for AuthorCode).

Cheers
Ray
Any ideas are appreciated!

Thanks!

Sep 13 '06 #3
Ray
Andy wrote:
wcscpy is a wide character function, and its second parameter expects a
wide character string to copy from. In your example, you are using
c_str which is not a wide character function - it returns a string of 8
bit chars.
But that c_str() belong to a wstring, so it returns a const wchar_t*

<snip>
Sep 13 '06 #4
I keep getting a strange error and can't pin it down. The message is:

This application has requested the Runtime to terminate it in an unusual
way.
Please contact the application's support team for more information.

However I'm not purposely requesting that the Runtime terminate in an
"unusual way." The line that is causing me headaches is:
...

The strange thing is that the program appears to be running fine in Visual
Studio, but generates the error message whenever I try to run it from the
command line. Putting a try...catch block around the line in question
doesn't help - it doesn't catch the exception. I have no idea what's
causing this...
First of all, verify that there is no heap corruption or obvious stack corruption
by compiling with /GS compiler option and testing under PageHeap,
as shown here:
http://www.debuginfo.com/tips/userbpntdll.html

If none of the above reveals the problem, attach the debugger to your
application at the moment when you see the message, and check the call stack.
Probably it will tell you where the problem is.

Regards,
Oleg
[VC++ MVP http://www.debuginfo.com/]


Sep 13 '06 #5
"Andy" <an****@infot ek-consulting.comw rote in message
news:11******** *************@e 3g2000cwe.googl egroups.com...
Just a guess for a starting point...

wcscpy is a wide character function, and its second parameter expects a
wide character string to copy from.
Thanks for taking a shot at it. The string is a std::wstring, so the
c_str() function is returning a const wchar_t * as far as I can tell. And
it does work when I run it in Visual Studio; it's just when I compile to an
exe and try to execute it from the command line that I get this error.

Thanks
Sep 13 '06 #6

"Ray" <ra********@yah oo.comwrote in message
news:e1******** ******@TK2MSFTN GP02.phx.gbl...
Mike C# wrote:
>However I'm not purposely requesting that the Runtime terminate in an
"unusual way." The line that is causing me headaches is:

wcscpy(data, MyCode.c_str()) ;

I'd suggest that you use wcscpy_s, which requires you to supply the length
of the destination string.
I'll consider that if I can figure out the cause of the error. A basic
copy, afaik, should work. Also I've tried wcsncpy which should effectively
limit the input as well, no?
>Where data and MyCode are defined as:

wchar_t data[256];
std::wstring AuthorCode;

My guess would be that your AuthorCode is longer than 256--I suggest you
step through your code, alternatively, cout the length of AuthorCode just
before you call wcscpy (again, wcscpy_s is a better alternative).
Hmmm. Your guess there would be wrong. The AuthorCode string is L"982091",
which is far less than 256 characters. Again, it works fine when run from
Visual Studio, but gives that error when compiled to an exe and run from the
command line. That leads me to believe that the problem isn't necessarily a
coding issue on my part. But I could be wrong there too.
>The strange thing is that the program appears to be running fine in
Visual Studio, but generates the error message whenever I try to run it
from the command line. Putting a try...catch block around the line in
question doesn't help - it doesn't catch the exception. I have no idea
what's causing this...

Yeah, wcscpy will just trample the end of the destination string over
without any exception. Try using wcscpy_s, and check for ERANGE (to find
out whether the size is too small for AuthorCode).
I'll try it, but I've already verified inside Visual Studio that the length
of the string is 6 and the actual string is L"982091", indicating that the
problem doesn't lie with the code. The fact that it runs perfectly fine in
Visual Studio, but unceremoniously craps out from the command line seems to
indicate an issue somewhere else. Maybe a DLL issue or something. Perhaps
VS is loading a newer version of some DLL, while the command-line version is
loading an older less-functional version or something. Unfortunately I'm
not sure how to nail that down.

Thanks again!
Sep 13 '06 #7

"Oleg Starodumov" <com-dot-debuginfo-at-olegwrote in message
news:Op******** ******@TK2MSFTN GP05.phx.gbl...
>
>I keep getting a strange error and can't pin it down. The message is:

This application has requested the Runtime to terminate it in an unusual
way.
Please contact the application's support team for more information.

However I'm not purposely requesting that the Runtime terminate in an
"unusual way." The line that is causing me headaches is:
...

The strange thing is that the program appears to be running fine in
Visual
Studio, but generates the error message whenever I try to run it from the
command line. Putting a try...catch block around the line in question
doesn't help - it doesn't catch the exception. I have no idea what's
causing this...

First of all, verify that there is no heap corruption or obvious stack
corruption
by compiling with /GS compiler option and testing under PageHeap,
as shown here:
http://www.debuginfo.com/tips/userbpntdll.html
Thanks, I'll give it a shot. The strange part is that it runs just fine in
Visual Studio IDE, but returns that error message when run from the command
line. Weird.
If none of the above reveals the problem, attach the debugger to your
application at the moment when you see the message, and check the call
stack.
Probably it will tell you where the problem is.

Regards,
Oleg
[VC++ MVP http://www.debuginfo.com/]


Sep 13 '06 #8

"Mike C#" <xy*@xyz.comwro te in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
>
"Ray" <ra********@yah oo.comwrote in message
news:e1******** ******@TK2MSFTN GP02.phx.gbl...
Mike C# wrote:
However I'm not purposely requesting that the Runtime terminate in an
"unusual way." The line that is causing me headaches is:

wcscpy(data, MyCode.c_str()) ;
I'd suggest that you use wcscpy_s, which requires you to supply the
length
of the destination string.

I'll consider that if I can figure out the cause of the error. A basic
copy, afaik, should work. Also I've tried wcsncpy which should
effectively
limit the input as well, no?
Where data and MyCode are defined as:

wchar_t data[256];
std::wstring AuthorCode;
My guess would be that your AuthorCode is longer than 256--I suggest you
step through your code, alternatively, cout the length of AuthorCode
just
before you call wcscpy (again, wcscpy_s is a better alternative).

Hmmm. Your guess there would be wrong. The AuthorCode string is
L"982091",
which is far less than 256 characters. Again, it works fine when run from
Visual Studio, but gives that error when compiled to an exe and run from
the
command line. That leads me to believe that the problem isn't necessarily
a
coding issue on my part. But I could be wrong there too.
The strange thing is that the program appears to be running fine in
Visual Studio, but generates the error message whenever I try to run it
from the command line. Putting a try...catch block around the line in
question doesn't help - it doesn't catch the exception. I have no idea
what's causing this...
Yeah, wcscpy will just trample the end of the destination string over
without any exception. Try using wcscpy_s, and check for ERANGE (to find
out whether the size is too small for AuthorCode).

I'll try it, but I've already verified inside Visual Studio that the
length
of the string is 6 and the actual string is L"982091", indicating that the
problem doesn't lie with the code. The fact that it runs perfectly fine
in
Visual Studio,
When running under the debugger your program ends up with the string as you
describe, but run from outside the debugger, a different codepath is taken,
which results in either a different string, or the wstring ends up not
initialized with any string.

Sep 13 '06 #9

"Code Jockey" <gi***@the.keyb oardwrote in message
news:ud******** ******@TK2MSFTN GP03.phx.gbl...
When running under the debugger your program ends up with the string as
you
describe, but run from outside the debugger, a different codepath is
taken,
which results in either a different string, or the wstring ends up not
initialized with any string.
I ran some more tests, which is all I can do considering I cannot reproduce
the problem under the debugger. There's no explicit differentiation between
my choice of code paths under the debugger versus outside the debugger. If
a different code path is taken, process of elimination says it has to be
inside the MS MFC and Windows libraries. And I'm not eager to delve into
those. Instead I'm re-writing code to avoid as many of these functions as I
can.

Thanks.
Sep 13 '06 #10

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

Similar topics

2
8932
by: Olaf | last post by:
I have a frameset page witch contains the myFuc() function. The function is accessed from a page in one of the frames in the frameset. An example is shown below. <input onclick="javaScript:alert('document.forms(0)='+document.forms(0)); parent.myFunc(document.forms(0));" type="button" value="Open" name="Button" ID="Button"> The strange part is that the debug alert says that the document.forms(0) is an object så all seem to be well. But...
25
3754
by: Neil Ginsberg | last post by:
I have a strange situation with my Access 2000 database. I have code in the database which has worked fine for years, and now all of a sudden doesn't work fine on one or two of my client's machines. The code opens MS Word through Automation and then opens a particular Word doc. It's still working fine on most machines; but on one or two of them, the user is getting an Automation Error. The code used is as follows: Dim objWord As...
0
328
by: Kris Vanherck | last post by:
yesterday i started getting this strange error when i try to run my asp.net project: Compiler Error Message: CS0006: Metadata file 'c:\winnt\microsoft.net\framework\v1.1.4322\temporary asp.net files\spsweb\0e3514bf\cb1844e7\assembly\dl2\3b163f 16\00452d31_84e5c301\infragistics.webui.ultrawebgrid.v3.dll' could not be found
6
1706
by: Gary | last post by:
I have an application that has been working just fine for a couple of years. It queries a SQL database and returns some formatted data back to the client. I have a new client, who has a larger database than any of our previous customers. For example, the query to build the datatable now takes about 2 minutes instead of one minute or less. This is a third party database we are integrating with. He is getting very strange results. For...
5
1743
by: Nathan Sokalski | last post by:
When I view my index.aspx page any time after the first time, I recieve the following error: System.Web.TraceContext.AddNewControl(String id, String parentId, String type, Int32 viewStateSize) +313 System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +201 System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +263
0
3576
by: ivb | last post by:
Hi all, I am using DB2 8.1.11.1 on NT with ASP.NET 1.1 When application make connection to database (via ADO.NET), it set "Connection timeout" parameter to 30 seconds. After, when my webpage requests database, and query execution time exceeds 30 seconds, the following error reported: ===
11
2602
by: Martin Joergensen | last post by:
Hi, I've encountered a really, *really*, REALLY strange error :-) I have a for-loop and after 8 runs I get strange results...... I mean: A really strange result.... I'm calculating temperatures. T = 20 degrees at all times.... The 2D T-array looks like this:
1
1562
by: JoReiners | last post by:
Hello, I have a really strange problem. I'm unable to figure it out on my own. I parse very simple xml documents, without any check for their form. These files look very similar and are encoded in UTF-8. Now minidom is always able to parse these files with minidom.parse("file") . Now when fetching I use this expression: xmldoc.getElementsByTagName('DocNumb').firstChild.data.encode('latin1')
3
1842
by: Shelly | last post by:
I am encountering two strange problems. First one: I get a "server misconfiguration error", but only sometimes. It occurs on the first screen that accesses the database on a submit. This error is intermittent -- sometimes it happens and sometimes not from the same screen with the same data. Here is the error:
0
9856
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10911
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10654
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9429
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7833
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7021
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4066
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3136
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.