Click to See Complete Forum and Search --> : Problem with ATL object returning LPVARIANT


ssimbas
February 23rd, 2000, 04:52 PM
Hi all,
I have a COM object written using ATL and VC++. One of the methods of the dll is GetData which gives back an LPVARIANT to the client. I either give a IDISPATCH or BSTR thru the VARIANT object.

I have this VB client that uses the COM object. If i declare a long variable in my VB client, and call this method, (and if this method gives back a numeric value in the bstrVal member of the VARIANT structure), VB applies the appropriate conversion function and gets the value properly into the variable.

But, if i declare a string variable, (and in the COM object i give back alphanumeric value), and i am running the app within the VB IDE, i see garbage data in the variable [which i am printing thru a message box]. Sometimes i see "????...", or "<variable name>=..", or complete path of a filename from my system, and so on. This happens only when i run the app from VB IDE. If i make an EXE and run it outside the IDE, i could see the proper value most of the time.

I tried to debug the COM DLL in VC++ using the VB exe, and i am putting the proper value in the bstrVal member, and i am seeing the value in quickwatch. But somehow the data is getting garbled when it reaches VB. I do not have symbols for the OLE & COM dlls, and so i cannot step beyond the DLL to see the value as it gets passed back to VB. I cannot also debug into the OLE dlls from VB, so i am rather stuck with this problem.

PS: My DLL object is built in MBCS, and since VB is entirely Unicode, i am doing a MultiBytetoWideChar() before copying the char* into the BSTR in VC++.

Has anyone faced similar kinda problem before ? Please help me 'coz i am in dire straits.

Thanxz in advance.