|
Hi, all!
========
I Need to send a buffer to this port 1234 and to this ip 127.0.0.1 .
How can I do it ?
BTW: come to #CodeProject on DalNet (mIRC)
|
|
|
|
|
Look for CSocket or CAsyncSocket (the first one is easier)
Andres Manggini.
Buenos Aires - Argentina.
|
|
|
|
|
Hello, the codegurus around the world.;)
Or use WinSock API direcly.
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winsock2.h>
#define WINSOCKVER MAKEWORD(2,0)
#pragma comment(lib, "wsock32.lib")
#pragma comment (lib, "ws2_32.lib") // link socket
int main()
{
int i, j;
int port=80;
char temp[1];
char host[512]="localhost";
SOCKADDR_IN ss_addr;
char request[MAX_PATH]="the buffer content goes here";
hostent FAR * he;
printf("Send Buffer \n");
printf("By Net Guy\n");
WSADATA wsdata;
if( WSAStartup(WINSOCKVER, &wsdata) != 0 )
exit (1);
if((he=gethostbyname(host)) == NULL)
{
fprintf(stderr, "invalid target\n");
exit (-1);
}
ss_addr.sin_family = PF_INET; in
ss_addr.sin_port = htons(port);
memcpy((char *) &ss_addr.sin_addr, (char *) he->h_addr,
sizeof(ss_addr.sin_addr));
if((i=socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1)
{
fprintf(stderr, "cannot create socket\n");
exit(-1);
}
j = connect(i, (struct sockaddr *) &ss_addr, sizeof(ss_addr));
if(j==-1)
{
fprintf(stderr, "cannot connect to %s\n", host);
exit(-1);
}
printf("]- Sending request: %s\n", request);
send(i, request, strlen(request), 0);
while(recv(i,temp,1, 0)>0)
{
printf("%c", temp[0]);
}
return 0;
}
|
|
|
|
|
Thanks.
You helped me alot.
Do you have an example of how I can listen to this port and recive data?
BTW: thanks again.
|
|
|
|
|
Hi, I have set up some dynamic menus that look for files on the hard-disk and adds the ones that interest me to a CMenu structure which is added to the top-level menu bar - no problem. I have implemented the message map so that when any of these dynamic menus are clicked on, it is directed to a standard function, where it is hoped an algorithm will be executed on the file concerned. The difficulty I`m having is knowing which menu item has just been clicked (so I can load the appropriate file). The code I use to append the menus is :
popup->AppendMenu(MF_STRING, IDM_MENU_SELECTED, file.name);
and my message map is
ON_COMMAND(IDM_MENU_SELECTED, OnMenuItemClick)
They all have the same ID ! Is there anyway of passing through a CMenu* or CCmdUI* to the menu item that has just been selected so that the function header is :
void CDisApp::OnMenuItemClick(CMenu* MenuItemJustSelected)
or is there a way of implementing dynamic menu ID's at runtime? Please help, this is starting to pee me off.
AEGC
|
|
|
|
|
You shouldn't use IDM_MENU_SELECTED as the value for nIDNewItem in your call to AppendMenu. That is why you always get the same id back.
But I'd use ON_COMMAND_RANGE as the message map macro.
Define your handler : afx_msg void MenuItemClick( UINT nID );
nID will be the id of the item that was clicked,
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
Hi,
If u are targetting,
Win 98/Me/2000 , u can get what u want by trying
the WM_MENUCOMMAND which gives u a handle to the menu
and u can get the text.
Best of Luck
|
|
|
|
|
Hi
I've tried to create a toolbar with dropdown-style from my shell namespace exstension. I set all the common flags that I normally do. The dropdown arrow is displayed but I don't get any dropdown-notifications, only commands, no matter where I click or if I use BTNS_DROPDOWN or BTNS_WHOLEDROPDOWN.
Anyone with experience from this problem?
|
|
|
|
|
Hi, I have set up a CStringList containing lines of co-ordinate points of the form "20,30" for example, and would like to be able to process the CStringList lines into respective CPoint values so that I can use them as co-ordinates to map to the screen. I have managed to process the CStringList line to extract the string representation of "20" and convert it to CPoint.x and "30" to CPoint.y, but i am not convinced this is the best way to go about it. I would appreciate some help on this guys,
Cheers, Alan.
AEGC
|
|
|
|
|
Logically that is precisely what you need to do if you have a good reason to store them as strings in the first place. Why can't you build a vector ( OK, or a CArray ) of CPoints ?
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
Hi friends,
i acutally have a little trouble with cursor on Win98SE. I have in the resource of my project 3 raw data item each one corresponding to an animated cursor.
With that:
HRSRC hrsc=FindResource(NULL,MAKEINTRESOURCE(IDR_NAV),"ANI");
DWORD dwSize=SizeofResource(AfxGetInstanceHandle(),hrsc);
HGLOBAL hg=LoadResource(AfxGetInstanceHandle(),hrsc);
LPBYTE pBytes=(LPBYTE)LockResource(hg);
i can get a pointer to my resource and with that :
HCURSOR m_Cur=(HCURSOR)CreateIconFromResource(pBytes,dwSize,FALSE,0x00030000)
result => m_Cur=NULL
but i must have to be able to create my cursor with CreateIconFromResource... but these cursor are 256 color. And it seems it is impossible to create 256 color cursors with the AIP function.
Have you any suggestion to help me ? ( i have to keep resource inside my .exe)
Thx all
|
|
|
|
|
Is There someone which can help me to kill a process by code (Visual C++) knowing the process name? Thanks
Nando
|
|
|
|
|
Hi,
Take a look at the following article.
http://codeguru.com/system/killer.html
Kumar
|
|
|
|
|
I'd like to add a colour to an already existing CPalette, so that I can then write on the corresponding bitmap with a new colour. Anyone know how please?
|
|
|
|
|
See MSDN for CPalette::SetPaletteEntries, and if necessary see CPalette::ResizePalette as well.
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
|
Hi, all.
========
I have a function that creates threads.
How can I know when a thread is ended?
Like when a thread is ended a function will be called, or somthing like that.
BTW: come to #CodeProject on DalNet (mIRC)
|
|
|
|
|
From MSDN:
When a thread terminates, the thread object attains a signaled state, satisfying any threads that were waiting on the object.
Use WaitForSingleObject() to determine if the thread has signalled:
if (WaitForSingleObject( hYourThreadHandle, 0) == WAIT_OBJECT_0)
DoSomething(...);
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
Hi,
U can use the above mentioned method or u can use the
'GetExitCodeThread' to test,
With this method u dont need to hold up processing,
and if the thread is still active it will return
the exitcode as 'STILL_ACTIVE'.
Best of Luck.
Kumar
|
|
|
|
|
Dear Friends
Hi
Will you please anyone tell me how to maintain scroll bar if no. of line of document is unknown.
is it not possible that system itself maintain the scroll bar automatically.i am new to VC++ so please help me in getting the solution.
Thanks in advance
Bye
Binay
|
|
|
|
|
If you're using MFC, and derive your view from CScrollView, then you'll get scrollbars, but there really is no way your program will magically know how far to scroll if you don't. You'll need to count the lines, and factor in the number of lines visible in order to derive the scroll values you need.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
Dear Christian
Hi
Thanks once again for ur suggesion.As you know i am doing modificaion by copying and paste method.So in my project it is not sure how many lines user has to copy.that is why i am facing problems.But i think there is no any other way for automatic adjustment of scrollbar without knowing the no. of lines.
Thanks for ur reply once again.
Bye
Binay
|
|
|
|
|
Hi guys, I need some help
I get a filename from an external source, and I must create a file on disk with that filename. The problem is that there is no garantee that the filename I have is a valid filename, i.e. it can have invalid characters such as \ / : * ? " < > |.
Is there a standard way of fixing invalid filenames (through a windows shell api maybe?). I know that I can do it manually, but I would prefer to use a standard method.
Thanks!
James
(2b || !2b)
|
|
|
|
|
You can't really "fix" a filename without applying human ai to it.
for example, say i typed this: c:\myfile.8nc
my big fingers hit the 8 key instead of the i key. You're never going to be able to fix errors like that: other problem areas are where user hits / instead of ., etc.
AFAIK no programs in windows will try to fix a bad name. what you should do is try to create the file anyway, but look for errors from the CreateFile() function. If there is an error, then report back to the user.
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|