LPCTSTR stringy;
stringy = "cheese";
std::ifstream mapData;
mapData.open("normalMaps.txt");
std::string currentLine;
std::getline(mapData, currentLine);
pGameObj->statusStr = currentLine.c_str();
mapData.close();
LPCTSTR stringy;
stringy = "cheese";
std::ifstream mapData;
mapData.open("normalMaps.txt");
std::string currentLine;
std::getline(mapData, currentLine);
pGameObj->statusStr = currentLine.c_str();
mapData.close();
char* GetAppName(){ return "My Awesome Application";}char* szName = GetAppName();strcat(szName, " or something");
Quote:Original post by Viperrr
Hi all,
I am working with DirectX in Cplusplus. Alot of DirectX fuctions require a LPCTSTR parameter. I have been using LPCTSTR's for a while now, but I don't really understand how they work.
I believe LPCTSTR = Long Pointer Const T STRing.
What is the difference between a string and a const string?
If 'const' means it cannot be changed, then what use would it ever be? I need some basic understanding here please.
Also, what if I did this:
*** Source Snippet Removed ***
Logic tells me that should not work because:
'stringy' is a pointer, meaning it holds a memory adress, not a string.
Yet miraculously, it DOES work :S WHY?
I assume the reason DirectX works with pointers to strings, is because it is more efficient to pass around memory adresses, then to move the actual strings around. Is this a correct assumption?
The reason I ask all this now is I can't get this to work:
*** Source Snippet Removed ***
pGameObj->statusStr is a LPCTSTR which I display on the screen, as a debugger.
error C2440: '=' : cannot convert from 'const char *' to 'LPCTSTR'
Basically I want to stop messing around and actually know what I am doing.
Quote:
I believe LPCTSTR = Long Pointer Const T STRing.
What is the difference between a string and a const string?
If 'const' means it cannot be changed, then what use would it ever be? I need some basic understanding here please.
Also, what if I did this:
LPCTSTR stringy;
stringy = "cheese";
Logic tells me that should not work because:
'stringy' is a pointer, meaning it holds a memory adress, not a string.
Yet miraculously, it DOES work :S WHY?
#include <windows.h>int main(){ LPCTSTR str; const char *c = "cheese"; str = c; return 0;}
[source lang=cpp]std::wifstream mapData; mapData.open("normalMap.txt");std::wstring currentLine;std::getline(mapData, currentLine);pGameObj->statusStr = currentLine.c_str();mapData.close();
[source lang=cpp]stdFont->DrawTextW(NULL, text, -1, &rectangle, DT_LEFT, D3DCOLOR_XRGB(255, 255, 255));
Quote:Original post by ViperrrOnly if your app is building in Unicode mode.
- _T("cheese") = L"cheese" , correct?
Quote:Original post by ViperrrCorrect.
- "cheese" is ANSI, L"cheese" is Unicode , correct?
Quote:Original post by ViperrrFor static strings known at compile time, yes. You can think of the _T() macro as just prefixing an L to the string in unicode builds, and doing nothing in multi-byte builds.
- all 'L' or '_T()' does is convert ANSI to Unicode, correct?
Quote:Original post by ViperrrIf you look at the debugger (Also required reading), does the value of text look strange? I.e. is it 0xcccccccc, or 0x00000000, or some other pattern? Does it show up correctly in a debug watch window?
I still am unable to fix my code though, I tried this:
*** Source Snippet Removed ***
This DOES compile, but my app crashes immediately. When I break, the cursor jumps to this line:
*** Source Snippet Removed ***
I pass 'pGameObj->statusStr' into 'text' (which are LPCTSTR's)
This drawText function worked fine before, I was able to display text.
Any idea whats wrong?
Thanks again.
pGameObj->statusStr = currentLine.c_str();
pGameObj->statusStr = currentLine;