|
Thank you for reminding me to do that. Thanks a million i got it working all over again.
|
|
|
|
|
If you save the file with a .c extension, when then try to compile it, it will compile as a C file and not C++. So if you use any C++-specific constructs (which your code does), it will fail to compile.
Peace!
-=- James Please rate this message - let me know if I helped or not!<hr></hr> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Hi,
In C you are required to declare the variables at the beginning of the block. but this is not necessary in C++. In C++ u can declare the variable just before it is going to be used . But this will show as erorr in C. so in your code the following bold statements cause errors in C.
#include
#include
int main()
{
WSADATA wsadata;
WORD wVersion;
int wsaerr;
wVersion = MAKEWORD(2,2);
wsaerr = WSAStartup(wVersion, &wsadata);
if(wsaerr != 0)
{
printf("There is a DLL linker problem");
return 0 ;
}
else
printf("\nDLL working and compatible!!");
SOCKET mysocket;
mysocket = socket(AF_INET,SOCK_STREAM,0);
if(mysocket == SOCKET_ERROR)
{
printf("socket cannote be created error: %d",WSAGetLastError);
WSACleanup();
return 0;
}
printf("\nSocket created successfully");
sockaddr_in Cservice;
Cservice.sin_family = AF_INET;
Cservice.sin_addr.s_addr = inet_addr("127.0.0.1");
Cservice.sin_port = htons(55555);
if(connect(mysocket,(sockaddr *)&Cservice,sizeof(Cservice))== SOCKET_ERROR)
{
printf("Connect is unsuccessful, error:%d",WSAGetLastError);
WSACleanup();
getchar();
return 0;
}
int bytesent;
int byterecv=SOCKET_ERROR;
char sendbuff[200] = "Client:This is a test string from client.";
char recvbuff[200] = "";
while(byterecv == SOCKET_ERROR)
{
byterecv = recv(mysocket,recvbuff,strlen(recvbuff),0);
if(byterecv==0||byterecv==WSAECONNRESET)
printf("\nClient: Connection closed");
if(byterecv>0)
return 0;
else
{
printf("\nClient: recv() is OK");
printf("\nClient: The string received %s",recvbuff);
printf("\nClient: The bytes received %d",byterecv);
}
}
bytesent=send(mysocket,sendbuff,strlen(sendbuff),0);
if(bytesent == SOCKET_ERROR)
printf("\nClient: send() failed:%d",WSAGetLastError);
else
{
printf("\n Client: send() is OK");
printf("\n Client: The string sent %s",sendbuff);
printf("\n Client: The number of bytes sent %d",bytesent);
}
getchar();
WSACleanup();
return 0;
}
thanks
Nitheesh
|
|
|
|
|
Yea thanks for tht but even after taking the variable declarations in the begining of the program i get error messages. For socket programming does C have some other constructs? Cos the books i used had socket as a structures and i could use it. can anyone suggest anything?
cheers
this is the error messages that i get.
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(11) : error C2065: 'sockaddr_in' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(11) : error C2146: syntax error : missing ';' before identifier 'Cservice'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(11) : error C2065: 'Cservice' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(12) : error C2143: syntax error : missing ';' before 'type'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(13) : error C2143: syntax error : missing ';' before 'type'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(14) : error C2143: syntax error : missing ';' before 'type'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(15) : error C2143: syntax error : missing ';' before 'type'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(33) : error C2065: 'Cservice' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(33) : error C2224: left of '.sin_family' must have struct/union type
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(34) : error C2065: 'Cservice' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(34) : error C2224: left of '.sin_addr' must have struct/union type
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(35) : error C2065: 'Cservice' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(35) : error C2224: left of '.sin_port' must have struct/union type
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(36) : error C2065: 'sockaddr' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(36) : error C2059: syntax error : ')'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(44) : error C2059: syntax error : 'while'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(58) : error C2065: 'mysocket' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(58) : error C2065: 'sendbuff' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(58) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(58) : warning C4024: 'send' : different types for formal and actual parameter 2
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(58) : error C2065: 'sendbuff' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(58) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(58) : warning C4024: 'strlen' : different types for formal and actual parameter 1
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(58) : error C2099: initializer is not a constant
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(59) : error C2059: syntax error : 'if'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(61) : error C2059: syntax error : 'else'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(68) : warning C4273: 'getchar' : inconsistent dll linkage
1> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(273) : see previous definition of 'getchar'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(69) : error C2373: 'WSACleanup' : redefinition; different type modifiers
1> c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2161) : see declaration of 'WSACleanup'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(70) : error C2059: syntax error : 'return'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(71) : error C2059: syntax error : '}'
1>Build log was saved at "file://c:\Documents and Settings\HP\My Documents\Visual Studio 2008\Projects\socketclientc\socketclientc\Debug\BuildLog.htm"
1>socketclientc - 25 error(s), 5 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
|
|
|
|
|
Thank you for reminding and helping me out i got it all working now.
|
|
|
|
|
Hello Guru's
I am making a application in MFC ( Modal Dialog Based ) But its form size is constant as we have fixed at design time . Can any one told me how can make it Maximized automatic after clicking maximized box.
Regard's
Kaushik
|
|
|
|
|
Sorry, but I'm not sure I understood your problem correctly. Do you want that the controls on your dialog position themselves correctly when you maximize your dialog ?
If that's the case, then take a look at these articles[^]. The first one looks promising.
If it's not what you asked for, then explain your problem more clearly.
|
|
|
|
|
I mean to say
Suppose we have create a dialog box and put on it edit box check box
etc..
when we design form on 600x800 resolution monitor form see complete at monitor. But when we open it at different resolution its see small and if we maximize its half of part see blank. How can we programming so that all control adjust automatically.
Regard's
Kaushik
|
|
|
|
|
Did you look at the article I mentioned to you ?
|
|
|
|
|
SetWindowPos will help you to resize your control!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
ShowWindow(SW_MAXIMIZE)
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
See the Extras sthis article.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi,
Try using ShowWindow(SW_MAXIMIZE).
thanks
Nitheesh
|
|
|
|
|
It seems you need to SetWindowPos or MoveWindow on the WM_SIZE.
|
|
|
|
|
Hello,
I would like to stop all messages to the window taskbar. I try to use the PreTranslateMessage function and it seems that the messages to the taskbar are not sending throw this function. Do you know a way to catch the messages?
Do you know if it should be throw this function?
Thank a lot !
|
|
|
|
|
TalSt wrote: I would like to stop all messages to the window taskbar. I try to use the PreTranslateMessage function and it seems that the messages to the taskbar are not sending throw this function. Do you know a way to catch the messages?
Use GetWindowLong and GWL_WNDPROC to get a window's main procedure address and replace it with your own version using SetWindowLong .
Now messages to the window which you hooked should go via your WindowProc . Store replaced WindowProc ptr to use with CallWindowProc to do default stuff. Don't forget to replace back this ptr when your application exits!
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
Hello,
Can you give more details? I am not sure I understand...
How can the messages be stopped this way?
Thanks !
|
|
|
|
|
|
I assume by "window taskbar" you mean the taskbar with the "Start" button on it. This is part of "Explorer.exe". You can't expect to recieve messages from windows in another process via "PreTranslateMessage"!
Steve
|
|
|
|
|
I want to delete a empty folder present at a specified path. I am using this code for doing this:-
<pre>
CString fol_Path = _T("C:\\Program Files\\New Folder");
if(_taccess(fol_Path, 0) != -1)
{
Attributes = GetFileAttributes(fol_Path);
if(Attributes != 0xFFFFFFFF)
{
SetFileAttributes(fol_Path,FILE_ATTRIBUTE_NORMAL);
_wunlink(fol_Path);
}
}
</pre>
but my _wunlink function is returning -1 value.....
i am using unicode.....
can anbody tel me how to do this.....
thanks in advance
|
|
|
|
|
You're using a rather bizarre mixture of Win32, tchar and _UNICODE functions. I assume you have checked elsewhere that the folder you want to delete is empty, right? Also, you don't have to use GetFileAttributes() since you want to delete the folder anyway.
Most importantly, check the return code from SetFileAttributes() with GetLastError() .
If that is successful, use RemoveDirectory() and again check the return value with GetLastError() .
|
|
|
|
|
good morning everybody,
I m very new to windows mobile..... i m using CeDialer application .... I m able to call outgoing call.... now i want to implement call hold.... the msdn says to use LinrHold().... but I dont know where to use it in my code ,,,, and which parameter to pass in it....
I m using visual studio 2005 and windows mobile 6 sdk....
Thanks a lot ...
modified on Monday, April 7, 2008 3:00 AM
|
|
|
|
|
i have 2 exprted functions in a dll ( Win32 dynamiclink dll project )
void __stdcall MsgBox()
{
MessageBox( NULL , "Hello" , "" , MB_OK ) ;
}
void __stdcall MsgBox1( LPSTR a )
{
MessageBox( NULL , a , "" , MB_OK ) ;
}
//i tried following commands , the first one works but the not the secnd one, can any one tell where is the problem ?
//{
rundll32.exe mydll.dll,MsgBox
rundll32.exe mydll.dll,MsgBox1 "hi"
//}
//def file
//{
LIBRARY MyDll
EXPORTS
MsgBox
MsgBox1
//}
Thanks
modified on Monday, April 7, 2008 3:35 AM
|
|
|
|
|
nitin3 wrote: MessageBox( NULL , T , "" , MB_OK ) ;
And what is the output you're expecting from?
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
sorry that was a mistake, i modified the code.
my problem is the second function MsgBox1 function does not displays the text i entered,
or its shows a message "An exception occured while trying to run "mydllfile.dll"
Thanks & Regards
|
|
|
|