Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am writing a class to simplify database query on sql server ce the code I am rewring to suite my purpose is located here


http://msdn.microsoft.com/en-us/library/windows/desktop/ms675047(v=vs.85).aspx

Can the void pointer returned by SafeArrayGetElement function be casted into a C++ type?


If not can it be casted into an sql datatype?
Posted

1 solution

See the _variant_t[^] class and the extractor functions. When the requested type is not identical to the type stored in the variant, the class tries to perform a conversion. Use the vt member of the encapsulated VARIANT type to determine which type is stored.
 
Share this answer
 
Comments
Gbenbam 7-Feb-14 10:51am    
Thanks I really appreciate it.What I gather is that I first have to save o
into a vatiant and cast into any data type I want.But for null terminated string I need to cast to a bstr fitst before casting to char string.
Jochen Arndt 7-Feb-14 11:05am    
There is no need to cast:
- The variant type covers all types that may occur in your database
- Access the variable using extractor functions or the VARIANT member that matches the type
- With _bstr_t, use the wchar_t* operator to access the string (note that it is an operator and not a casting)
- Alternatively copy the variant to a CString which suppports them for constructor and assignment
Gbenbam 8-Feb-14 3:12am    
I am sorry to border you again on this question.How does one use these accessor functions.My understanding of opetator is limeted to overloading of operators like = + - * % etc.I have always believed that. operators are autimatically invoked when expression involving them are executed.

Could you show me perhaps a one line of code that illustrate how. they are used.
Or is it that I just assign each to the other to initiate. the associated operator.
Gbenbam 8-Feb-14 10:46am    
Thanks man I finally get it.All I need do is assigned to the equivalent data type and th appropriate operator is invoked.
For bstr I assign to a wchar_t * type and the appropriate operator is called.

Thanks a million times.
Jochen Arndt 9-Feb-14 4:53am    
Fine that you got it and my answer helped you.
Sorry for the late reply, but I was busy yesterday.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900