15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Dao returns char* when it should be a BSTR, why?

Noel Burton-Krahn -- noel@harleystreet.com
Friday, November 15, 1996

Environment: MSVC 4.0 / Win95

CDaoRecordset::GetFiledValue() fills in a COLEVariant which it *says* is a 
BSTR, but really it's just a char*.  How can I force this char* into a BSTR 
when VARIANTs don't seem to know anything about char*'s?

CDaoDatabase db;

db.Open("mydb.mdb");

CDaoRecordset rec(&db);
COLEVariant v;

rec.Open(dbSnapshot, "select * from Person");
rec.GetFieldValue("LastName", v);
// PROBLEM: v.vt == VT_BSTR, but v.bstrVal is a char*.  Lies, all lies!


TIH
--Noel







Dan Kirby -- dkirby@accessone.com
Sunday, November 17, 1996

Take a look at article  Q140599  in the Microsoft Developer Knowledgebase
for some insights. Basically DAO works with ANSI BSTRs in ANSI builds.

You can use the SysAllocString to convert to from a char * to a BSTR.

--dan

----------
> From: Noel Burton-Krahn 
> To: 'mfc' 
> Subject: Dao returns char* when it should be a BSTR, why?
> Date: Friday, November 15, 1996 9:27 AM
> 
> Environment: MSVC 4.0 / Win95
> 
> CDaoRecordset::GetFiledValue() fills in a COLEVariant which it *says* is
a 
> BSTR, but really it's just a char*.  How can I force this char* into a
BSTR 
> when VARIANTs don't seem to know anything about char*'s?
> 
> CDaoDatabase db;
> 
> db.Open("mydb.mdb");
> 
> CDaoRecordset rec(&db);
> COLEVariant v;
> 
> rec.Open(dbSnapshot, "select * from Person");
> rec.GetFieldValue("LastName", v);
> // PROBLEM: v.vt == VT_BSTR, but v.bstrVal is a char*.  Lies, all lies!
> 
> 
> TIH
> --Noel
> 
> 
> 
> 




| Вернуться в корень Архива |