Need help--> BSTR in ATL
-
Hi, I am a newbie in ATL and have a question that hope you can answer it. The question is that I am trying to convert a BSTR type variable into a LPCTSTR type. I used the _com_util to do it but when i compiled the program, errors appear. I created the ATL project using the ATL wizard and the error message i received was -------------------------------------------------------------------------- The original source code: STDMETHODIMP CIniLoader::GetPrivateProfileString(BSTR bsSection, BSTR bsEntry, BSTR *bsOutput) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) LPCTSTR lpSection = _com_util::ConvertBSTRToString(bsSection); return S_OK; } The Error message {C:\temp\Project\PlatformManager\IniLoader.cpp(45) : error C2653: '_com_util' : is not a class or namespace name C:\temp\Project\PlatformManager\IniLoader.cpp(45) : error C2065: 'ConvertBSTRToString' : undeclared identifier} ---------------------------------------------------------------------- I tried to include the header file 'comutil.h' into the project and added an extra line 'using namespace _com_util' into the implementation but another different errors appeared. -------------------------------------------------------------------------- Creating library Debug/PlatformManager.lib and object Debug/PlatformManager.exp IniLoader.obj : error LNK2001: unresolved external symbol "char * __stdcall _com_util::ConvertBSTRToString(unsigned short *)" (?ConvertBSTRToString@_com_util@@YGPADPAG@Z) Debug/PlatformManager.dll : fatal error LNK1120: 1 unresolved externals Error executing link.exe. I have no idea which portion of the code went wrong...please help... thanks in advance. leonwoo
-
Hi, I am a newbie in ATL and have a question that hope you can answer it. The question is that I am trying to convert a BSTR type variable into a LPCTSTR type. I used the _com_util to do it but when i compiled the program, errors appear. I created the ATL project using the ATL wizard and the error message i received was -------------------------------------------------------------------------- The original source code: STDMETHODIMP CIniLoader::GetPrivateProfileString(BSTR bsSection, BSTR bsEntry, BSTR *bsOutput) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) LPCTSTR lpSection = _com_util::ConvertBSTRToString(bsSection); return S_OK; } The Error message {C:\temp\Project\PlatformManager\IniLoader.cpp(45) : error C2653: '_com_util' : is not a class or namespace name C:\temp\Project\PlatformManager\IniLoader.cpp(45) : error C2065: 'ConvertBSTRToString' : undeclared identifier} ---------------------------------------------------------------------- I tried to include the header file 'comutil.h' into the project and added an extra line 'using namespace _com_util' into the implementation but another different errors appeared. -------------------------------------------------------------------------- Creating library Debug/PlatformManager.lib and object Debug/PlatformManager.exp IniLoader.obj : error LNK2001: unresolved external symbol "char * __stdcall _com_util::ConvertBSTRToString(unsigned short *)" (?ConvertBSTRToString@_com_util@@YGPADPAG@Z) Debug/PlatformManager.dll : fatal error LNK1120: 1 unresolved externals Error executing link.exe. I have no idea which portion of the code went wrong...please help... thanks in advance. leonwoo
leonwoo wrote: IniLoader.obj : error LNK2001: unresolved external symbol "char * __stdcall _com_util::ConvertBSTRToString(unsigned short *)" (?ConvertBSTRToString@_com_util@@YGPADPAG@Z) Are you possibly passing it the string literal where it may need a pointer to it? :confused: Have you looked at this MSDN page[^] Nick Parker
**The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown
**
-
Hi, I am a newbie in ATL and have a question that hope you can answer it. The question is that I am trying to convert a BSTR type variable into a LPCTSTR type. I used the _com_util to do it but when i compiled the program, errors appear. I created the ATL project using the ATL wizard and the error message i received was -------------------------------------------------------------------------- The original source code: STDMETHODIMP CIniLoader::GetPrivateProfileString(BSTR bsSection, BSTR bsEntry, BSTR *bsOutput) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) LPCTSTR lpSection = _com_util::ConvertBSTRToString(bsSection); return S_OK; } The Error message {C:\temp\Project\PlatformManager\IniLoader.cpp(45) : error C2653: '_com_util' : is not a class or namespace name C:\temp\Project\PlatformManager\IniLoader.cpp(45) : error C2065: 'ConvertBSTRToString' : undeclared identifier} ---------------------------------------------------------------------- I tried to include the header file 'comutil.h' into the project and added an extra line 'using namespace _com_util' into the implementation but another different errors appeared. -------------------------------------------------------------------------- Creating library Debug/PlatformManager.lib and object Debug/PlatformManager.exp IniLoader.obj : error LNK2001: unresolved external symbol "char * __stdcall _com_util::ConvertBSTRToString(unsigned short *)" (?ConvertBSTRToString@_com_util@@YGPADPAG@Z) Debug/PlatformManager.dll : fatal error LNK1120: 1 unresolved externals Error executing link.exe. I have no idea which portion of the code went wrong...please help... thanks in advance. leonwoo
The quickest way is to use a _bstr_t, which provides the character set conversion:
BSTR bs1 = ...; // this is filled in already
_bstr_t bs2 ( bs1, true ); // bs2 has a copy of the string now
LPCTSTR psz = (LPCTSTR) bs2; // invoke _bstr_t conversion function--Mike-- Just released - 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm
-
The quickest way is to use a _bstr_t, which provides the character set conversion:
BSTR bs1 = ...; // this is filled in already
_bstr_t bs2 ( bs1, true ); // bs2 has a copy of the string now
LPCTSTR psz = (LPCTSTR) bs2; // invoke _bstr_t conversion function--Mike-- Just released - 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm
Michael Dunn wrote: The quickest way is to use a _bstr_t, which provides the character set conversion: Ok Mike, maybe you can clear this up for me, maybe (please): What is the purpose (for example) of having all these different types/names for string like data types? After reviewing the MSDN article[^] here I see things like,
LPCSTR
,LPCTSTR
,LPCWSTR
,LPTSTR
,LPWSTR
,PCSTR
,PCTSTR
, etc.... I think you get the point. I understand these are names, but why in the hell are there so many, they seem to be so closely related to each other. Nick Parker
**The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown
**
-
Michael Dunn wrote: The quickest way is to use a _bstr_t, which provides the character set conversion: Ok Mike, maybe you can clear this up for me, maybe (please): What is the purpose (for example) of having all these different types/names for string like data types? After reviewing the MSDN article[^] here I see things like,
LPCSTR
,LPCTSTR
,LPCWSTR
,LPTSTR
,LPWSTR
,PCSTR
,PCTSTR
, etc.... I think you get the point. I understand these are names, but why in the hell are there so many, they seem to be so closely related to each other. Nick Parker
**The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown
**
The LP and P prefixes mean the same thing these days. The difference is a leftover from the days when there were near and far pointers (L = long, indicating a far pointer). I just posted an article about strings[^], and I have part 2 almost done which covers the various wrapper classes and how to convert among them. :) --Mike-- Just released - 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm
-
The LP and P prefixes mean the same thing these days. The difference is a leftover from the days when there were near and far pointers (L = long, indicating a far pointer). I just posted an article about strings[^], and I have part 2 almost done which covers the various wrapper classes and how to convert among them. :) --Mike-- Just released - 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm
Michael Dunn wrote: I just posted an article about strings[^], and I have part 2 almost done which covers the various wrapper classes and how to convert among them. Thanks Mike, that's exactly what I was looking for, C++ keeps becoming more and more inviting every day. :) Nick Parker
**The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown
**
-
The LP and P prefixes mean the same thing these days. The difference is a leftover from the days when there were near and far pointers (L = long, indicating a far pointer). I just posted an article about strings[^], and I have part 2 almost done which covers the various wrapper classes and how to convert among them. :) --Mike-- Just released - 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm
-
leonwoo wrote: IniLoader.obj : error LNK2001: unresolved external symbol "char * __stdcall _com_util::ConvertBSTRToString(unsigned short *)" (?ConvertBSTRToString@_com_util@@YGPADPAG@Z) Are you possibly passing it the string literal where it may need a pointer to it? :confused: Have you looked at this MSDN page[^] Nick Parker
**The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown
**
-
thanks for the link Nick. I have doubt in what this line is doing. Can you explain it. thanks. #pragma comment(lib, "comsupp.lib") leonwoo
leonwoo wrote: I have doubt in what this line is doing. Can you explain it. It is telling the compiler to search the comsupp.lib while linking. :) Nick Parker
**The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown
**