Re: passing parameters
Eric Kaplan wrote:
why calling PostSoapRequest will crash the program?
"crash" is an interpretation, but it would actually help you get better help
if you didn't interpret but told us what you did, what happened and what
you expected instead.
int post_soap_request(string start, string end)
{
string request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ start + end;
const char* REQUEST_BODY = request.c_str();
Note: you get a pointer to a buffer here which remains valid as long as
the 'request' object remains unchanged. Further, it is horrible style to
use an ALL_UPPERCASE name for a local variable. Reserve those to macros.
ne_set_request_body_buffer(req, REQUEST_BODY,
strlen(REQUEST_BODY));
If this function only attaches the given pointer to 'req' but doesn't make a
copy, you must make sure that it is not used after 'request' above went out
of scope. BTW: instead of counting the number of characters in the string,
you could have simply used the std::string's length:
ne_set_request_body_buffer( req, request.c_str(), request.size());
HRESULT PostSoapRequest(string start, string end) {
return (post_soap_request(start, end) == 0) ? S_OK : E_FAIL;
}
Just a suggestion which will probably be rather invasive at the moment but
come handy in the long run: use exceptions. Since composing or copying
strings already does that to signal errors, you need to be able to handle
them anyway, and it then allows you to concentrate error handling to one
place instead of always checking, converting and forwarding returnvalues.
Uli
--
C++ FAQ: http://parashift.com/c++-faq-lite
Sator Laser GmbH
Gesch??ftsf??hrer: Michael W??hrmann, Amtsgericht Hamburg HR B62 932