I have a LPWSTR with a value and I want to convert it to char* or string.
Is there a simple function to do this?
Printable View
I have a LPWSTR with a value and I want to convert it to char* or string.
Is there a simple function to do this?
LPWSTR is actually wchar_t* (or the equivalent of).
You can use this raw under 2000 (it's a Unicode string), but for 98 you need to convert it. Search the forum for WideCharToMultiByte and you should be sorted :)
Ok, I am in 2000, so how do I do this?Quote:
Originally posted by parksie
You can use this raw under 2000
What are you using? Is it a console app?
I think you can just output it to wcout in the usual manner. It's hazy trying to use both in one program, though - either convert everything to Unicode, or everything to the multibyte set (the normal char* stuff...yes I know it's called multibyte but for most characters 1 byte will suffice).
It is in console for now.
To be honest with you, I am in a bit of a mess. I am trying to enumerate the Protected Storage in W2K like here http://www.codeproject.com/w2k/pseenuma.asp
Here is the code I have so far.
... and you see what happens. :eek:Code:
#include <windows.h>
#include <iostream>
using namespace std;
// import type library.
#import <pstorec.dll> no_namespace
// function pointer
typedef HRESULT (WINAPI *PStoreCreateInstancePtr)(IPStore **, DWORD, DWORD, DWORD);
void main(){
CoInitialize(NULL);
HMODULE hPstoreDLL;
hPstoreDLL = LoadLibrary("pstorec.dll");
PStoreCreateInstancePtr PStoreCreateInstance;
PStoreCreateInstance =
(PStoreCreateInstancePtr)GetProcAddress(hPstoreDLL, "PStoreCreateInstance");
IPStorePtr spPStore;
HRESULT hRes;
hRes = PStoreCreateInstance(&spPStore, 0, 0, 0);
IEnumPStoreTypesPtr spEnumTypes;
hRes = spPStore->EnumTypes(0, 0, &spEnumTypes);
GUID typeGUID;
unsigned long ul1;
for(int i = 0; i < 5; i++) // Internet Explorer Type
hRes = spEnumTypes->Next(1, &typeGUID, &ul1);
IEnumPStoreTypesPtr spEnumSubTypes;
GUID subtypeGUID;
hRes = spPStore->EnumSubtypes(0, &typeGUID, 0, &spEnumSubTypes);
hRes = spEnumSubTypes->Next(0, &subtypeGUID, &ul1); // Internet Explorer Subtype
IEnumPStoreItemsPtr spEnumItems;
hRes = spPStore->EnumItems(0, &typeGUID, &subtypeGUID, 0, &spEnumItems);
LPWSTR lpwstr;
hRes = spEnumItems->Next(0, &lpwstr, &ul1);
wcout << lpwstr << endl;
CoUninitialize();
}
PS - Anybody that knows win2K Protected Storage, feel free to jump in.
Shouldn't that just be "lpwstr" not "&lpwstr"?Code:hRes = spEnumItems->Next(0, &lpwstr, &ul1);
Well, one would think it should be. The parameter is actually
LPWSTR* rgelt
go figure.