473,397 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Urgent help on IXMLHTTPREQUEST

Hi,

Everything works fine with ixmlhttprequest. It gives me "access
violation" only when i am trying to release it from the memory (i.e
pXMLHttpReq->Release()).

Below is my code.
//////////////////////////////////////////////////////////////////////////
::CoInitialize(NULL);
// Variables.
bstr_t sUrl = "http://localhost/test.xml";
bstr_t sMethod = "GET";
_variant_t vUser = L"USERNAME";
_variant_t vPassword = L"PASSWORD";
_variant_t vAsync = (bool)FALSE;
long lStatus = 0;
BSTR bstrResp;
BSTR bstrResponseText;
HRESULT hr;

IXMLHTTPRequestPtr pXMLHttpReq= NULL;
hr=pXMLHttpReq.CreateInstance("Msxml2.XMLHTTP.4.0" );

if(hr != S_OK)
{

}
try
{
// Open the XMLHTTPRequest object with the DELETE method and
// specify that it will be sent asynchronously.
pXMLHttpReq->open(sMethod,
sUrl,
vAsync,
vUser,
vPassword);
pXMLHttpReq->send();

// Get the response status.
pXMLHttpReq->get_status(&lStatus);

// An error occurred on the server.
if(lStatus == 500)
{
}

else
{
// Display the response status.

// Display the response status text.
pXMLHttpReq->get_statusText(&bstrResp);

// Display the response text.
pXMLHttpReq->get_responseText(&bstrResponseText);
}

// Release the memory.
pXMLHttpReq->Release(); //THIS IS WHERE I GET ACCESS VIOLATION ERROR

}
catch(_com_error &e)
{
// Display the error information.

// Release the memory.
pXMLHttpReq->Release(); //THIS IS WHERE I GET ACCESS VIOLATION
ERROR

return 1;
}

CoUninitialize();
//////////////////////////////////////////////////////////////////////////

I have been trying to solve this for a long time but am not able to
find answer to it. Please help . I am using Ms Visual Studio 6.0 sp6.

Thanks for your help.
Agam Mehta
Nov 17 '05 #1
8 2776
"Agam Mehta" <ag*******@hotmail.com> wrote in message
news:ab**************************@posting.google.c om...
Everything works fine with ixmlhttprequest. It gives me "access
violation" only when i am trying to release it from the memory (i.e
pXMLHttpReq->Release()).


Almost everyone makes the error you made once.

COM's smart pointers see to it that Release() is called when an object goes
out of scope. The problem is that your object goes out of scope after the
return statement. But at that point COM has already been uninitialized and
the call to Release() does a bad thing. <g>

One thing that you can do is to change the location where the object goes
out of scope:

::CoInitialize(0);
{
// Insert your declarations and code here
}
::CoUninitialize();

Now your object will go out of scope at the right brace _before_
CoUnitialize() is called. The destructor of your object runs and Release()
gets called _before_ COM is uninitialized.

Regards,
Will


Nov 17 '05 #2
Thanks William for your suggestion. But now when i try it the way you
suggested i get "Breakpoint" error. i am trying really simple thing.

///////////////////////////////////////////////////////////////
HRESULT hresult;
hresult = ::CoInitialize(0);
if(hresult == S_OK)
{
IXMLHTTPRequestPtr pXMLHttpReq= NULL;
hresult=pXMLHttpReq.CreateInstance("Msxml2.XMLHTTP .4.0");

pXMLHttpReq->Release();
}
::CoUninitialize();
///////////////////////////////////////////////////////////////

Please help.
Thanks,
Agam Mehta

"William DePalo [MVP VC++]" <wi***********@mvps.org> wrote in message news:<ev**************@tk2msftngp13.phx.gbl>...
"Agam Mehta" <ag*******@hotmail.com> wrote in message
news:ab**************************@posting.google.c om...
Everything works fine with ixmlhttprequest. It gives me "access
violation" only when i am trying to release it from the memory (i.e
pXMLHttpReq->Release()).


Almost everyone makes the error you made once.

COM's smart pointers see to it that Release() is called when an object goes
out of scope. The problem is that your object goes out of scope after the
return statement. But at that point COM has already been uninitialized and
the call to Release() does a bad thing. <g>

One thing that you can do is to change the location where the object goes
out of scope:

::CoInitialize(0);
{
// Insert your declarations and code here
}
::CoUninitialize();

Now your object will go out of scope at the right brace _before_
CoUnitialize() is called. The destructor of your object runs and Release()
gets called _before_ COM is uninitialized.

Regards,
Will

Nov 17 '05 #3
"Agam Mehta" <ag*******@hotmail.com> wrote in message
news:ab**************************@posting.google.c om...
Thanks William for your suggestion.
You are welcome.
But now when i try it the way you suggested i get "Breakpoint" error.
Check the output window. The class designer may have put in a breakpoint to
signal a coding error. The breakpoints are often accompanied by a debug
message.
i am trying really simple thing.


Nothing about COM is simple. Ever. :-)

Regards,
Will
Nov 17 '05 #4
Hi William DePalo,

I checked my output window and it doesn't have any breakpoint in it.
This sucks. Please help.

Thanks,
Agam Mehta

"William DePalo [MVP VC++]" <wi***********@mvps.org> wrote in message news:<up**************@tk2msftngp13.phx.gbl>...
"Agam Mehta" <ag*******@hotmail.com> wrote in message
news:ab**************************@posting.google.c om...
Thanks William for your suggestion.


You are welcome.
But now when i try it the way you suggested i get "Breakpoint" error.


Check the output window. The class designer may have put in a breakpoint to
signal a coding error. The breakpoints are often accompanied by a debug
message.
i am trying really simple thing.


Nothing about COM is simple. Ever. :-)

Regards,
Will

Nov 17 '05 #5
"Agam Mehta" <ag*******@hotmail.com> wrote in message
news:ab**************************@posting.google.c om...
I checked my output window and it doesn't have any breakpoint in it.
Hmm, earlier you wrote:

"But now when i try it the way you suggested i get "Breakpoint" error."
This sucks.
Nope.

Developing software is a strange endeavor. It is _far_ too easy to do at
all. And _extraordinarily_ difficult to do well.

As I see it, that's the big problem. And it continues to get worse because
as tools get better they lower the bar to entry. The better tools and more
capable systems lead users to want more and developers to try to do more.
That serves to increase the complexity. So the tools have to get better.
They do. But then they hide more which adds to complexity. Which puts us
back on the carousel for another ride and we go around again and again ...

But I digress ... <BWG>
Please help.


I'll try. Are you running in debug mode? If not, do so. Do you get a
breakpoint error or not? If you do what else do you see in the output window
when the debug error is reported. It is hard to imagine that anyone would
insert a breakpoint error to signal an error and not add a diagnostic
message so you can troubleshoot the problem.

Regards,
Will
Nov 17 '05 #6
William,

Thanks for your response. Let me tell you i am using console
application with no MFC support. I guess this souldn't matter. Yes i
am running this application in debug mode. When i call "Release()" it
shows "Breakpoint message box" and displays "Extra call to Release()
!!!" is showed in my output window.

I have no idea why it even does this.

thank you very much for your help.

Agam Mehta

"William DePalo [MVP VC++]" <wi***********@mvps.org> wrote in message news:<OB**************@TK2MSFTNGP11.phx.gbl>...
"Agam Mehta" <ag*******@hotmail.com> wrote in message
news:ab**************************@posting.google.c om...
I checked my output window and it doesn't have any breakpoint in it.


Hmm, earlier you wrote:

"But now when i try it the way you suggested i get "Breakpoint" error."
This sucks.


Nope.

Developing software is a strange endeavor. It is _far_ too easy to do at
all. And _extraordinarily_ difficult to do well.

As I see it, that's the big problem. And it continues to get worse because
as tools get better they lower the bar to entry. The better tools and more
capable systems lead users to want more and developers to try to do more.
That serves to increase the complexity. So the tools have to get better.
They do. But then they hide more which adds to complexity. Which puts us
back on the carousel for another ride and we go around again and again ...

But I digress ... <BWG>
Please help.


I'll try. Are you running in debug mode? If not, do so. Do you get a
breakpoint error or not? If you do what else do you see in the output window
when the debug error is reported. It is hard to imagine that anyone would
insert a breakpoint error to signal an error and not add a diagnostic
message so you can troubleshoot the problem.

Regards,
Will

Nov 17 '05 #7
"Agam Mehta" <ag*******@hotmail.com> wrote in message
news:ab**************************@posting.google.c om...
Thanks for your response.
You are welcome.
Let me tell you i am using console
application with no MFC support.
OK.
I guess this souldn't matter.
That's right.
Yes i am running this application in debug mode.
Good start.
When i call "Release()" it shows "Breakpoint message box"
and displays "Extra call to Release()
!!!" is showed in my output window.

I have no idea why it even does this.


OK. You need to check a good text on the Component Object Model - COM. COM
objects are reference counted. That is to say that there are methods named
Add() and Release() in an interface which are used to increment the count of
clients that hold references to an object. When the reference count goes to
0 no client is holding a reference and the object may be deallocated. The
diagnostic is telling you that there is one EXTRA call to Release() in yout
application which would have set the reference count to -1. That's what you
have to fix.

Regards,
Will
Nov 17 '05 #8
> ///////////////////////////////////////////////////////////////
HRESULT hresult;
hresult = ::CoInitialize(0);
if(hresult == S_OK)
{
IXMLHTTPRequestPtr pXMLHttpReq= NULL;
hresult=pXMLHttpReq.CreateInstance("Msxml2.XMLHTTP .4.0");

pXMLHttpReq->Release();
}
::CoUninitialize();
///////////////////////////////////////////////////////////////


IXMLHTTPRequestPtr is a smart pointer and it releases COM object by itself
when it goes out of scope. Don't call pXMLHttpReq->Release() yourself.
--
Vladimir Nesterovsky
e-mail: vl*******@multiconn.com
Nov 17 '05 #9

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

Similar topics

3
by: Rob | last post by:
I have a form - when you click the submit button, it appends a variable to the URL (e.g. xyz.cgi?inputID=some_dynamic_variable) It also opens a new page. Now, that some_dynamic_variable is...
9
by: Stefan Bauer | last post by:
Hi NG, we've got a very urgent problem... :( We are importing data with the LOAD utility. The input DATE field data is in the format DDMMYYYY (for days) and MMYYYY (for months). The target...
28
by: Tamir Khason | last post by:
Follwing the struct: public struct TpSomeMsgRep { public uint SomeId;
16
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In:...
0
by: Joseph | last post by:
I have been using "XMLHTTPClass" in an asp.net module. It is properly referenced and was working up until recently. Now it is failing with the error message "QueryInterface for interface...
3
by: N. Spiker | last post by:
I am attempting to receive a single TCP packet with some text ending with carriage return and line feed characters. When the text is send and the packet has the urgent flag set, the text read from...
7
by: Cirene | last post by:
I used to use the Web Deployment Project with my VS2005 projects. Now I've fully upgraded to VS2008. Do I have to download a new version of the Web Deployment Project? If so where can I find...
2
by: bhushanbsc | last post by:
Hi, I am working on a project related to windows pocket pc 5.0 (win32). in that i am trying client-server communicationusing SOAP server. but facing problem on...
1
by: AlirezaShokoienia | last post by:
Hi all, I have developed an C++ application with Visual Studio 2005 and in them i want save some files in a remote server using IXMLHTTPRequest component. usually before save the file, i read the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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,...
0
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...

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.