Kvschaganti

I am using the XMLHTTPObject in javascript, it need to invoke an ActiveX object.
The ActiveX Object is written in VC++ 6.0.

VC++ function looks like this.
=========================
long CMYComponent::saveToFile(LPCTSTR aFileName, LPCTSTR aData, short aNewFile)
{
// TODO: Add your dispatch handler code here
writeToFile((char *)aFileName , (char *)aData, aNewFile);
return 0;
}
==========================JAVASCript code===
saveToFile(fileName, xmlHTTP.responseText,1);
=================================

if the data type in the reposne is ascii it works fine. if the data type is binary it fails.
Really I want to send
xmlHTTP.responseBody to the C++ function above, what is the best data type I should use
in C++ function so that I can make it work for the data coversion between the javascript and VC++.

Any help, example would work.
In the new versions of the compiler it looks like BYTE type is there. but due to client limitations I can not use the .Net version of the C++ compilers.

Regards
Krishna



Re: Visual C++ Language Data Type conversion between JavaScript and C++

Simple Samples

If I understand the problem, then it is easily understood with a basic understanding of C++ and you will certainly benefit from a tutorial or book about C++.

I don't know what the writeToFile function does but I don't see a size specified for the data. Therefore the writeToFile function probably determines the size of the data by looking for a null (zero). This is basic to the way that C/C++ works. Binary data is likely to contain nulls.

The saveToFile function must be able to determine the size of the data; for binary data, there must be a size parameter somewhere somehow. Then it must also use a function that also specifies the size, unlike writeToFile.

Also, the BYTE type is old, not new. It is also char, but it is unsigned char.






Re: Visual C++ Language Data Type conversion between JavaScript and C++

Marius Bancila

If you intend to write anything else than ASCII or UNICODE characters, you have to modify the signature of the function, so that you can pass anything. aData should be a const unsigned char (const so that it does not get modified) and you should also specify the length of the buffer. Now, this aData is just a buffer of bytes, it can hold anything. It depends on your function how it interpret that data.

long CMYComponent::saveToFile(LPCTSTR aFileName, const unsigned char* aData, size_t length, short aNewFile)






Re: Visual C++ Language Data Type conversion between JavaScript and C++

Kvschaganti

Thanks for the reply. you are correct about BYTE type.
Because this is between javascript and C++, I can not use 'unsigned char' as one of the type.
unsigned char is not one of the COM automation type.

Regards
Krishna





Re: Visual C++ Language Data Type conversion between JavaScript and C++

Marius Bancila

That is not a problem. unsigned or not, it's still 8 bits.




Re: Visual C++ Language Data Type conversion between JavaScript and C++

Kvschaganti

Thanks for the reply.
I found the solution.
javascrpt XMLHTTPRequest.responseBody is saved as BLOB, so I used VARIANT data type which solved the problem I am having.

Thanks for all the replies.

--Krishna