|
Just a quick sample though I think it might be on a brute-force approach. I had problems with TCHAR though, it has some trash characters at the end.
TCHAR* tchar;<br />
CString message("Hello there");<br />
<br />
int temp = message.GetLength()*2;
tchar =(TCHAR*)malloc(temp+1);
memset(tchar, NULL, temp+1);<br />
memcpy(tchar, message, temp);
<br />
CString messageback(tchar, temp/2);
free(tchar);
Sorry but still a problem with TCHAR's variable as there are "trash" characters on the end. Maybe others can help.
Read this article here
-- modified at 18:50 Wednesday 7th November, 2007
ouch! sorry bout that. admittedly, I did not really took that much attention to the article. comments noted. lesson learned.
|
|
|
|
|
Honestly, I think you've to read (perhaps with more attention ) the article too (and, maybe, related MSDN documentation).
Don't blame me for this.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Llasus wrote: int temp = message.GetLength()*2; //multiply by 2 because of the CString format
Why multiply by 2 ? How do you know that a character is 2 bytes long ? It's only the case when UNICODE is enabled.
Llasus wrote: tchar =(TCHAR*)malloc(temp+1); //add 1 for the NULL at the end: but doesn't work
Don't use malloc in C++. If you had used new, you won't have any problem with calculating the size. You just create an array of TCHAR and the compiler will allocate the correct size depending of UNICODE is set or not.
Llasus wrote: memcpy(tchar, message, temp); //copy; now we have the TCHAR
Don't use memcpy to copy strings. Prefer to use the macro _tcscpy that will be strcpy if UNICODE is not declared or wscpy if UNICODE is declared (so you don't have to bother about it).
If you have garbage values at the end of your string, it's simply because you didn't put a ending zero at the end of your string.
|
|
|
|
|
I'm not getting what you are trying to do with the code.
CString is just a wrapper for TCHAR.
That is CString has a member variable like below.
CString
{
private:
TCHAR *m_buf;
//Several other stuffs!
};
if your intention is to construct another CString from the edit box contents then CString messageback(message) will suffice.
to get the pointer to member variable m_buf(member variable name might not be exact) by using GetBuffer() method.
pratap
|
|
|
|
|
you are writing pure crap, and you think it's a correct answer for someone that is lost with his code ?
read here[^] for how to consert from one type to the other (and benefit of the whole linked thread to read it, it could be useful for you too)
|
|
|
|
|
here[^]
and be sure "the Notify me by e-mail if someone answers this message" box is checked
|
|
|
|
|
HAI FRIENDS
THIS IS KANSAGOUS
I AM HAVING A PROBLEM: I AM NOT ABLE TO RECEIVE INFORMATION
FROM CLIENT SIDE USING INTERNET EXPLORER I HAVE CREATED A
SERVER IN VC++ BUT NOW I WANT A FUNCTIONALITY BY WHICH I
CAN RESPOND TO THE WEB REQUEST BY CLIENT
THIS IS MY CODE PLEASE REVIEW IT AND TELL ME WHAT TO DO
// THIS PROGRAM SHOWS THE BASIC WORKING OF A SOCKET USING winsock2.h header file //
//************************************************************************************************************
#include "winsock2.h"
#include "MyServer.h"
void main()
{
// I DONT KNOW # htons
//************************************ INITIALISING A SOCKET **************************************************
//The WSADATA structure contains information about the Windows Sockets implementation
WSADATA wsaData; // To initialise WINSOCK we have created an object
//The WSAStartup function is called to initiate use of WS2_32.lib.
int iResult = WSAStartup ( MAKEWORD(2,2) , &wsaData ); // MAKEWORD(2,2) parameter of WSAStartup makes a request for the version of Winsock on the system
if(iResult != NO_ERROR)
{
printf("Error at WSAStartup() \n");
}
//************************************ CREATING A SOCKET ******************************************************
SOCKET m_socket;
m_socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); // SOCK_STREAM IS INPUT TYPE
//Check for errors to ensure that the socket is a valid socket.
if( m_socket == INVALID_SOCKET )
{
printf("Error at socket() :- %d\n",WSAGetLastError() ); //WSAGetLastError returns an error number associated with the last error that occurred.
WSACleanup(); //WSACleanup is used to terminate the use of the WS2_32 DLL.
return;
}
//************************************ BINDING A SOCKET ********************************************************
//To bind a socket that has already been created to an IP address and port
//The sockaddr structure holds information regarding the address family, IP address, and port number.
//sockaddr_in is a subset of sockaddr and is used for IP version 4 applications
sockaddr_in service;
service.sin_family = AF_INET; //AF_INET is the Internet address family
service.sin_addr.s_addr = inet_addr("192.168.50.243");
service.sin_port = htons( 1200 );
if ( bind(m_socket,(SOCKADDR*) &service, sizeof(service) ) == SOCKET_ERROR )
{
printf("Bind() is not sucessfull\n");
closesocket(m_socket);
return;
}
//************************************ LISTENING A SOCKET ****************************************************
if(listen(m_socket,1) == SOCKET_ERROR)
{
printf("Error in listening on socket. . . . . \n");
}
//************************************ ACCEPTING A SOCKET ****************************************************
SOCKET AcceptSocket;
printf("Waiting for client to connect . . . .\n");
while(1) // Continuous loop that checks for connections requests
{
AcceptSocket = SOCKET_ERROR;
while( AcceptSocket == SOCKET_ERROR )
{
AcceptSocket = accept(m_socket, NULL, NULL); // Call the accept function to handle the request.
}
printf ("Client Connected....\n");
m_socket = AcceptSocket; // Transfer control from the temporary socket to the original socket
break; // Stop checking for new connections.
}
//************************************ SENDING & RECIEVING DATA **********************************************
int bytesSent;
static flag = 0;
while (1)
{
static int count = 0 ;
ifstream inFile;
inFile.open("C:\\MyProjects\\MyServer\\Debug\\index.htm");
int bytesrecv = SOCKET_ERROR;
char recvbuf[1500];
printf("Bytes Recieved....%s\n",recvbuf);
bytesrecv = recv( m_socket, recvbuf, 1500, 0 );
if (inFile.is_open())
{
char sendmsg[1234];
while (!inFile.eof())
{
inFile.getline(sendmsg,1234);
bytesSent = send( m_socket, sendmsg ,strlen(sendmsg), 0 );
if(count > 1)
break;
}
}
else
{
cout << "Error opening File .. . . ";
}
if(count < 1 )
{
while(1)
{
bytesrecv = recv( m_socket, recvbuf, 1500, 0 );
printf("Bytes Recieved....%s\n",recvbuf);
fstream inFile1;
inFile1.open("C:\\MyProjects\\MyServer\\Debug\\dump.txt",ios::out);
inFile1.write (recvbuf,1500);
printf("Bytes Recieved....%d\n",bytesrecv);
inFile1.close();
count++;
break;
}
}
else
break;
}
printf("Bytes Sent.....%d\n",bytesSent);
closesocket(m_socket);
getch();
return;
}
//*************MyServer.h****************
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <conio.h>
#include <iomanip>
using namespace std;
-- modified at 5:06 Monday 12th November, 2007
|
|
|
|
|
Allow me to remind you a rule (that is written in the sticky - that is the first message in VC++ Message Board): keep your code samples as brief as possible!
I really wanted to help but trust me... having an application that long read line by line isn`t too easy... Try to replace blocks of code you know that work (for example #include blocks, error management) and cut some free lines... briefly said, make your code easier to read and results will show up soon
Regards,
Shpid3r
|
|
|
|
|
i have created a window with Hollow brush as its background , and performed some drawing on that window. when tried to erase the contents by calling InvalidateRect nothing happens. How i could erase that drawing ?
please help me
Thanks & Regards
|
|
|
|
|
Try with ReCalculateLayout()
|
|
|
|
|
ReCalculateLayout()
what is that ?
Thanks & Regards
|
|
|
|
|
It internally calls OnPaint(), and call all the function which gets called after
minimizing and maximizing the window.
-- modified at 5:21 Wednesday 7th November, 2007
|
|
|
|
|
You need to force the redraw of whatever is behind/underneath your
window.
Maybe try something like
RECT rect;
::GetClientRect(hwndMyWindow, &rect);
::MapWindowPoints(hwndMyWindow, HWND_DESKTOP, (LPPOINT)&rect, 2);
::InvalidateRect(NULL, &rect, TRUE);
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi all,
I am having a main exe dialog box from which another dialog box opens up which is having a button and a edit box. On clicking button my menu appears. what i want is when i click on menu item particular text should be written in edit box. when i open class wizard for menu items and choose my dlg class and write OnCommand code over there a debug error is given and when i choose second class as base class nothing happens on click event
Can anybody help me in this
Thanks in advance
|
|
|
|
|
|
write the command handler in the class which has the edit control.
then, if u have a member variable for the edit control then use it to set the required text otherwise directly use win32 api: setdlgitemtext() by taking the hande of the edit control
prasann
who else
|
|
|
|
|
hallo,
in order to display and change a date list written in a txt file, seveal CEdit and CSpinCtrl should be dynamic created. The amount for the set of Editbox and SpinCtrl should be dynamic decided, according to the count of date set. CSpinCtrl and CEdit has the same behavior.
I cant set the Message using ClassWizard, How can I dynamic set the Message for the CEdit and CspinCtrl?
I have tried,
in the Class, a Message Map UDN_DELTAPOS (ID, OnEditChange()). I set all the CSpinCtrl with the same ID. In this way, when any CspinCtrl changes, the function OnEditChange() will be called, but i can not recognize which one has been clicked.
does anyone who has a solution?
thanks
mwolf
|
|
|
|
|
|
To Hamid:
for the edit control is created dynamicly, we may asign an ID for this edit control using
<br />
#define LVS_EDIT_ID 5100<br />
<br />
m_pctlEdit = new CEdit;<br />
m_pctlEdit->Create(xxx, <big>LVS_EDIT_ID</big>);<br />
If we send a message to the edit control(NOT FAMILAR TO SendMessage too), The edit control how to deal with this message, and where is the code?
I'm very poor at SDK programming way.
|
|
|
|
|
to Hamid,
unfortunately, i havent got sendmessage in the link you gave.
I can assign a ID and a function before the CEdit is created, and use
UDN_DELTAPOS (ID, OnEditChange().
then by creating the CEdit, I can set the same ID for the CEdit.
the problem is, before the programm running, i cant decide how many CEdit should be created, so I have no idea how many IDs should be assigned in my program.
|
|
|
|
|
Do you want to make edit controls with user select why you dont use of a int variable I had worked before but I think its possible that you use of them.
|
|
|
|
|
I didnt understand what you siad you make a dynamic control now do you want to know where you must send messagess to it?
|
|
|
|
|
Hi,
I am studying LR1 compiler construction and am confused with the Closure(I) function.
The book I have gives the following:
Closure(I) =
repeat
for any item (A ---> a.XB, z) in I
for any production X ---> y
for any w {set} FIRST(Bz)
I <-- I U {(X ---> .y, w)}
until I does not change
return I
The part I do not understand is FIRST(Bz). Is this the same as FOLLOW(X)?
It would be great if somebody could rewrite this in C style pseudocode to help me understand this further. Here is some pseudocode for the type of thing I have atm....the actual C++ code is too involved for a forum posting:
STATE Closure(STATE I)<br />
{<br />
bool updated = false;<br />
do<br />
{<br />
updated = false;<br />
for(int i = 0; i < I.itemcount; i++)<br />
{<br />
ITEM *pItem = I.items[i];<br />
int prev_prod_count = I.prod_count;<br />
<br />
if(pItem->phase < item.production.right_length)<br />
{<br />
right_token = item->prod.right(item.phase);<br />
for(vector<PRODUCTION>::iterator itProd = grammar->begin(); itProd != grammar.end(); itProd++)<br />
{<br />
if(itProd->left_side == right_token)<br />
{<br />
SYMBOLSET *pBeta = NULL;<br />
if(item.phase + 1 < item.right_length)<br />
{<br />
pBETA = FIRST[item.prod.right[item.phase + 1]];<br />
if(pBETA->count == 0)<br />
pBETA = FIRST[item.look_ahead];<br />
}<br />
else<br />
pBETA = FIRST[item.look_ahead];<br />
<br />
foreach(symbol in pBeta)<br />
{<br />
item.append(*ItProd, 0, symbol);<br />
}<br />
}<br />
}<br />
}<br />
if(I.prod_count != prev_prod_count)<br />
updated = true;<br />
}<br />
}<br />
<br />
return I;<br />
}
Any help would be greatly appreciated!
Lea Hayes
|
|
|
|
|
Hi,
Would the following be true?
int right_pos = B;
SymbolSet *pSymbolSet = EmptySet();
do
{
pSymbolSet = Union(pSymbolSet, FIRST(right_pos));
right_pos++;
}
while(NULLABLE[right_pos]);
Because given the grammar:
Z' --> Z $
Z ---> X Y Z
Z --->
Z ---> d
X ---> Y
X ---> a
Y --->
Y ---> c
The rule production Z ---> X Y Z has two nullable non-terminals (X and Y), so I am guessing that Z would need to be included within the set w : {Bz}?
I have tried implementing this and it seems to work as I expected....but I wanted to verify if I have in fact understood the algorithm correctly so that I don't encounter a nasty suprise further down the line.
Best regards,
Lea Hayes
|
|
|
|
|
Using VC 6, is it possible to create VS macros that are unique to a project? What I mean by "VS macros" is the macros that are created, edited and run using "Tools | Macro" in VC 6 and documented in Macros[^]. The macros are in DSM files and have access to the Developer Studio Objects[^].
I can create a DSM file in the project but the only way I know to execute a macro in the DSM file is to load the file, which is done globally and for all projects and all workspaces. I want the macros in the project's DSM file to be used only for the project it is in.
I expect that someone is going to say that I should use a macro with a VBS or JS extension. Let me say ahead of time that if you think that will work, it is highly likely you are not familiar with VC 6 enough to understand. I will likely ignore replies suggesting I use macros that will be executed by WScript or CScript.
|
|
|
|
|