|
Thnx fr guiding me . This being my fst attempt in socket prg.
Yeah i cud move ahead all bcoz of u , but caught again midway.
In my server program when i use recv() it gives the failed to bind and failed to listen errors. When i m trying to print the acceptance after the accept function it shows the connection. That <client ip="" address="" is="" connected="">
On other side When i use recv fn in Client application some garbage is printed in . I use it like
<br />
{<br />
<br />
char buff[512];<br />
servAddrSrvr.sin_addr.s_addr=inet_addr("192.168.0.20");<br />
servAddrSrvr.sin_family=AF_INET;<br />
servAddrSrvr.sin_port=htons(80);<br />
connect(conn,(struct sockaddr*)&servAddrSrvr,sizeof(servAddrSrvr));<br />
recv(conn,buff,sizeof(buff),0);<br />
printf("%s\n",buff);<br />
}<br />
Can u say me where i went wrong.
amit mishra
|
|
|
|
|
You're ignoring the length of received data (returned by recv() ), you're not checking if all data is read in a single call to recv() and you're assuming that the data placed in buf by recv() is zero-terminated.
|
|
|
|
|
Hi all! I am Alex and wanna get help for how to Open the binary data file in C++ through the code. Actualy, the information in these data files are in hexadecimal forms, so I wanna ask how to use code to convert hexadecimal number to decimal number!
Weclome for all help!
Thank you very much!
Alex
|
|
|
|
|
Alex Wong 19 wrote:
...how to Open the binary data file in C++ through the code.
I would suggest CFile for this.
Alex Wong 19 wrote:
...how to use code to convert hexadecimal number to decimal number!
This is limited information, but my first inclination would be to use strtoul() . This assumes you would be reading the data in as a string.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hi world,
I'm want limiting a folder size. My application create some files inside this folder but I don't want exceed the desired size. Thus this application must delete older files when I want to add new file (to always respect the size limitation).
Anybody have an idea to do that?
Thank in advance...
Hello World!!!
from Raphaël
|
|
|
|
|
U may monitor that specified folder
ReadDirectoryChangesW is the API
it gives u many notifications (including size change, files added etc)
I hope this will help u
|
|
|
|
|
Rather than handle this at the software level, why not use quotas offered by the OS?
If you must attack this via software, a rough example is located here. It's specific to cookies, but you can alter the code as necessary to clean out old files.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hello everyone,
I am using an MFC dialog based application where a gif is loaded into the dialog. Now, the problem is that some of the controls within the dialog become hidden by the image.
What I want to do is to place the controls infront of the image as a background. Can anyone guide me.
Thanx in advance
|
|
|
|
|
Call SetWindowPos(wndTop, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE) to all hidden controls.
Robert-Antonio
"It's a good luck, when you meet a real fink. Then you get a respect to
normal, mid-honest people."
|
|
|
|
|
is this one able to replace IAMMultiMediaStream::open file?
i want a sample of using it.
who can do me a favor?
|
|
|
|
|
I have an editor applications which should bring up a window or dialog with the list of keywords. Based on the selected keyword the window should show the appropriate controls in the window. Filling up input into these controls and clicking insert the keyword should get inserted into the editor.
PLease someone help with some ideas on this.
|
|
|
|
|
The simplest approach is, that you create all controls in Dialog editor. In OnInitDialog you parse the keywords and set CWnd::ModifyStyle(WS_VISIBLE, 0, 0) to appropriate controls. This function makes the controls invisible.
Robert-Antonio
"Love without sex is like a fish without antlers"
|
|
|
|
|
also, I would put each set into a vector collection so that for each collection you can use the iterator to iterate through each one and set the visibility appropriately.
Who are all these people and what are they doing in my house?...Me in 30 years, inside a grocery store
My articles[^]
bdiamond
|
|
|
|
|
I have seen some code recently in the Unreal Tournament public source code that uses types like "void(UObject::*Func)( FFrame& TheStack, RESULT_DECL );" and I am trying to figure out how to use this in my own code. I have written something like below but I always get the error "C2064: term does not evaluate to a function"
class A<br />
{<br />
public:<br />
void TestFunc()<br />
{<br />
printf("Hello\n");<br />
}<br />
};<br />
<br />
void Test(void(A::*Prm1)(void))<br />
{<br />
Prm1();<br />
}<br />
<br />
int main(int argc, char **argv)<br />
{<br />
Test(A::TestFunc);<br />
<br />
return 0;<br />
}
It won't even let me cast it to a DWORD or any other types but you must be able to do something with it or it would not exist. So is there anyone here who can tell me how to use this (I dont even know what to call it), I have tried searching but all the search engines that I have tried have problems with "::*".
|
|
|
|
|
Try this:
class A
{
public:
void f() { printf("Hello\n"); }
};
void Test(void (A::*fun)(void))
{
A a;
(a.*fun)();
};
void main()
{
Test(&A::f);
}
If you call a non-static function via pointer-to-member, you have to specify a instance of class, that is passed to the member function.
Robert-Antonio
"Love, truth and electric traction must gain victory over hate, lie and
diesel traction."
|
|
|
|
|
Thanks alot, thats what I needed.
|
|
|
|
|
Hi,
I am writing an application that can do the following
1. Start an application
2. Open up a dialog box in the application
3. Write a message into a text dialog box and commit it.
I am having a problem with step 3. How do I pass along a string to write to a dialog box that is in focus. If this question has already been asked before, can you send me a pointer? Thanks.
Lohith
|
|
|
|
|
that means u wnat to update the edit box with some string?
ALL THINGS ARE POSSIBLE UNTIL THEY ARE PROVED IMPOSSIBLE-AND EVEN THE IMPOSSIBLE MAY ONLY BE SO,AS OF NOW
|
|
|
|
|
Get window handle of the text box and use SetWindowText.
Then send dialog a command message for the OK button press.
|
|
|
|
|
hi all,i have a problem with suspending a process.
Could someone help me?
Thanks a lot!
|
|
|
|
|
I expect we will be able to help you if you tell us what the problem is.
Mike
|
|
|
|
|
here are some code used to suspend a process. since I do not known the exact problem you meet, I only show it for you:
BOOL WINAPI SuspendProcess(DWORD dwProcessID, BOOL bSuspend)
{
// 取得OpenThread函数的地址
typedef HANDLE (__stdcall *PFNOPENTHREAD)(DWORD, BOOL, DWORD);
HMODULE hModule = ::GetModuleHandle("kernel32.dll");
PFNOPENTHREAD OpenThread = (PFNOPENTHREAD)::GetProcAddress(hModule, "OpenThread");
if(OpenThread == NULL)
return FALSE;
// 取得指定进程内的线程列表
HANDLE hSnap;
hSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, dwProcessID);
if(hSnap != INVALID_HANDLE_VALUE)
{
// 遍历线程列表
THREADENTRY32 te = { 0 };
te.dwSize = sizeof(te);
BOOL bOK = ::Thread32First(hSnap, &te);
while(bOK)
{
if(te.th32OwnerProcessID == dwProcessID)
{
DWORD dwID = te.th32ThreadID;
// 试图打开这个线程
HANDLE hThread = OpenThread(THREAD_SUSPEND_RESUME, FALSE, dwID);
if(hThread != NULL)
{
// 暂停或者唤醒这个线程
if(bSuspend)
::SuspendThread(hThread);
else
::ResumeThread(hThread);
::CloseHandle(hThread);
}
}
bOK = ::Thread32Next(hSnap, &te);
}
::CloseHandle(hSnap);
}
return TRUE;
}
I am a Chinese man, so the commentary is in Chinese.
Regards
|
|
|
|
|
1.what's type in fact?
we often write code like this :
typedef struct _M_{
int a;
char b;
}M;
M m;
m.b = 'w';
here is the question ,how C++ compiler treat M?How to get the address of m(I mean how compiler can)?and the offset of M::b?
2.template<class T>
class A{
T t;
};
case T is a structure,how can I visit every element of the struct T?
3.RTTI
How can I know the type of a variable at runtime?typeid can get its name,but what I need is the real type,not its name.
|
|
|
|
|
1. the compiler treat M very nicely; &m is the address, as for the other, I don't know.
2. huh ? without knowing the class/struct; with a class declaration, you can't ( but I must be wrong )
3.you can't. the best you can do if find if it matches an existing type; with dynamic_cast<type>, you will know if the variable is of type Type.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
1. A struct definition is a way to tell the compiler that: Whenever a variable of type struct is declared, it must allocate memory, at least, the size that the struct definition defines.
Let's declare a struct:
typedef struct tagMyStruct
{
int theInteger;
char theCharacter;
}
MyStruct;
Then we declare a variable of this type:
MyStruct theVariable;
char * pointerToCharacterMember;
theVariable.theInteger = 42;
theVariable.theCharacter = 'A';
When the compiler handles the variable declaration, it must find an offset in memory to put it. Let's say it puts it at 0x0001000.
For sizeof(MyStruct), the compiler should return sizeof(int) + sizeof(char), which is 4 + 1.
For simplicity of the example, I've chosen to use pointers. Let's do this:
pointerToCharacterMember = &theVariable.theCharacter;
To get the address that pointerToCharacterMember should point to, the compiler gets the address of theVariable. To get the address of the member theCharacter, it must add the size of the member theInteger. So the address pointed to by pointerToCharacterMember, should be 0x0001004.
In memory the variable would look like this:
memory offset Value
-------------- --------------
0x00001000 0x2A ; This is where theVariable is placed, it is also the address of theInteger.
0x00001001 0x00
0x00001002 0x00
0x00001003 0x00
0x00001004 0x41 ; This is the address of theCharacter
Now, I've actually lied to you all the time , the sizes and addresses are not computed exactly like this, because the compiler optimizes for running on CPU's that prefer variables to start on certain boundaries.
So the size of our struct would NOT be sizeof(int) + sizeof(char), but rather sizeof(int) + (n bytes) + sizeof(char) + (n bytes).
2. You can't. The compiler takes all your method names and variable names and translates them into addresses. When the code is compiled, there will be no such thing as a class A, the objects exists solely on design time, and besides RTTI, there is no nifty runtime features like the reflection APIs in Java and .NET.
3.Wiltein wrote:
but what I need is the real type,not its name.
But you've allready GOT the real type, otherwise you couldn't get it's name!?...
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|