> You receive a unicode string.
>
[quoted text clipped - 11 lines]
>
> Ismail Pazarbasi
Hello Roberto,
I have seen some problems with that code. I guess, Visual Studio
generated proxy classes for your web service. These are generated with
ATL. So, in that case, your service name, say MyService, has a class
named CMyService. I did not understand how you called that HelloWorld
function. You need to do something like following:
#include "stdafx.h" // i think you have a precompiled header
// #include <atlbase.h> // uncomment, if you don't have these files in
your precompiled header
// #include <atlconv.h>
#include "Myservice.h"
int main()
{
USES_CONVERSION;
CoInitialize(NULL);
HRESULT hr;
CMyService svc;
CComBSTR bsHello; // if you use this, it will free the memory
allocated by the service
hr = svc.HelloWorld(&bsHello);
if (hr)
{
printf("We've a problem: %08x", hr);
return 1;
}
printf(W2A(bsHello));
CoUninitialize();
}
sizeof(BSTR*) is wrong. This returns 4. However, empty BSTR's size is
at least 6 bytes. BSTR starts with a DWORD that represents the size of
the string at the beginning, which is 4 bytes. 2 bytes for each
character in the string, two bytes for terminating null characters. On
the other hand, normally malloc is not used for BSTR allocation. You
can use SysAllocString, SysAllocStringByteLen or SysAllocStringLen
functions. These functions does a similar job with malloc (use
HeapAlloc, as far as I know - like malloc), however SysXXXX functions
can construct a well-formed BSTR. Also, there is no free - that leaks.
If you use CComBSTR for BSTR, you don't need to call SysFreeString -
its destructor automatically does it. If you use BSTR, the function
that receives BSTR* allocates some memory, and you need to explicitly
call SysFreeString or you leak that.
VectorFromBstr constructs a SAFEARRAY of chars. You need to retrieve
these chars from within the SAFEARRAY, that's too much of work. ATL's
conversion macros (A2W, W2A and their cousins) use MultiByteToWideChar
and WideCharToMultibyte Windows unicode character set functions. These
are directly dealing with your case.
Please also note that the computer that you will use this DLL should
have at least Internet Explorer 6.0. Because generated proxy classes
use SAX XML Reader object that comes with IE6 (with MSXML2 actually).
Ismail Pazarbasi
Roberto Perez - 31 Mar 2005 23:47 GMT
Hello Ismail:
I’ve changed my C++ function as you suggested and words much better but I
found another problem(?).
Doing a real test accessing the database, I discovered that the max string
length is 55 (starting in 1 or 54 stating in 0), do you know the answer? Let
me tell you that I'm not passing parameters yet, the web services goes to the
database and read a specific string-column which is returned.
If you wish, reply me directly at roberto.perez@ky.gov
Thanks.