|
If you use the c_str function, it will return a LPCxSTR. Depending on if you are using MBCS or UNICODE std strings, it will return LPCSTR or LPCWSTR. If you are using std::string, then you can use the A2CW macro.
LPCWSTR psz = A2CW (str .c_str ());
BUT, there are some gotcha's.
A2CW uses stack space. So you can't invoke it 100000 times in a for loop. Also, you can't use it to convert large string.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
A2CW uses stack space. So you can't invoke it 100000 times in a for loop.
Yep, that's a pity. Things would be easier if space allocated by _alloca would follow normal scope rules for stack-based objects (that is, if automatic freeing happened on block exit). In connection with this, C99 allows for variably sized stack arrays:
void f(const char *str)
{
char array[strlen(str)+1];
...
} I think this feature is being considered for inclusion in the next C++ release, which could be a boon to implementations of superfast containers (like std::vector s without the heap allocation overhead). While this day comes, I think the effect could be reproduced in VC++ with a little assembly and some wrapper class:
class variable_array
{
public:
variable_array(variable_array& r):p(r.p),n(r.n)
{
r.p=0;
}
~variable_array()
{
if(p){
}
}
void *p;
size_t n;
private:
variable_array(void* p,size_t n):p(p),n(n){}
friend variable_array make_variable_array(size_t n);
}
variable_array make_variable_array(size_t n)
{
return variable_array(stack pointer,n);
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
HI,
I have created an MDI application, but my problem is i am unable to create a window just like debugger window in VC++, for which i want to use to display some information, i tried using CSplitterWnd but couldn't use as child window has to used to split. But my problem is i want to create an independent window at bottom.
do let some light on it!!.
Arun Kumar
|
|
|
|
|
maybe i'm not getting the question properly but can't you jus create a new doctemplate for your debugging output window and create one of those when your app runs?
---
"all's fair in love and war but in love there's no geneva convention"
|
|
|
|
|
I'm trying to create a simple IRC client for learning purposes. I made it singlethreaded to begin with and everything worked great. But after I added a thread to handle incoming messages from the IRC server i keep getting an assertion when there isn't anything to recieve. I've traced it down to this...
while ((nResult = CAsyncSocket::Receive(lpBuf, nBufLen, nFlags)) == SOCKET_ERROR)
{
if (GetLastError() == WSAEWOULDBLOCK)
{
if (!PumpMessages(FD_READ))
return SOCKET_ERROR;
.
.
. This code above is taken from within the function (CSocket::Receive) I call to recieve data from the IRC server, and as long as there is data to recieve CAsyncSocket::Receive returns the number of bytes read and everything is ok. But when there isn't GetLastError() returns WSAEWOULDBLOCK and CSocket::PumpMessages is beeing called...:
ASSERT(m_pbBlocking == NULL);
_AFX_SOCK_THREAD_STATE* pState = _afxSockThreadState;
ASSERT(pState->m_hSocketWindow != NULL); The above code is the beginning of CSocket::PumpMessages, and this last assertion is the one I'm talking about. Why is PumpMessages called at all? I just want Recieve to return whatever data is waiting to be recieved, and if there is none just wait for some
Sprudling
PS! I created the new thread using ::CreateThread(), not using the CWinThread MFC class. Could that have anything to do with it?
|
|
|
|
|
When you create sockets in Windows using SDK functions, they are generally blocking, meaning that if no data is available for a receive, the application would hang until data is ready.
However, the CAsyncSocket class hides a lot of implementation details from you. When you create a socket based on this class, the calls are non-blocking. The idea is that your program will respond to networking events, rather than waiting for something to happen.
Receiving "WSAEWOULDBLOCK" is more of an informational message than an error. All it is telling you is that if you were using the blocking version of that function, it would be blocking right now.
What you should do is create a subclass of CAsyncSocket, and overload the "OnReceive" function. Any time data is available from the network, this function is called. You can put it in your screen buffer and display it at that point.
--
Paul
"I drank... WHAT?"
|
|
|
|
|
Thank you VERY much, it worked perfectly
Sprudling
|
|
|
|
|
You're welcome! I just spent the past few days working with MFC's CAsyncSocket class, so I through I might be able to help
--
Paul
"I drank... WHAT?"
|
|
|
|
|
Hi Friends
I need some help I want to Execute a Dos Command , not a one shot one. Eg ftp,
Say ftp xxxx , then it will ask for the username , then I want to pass it , then the password? How to do this from a C++ Programe, remember ftp is just a Example , I need a generalized solution which I can use in this type of situations.
Thanks
Gaurika Wijeratne..
Gaurika Wijeratne .. www.gaurika.com
|
|
|
|
|
You can use "<" to redirect input.
eg:-
D:\>copy con abc.txt
d100
q
^Z
1 file(s) copied.
D:\>debug < abc.txt
-d100
0B00:0100 4D 8B 56 05 80 FA 00 74-05 80 FE 3A 74 02 B2 40 M.V....t...:t..@
0B00:0110 80 CA 20 80 EA 60 E8 74-E4 73 06 E8 34 00 EF 0A .. ..`.t.s..4...
0B00:0120 D8 8B D5 83 C2 05 8A 7E-04 80 E7 06 80 FF 06 75 .......~.......u
0B00:0130 18 8B 76 02 B3 3A 38 5C-FE 75 06 C6 46 00 02 EB ..v..:8\.u..F...
0B00:0140 05 C6 46 00 01 4E E9 83-00 80 FF 02 75 05 C6 46 ..F..N......u..F
0B00:0150 00 00 C3 E8 B6 EB B4 3B-CD 21 72 39 8B FA 33 C0 .......;.!r9..3.
0B00:0160 8B C8 49 26 8A 05 47 0A-C0 74 0C 32 E4 E8 23 E2 ..I&..G..t.2..#.
0B00:0170 74 F1 47 FE C4 EB EC 4F-A0 03 96 C6 46 00 02 0A t.G....O....F...
-q
D:\>
Nish
The rumours that I am an AI bot are absolutely false. These rumours have been propogated by *them* to focus all the attention on to me, while *their* bots take over the planet. Thank y%%%% Divide by zero. Cannot proceed. Abort(y/y)?
|
|
|
|
|
Take a look at CreateProcess() in your docs.
cheers,
-Ben
|
|
|
|
|
eheheh!!
I don't think that's right, because in this case ... try it:
#include "stdio.h"
template < class type > int size(){return sizeof(type);};
int main(int argc, char* argv[])
{
printf("%i\n",size <float>());
printf("%i\n",size <int>());
printf("%i\n",size <double>());
printf("%i\n",size <char>());
printf("%i\n",size <short>());
};
Why???
Gianfranco Lanzetta.
|
|
|
|
|
Works fine for me with VC7.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Tim Smith wrote:
Works fine for me with VC7.
Tim,
I think he can compile it and run it, but that he is not fully satisfied with the outputs he got.
Nish
The rumours that I am an AI bot are absolutely false. These rumours have been propogated by *them* to focus all the attention on to me, while *their* bots take over the planet. Thank y%%%% Divide by zero. Cannot proceed. Abort(y/y)?
|
|
|
|
|
What is wrong with the output. I got all the numbers I expected.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Tim Smith wrote:
What is wrong with the output. I got all the numbers I expected.
I believe his expectations don't match those of yours.
Nish
The rumours that I am an AI bot are absolutely false. These rumours have been propogated by *them* to focus all the attention on to me, while *their* bots take over the planet. Thank y%%%% Divide by zero. Cannot proceed. Abort(y/y)?
|
|
|
|
|
Yeah, looking at the code again, I ran into this bug with VC6. Fixed in VC7.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
|
I haven't installed any VC7 patches.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
If all you are getting is 4 or 2 for each of the types, this is a known bug I reported to MS with template functions that don't have unique types in the arguments.
This bug is fixed in VC7. Don't hold your breath for a patch to VC6.
The workaround is to use structs and not functions.
template <class _T>
struct sizer
{
int sizer () { return sizeof (_T); }
};
printf ("%d", sizer<int>::sizer ());
I think that will do it, but I didn't test it.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Some Window Engine in this page is very good (use API function: WindowFromPoint()) . But I can't use it for my purpose:
-Get handle of a "static " (label) created in Visual Basic 6.0.
It seems VB label is drawn onto screen, not be a control (so you can't get its handle).
Can you give me an answer ?
Hung Son
A Vietnamese student
i-g.hypermart.net
dlhson2001@yahoo.com
|
|
|
|
|
dlhson wrote:
It seems VB label is drawn onto screen, not be a control
I think the VB label is a STATIC control. I might be wrong here. But that's my impression.
Nish
The rumours that I am an AI bot are absolutely false. These rumours have been propogated by *them* to focus all the attention on to me, while *their* bots take over the planet. Thank y%%%% Divide by zero. Cannot proceed. Abort(y/y)?
|
|
|
|
|
You are correct, the VB label is not a control. The form draws it. My guess this is to reduce the number of controls that VB programmers place on a form, since you are only allowed to have 255 declared in a resource file.
What purposes do you want to have the handle to the label in VB? Depending on what you plan on doing, there are options.
Checkout my Guide to Win32 Paint for Intermediates
|
|
|
|
|
control.hwnd
Best Regards
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
I'm sorry I thinked that you was talking about VB...
If you want to Know the HWND of the label, you must to use the label like a CWnd, and asign it with CWnd::GetDlgItem. You can get the handle with the data memeber CWnd::m_hWnd...;)
Best Regards...
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|