C++ understanding LPCOLESTR and how to manipulate data good tutorial on this subject

I am trying to substatute line 2 for line 1 so that i can pass it a sql statement but and also need a good resurse that i can read up on this subject been searching the net for hours and have not come across any good tutorials
any help would be appreciated


there are lines missing but these are the ones that i am trying to operate on

#include	"StdAfx.h"
#include  <atldbcli.h>
#include <iostream>
#include <string>


int _tmain()
{

   char arrayd[1][4] ;
   char querySQL = "LSELECT * from bothtaables;";
LPCOLESTR lpcOleConnect = L"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\c++ tree view\\new files\\DB\\TreeView.mdb;User Id=admin;;Password=;";

// PLACE IN HERE THE CODE FOR THE SQL REQUIRED
//this line works
1)  LPCOLESTR query = L"SELECT * from bothtaables;";
// BUT I WANT TO CHANGE IT TO THE BELOW SO I CAN JUST SEND OR CHANGE THE SQL STRING AS I WANT IT
2)  LPCOLESTR query = LquerySQL;


}

Open in new window

sydneyguyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Karrtik IyerSoftware ArchitectCommented:
OLECHAR is the same as WCHAR if preprocessor macro OLE2ANSI is undefined (most cases under win32). Otherwise, it is CHAR if OLE2ANSI defined (win16).
converting a char* to LPCOLESTR is simple:

USES_CONVERSION;
LPCOLESTR lpo = A2COLE(lpa);

Since you are working with visual studio and windows, I suggest you use CString instead of char*, which makes it simple and easy to convert between these types.

Refer the section 2.1 in the below tutorial for more information on different string types and what they mean.
http://progtutorials.tripod.com/COM.htm
Also I find explanation in below article good.

http://www.codeproject.com/Articles/3004/The-Complete-Guide-to-C-Strings-Part-II-String-Wra
0
Karrtik IyerSoftware ArchitectCommented:
An even simpler option to work with OLE strings (LPCOLESTR) is to use CCOMBSTR, since OLE technology was later enhanced to COM, CCOMBSTR has a constructor that directly takes LPCOLESTR. Also CCOMBSTR takes care of freeing up the memory and the developer need not worry about calling delete explicitly.
And once you convert it to CCOMBSTR you can convert it to wchar_t and other types very conveniently.
Please note that you will have to include atlbase.h header file to use CCOMBSTR.
#include<atlbase.h>
	LPCOLESTR lpcOleConnect = L"Test String";
	CComBSTR objteststring(lpcOleConnect);
	std::wstring wstest = objteststring.m_str ;
	const wchar_t* wctest = wstest.c_str();
        std::wcout<< L"Hello World: " << wctest << std::endl;

Open in new window

To learn more about CCOMBSTR you can refer the below MSDN link:
https://msdn.microsoft.com/en-us/library/zh7x9w3f%28v=vs.90%29.aspx
0
sarabandeCommented:
to add to above comment:

you could use LPCWSTR instead of the LPCOLESTR. both resolve to 'const wchar_t *' what perhaps is the best alternative if you don't want to fight in the struggle of api macros of a long-term history.

note, LPCTSTR which is based on TCHAR is not a good choice, since it could be either 'const wchar_t *' or 'const char *' depending on the UNICODE macro being defined.

LPCOLESTR is always wide characters (if we ignore old 16-bit windows as explained by Karrtik). so you need to define L prefix when using literals. if you use a string class you could take std::wstring and use std::wstring::c_str() to extract a const wchar_t *:

std::wstring strw = L"whatever";
strw += L" is appropriate";

LPCOLESTR pwstr = strw.c_str();

Open in new window


an alternative string class is _bstr_t which can switch between ansi and utf-16 and therefore has functions to convert into both directions.

Sara
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sydneyguyAuthor Commented:
thanks for all your help you are all so versed in this language. hope fully one day  i too will have this knowledge
thanks again for all  your help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.