|
I found one answer: CListBoxChat::PreSubclassWindow() is the place to create the fonts
|
|
|
|
|
I'm not very familair with C++, but I'm making a program that acts as a client and server.
I've based my code on one of the examples from this web site (http://www.codeproject.com/internet/winsockintro01.asp). Below is the important part of the code:
UINT MTServerThread(LPVOID pParam)
{
WSADATA wsaData;
sockaddr_in local;
int wsaret=WSAStartup(0x101,&wsaData);
if(wsaret!=0)
{
return 0;
}
local.sin_family=AF_INET;
local.sin_addr.s_addr=INADDR_ANY;
local.sin_port=htons(listenSendPort);
server=socket(AF_INET,SOCK_STREAM,0);
if(server==INVALID_SOCKET)
{
return 0;
}
if(bind(server,(sockaddr*)&local,sizeof(local))!=0)
{
return 0;
}
if(listen(server,10)!=0)
{
return 0;
}
SOCKET client;
sockaddr_in from;
int fromlen=sizeof(from);
while(true)
{
client=accept(server,(struct sockaddr*)&from,&fromlen);
if (client == INVALID_SOCKET)
{
return 0;
}
else
{
cout << "Connection from " << inet_ntoa(from.sin_addr) <<"\r\n";
AfxBeginThread(ClientThread,(LPVOID)client);
}
}
return 0;
}
UINT ClientThread(LPVOID pParam)
{
char buff[512];
int n;
SOCKET client=(SOCKET)pParam;
while(true)
{
n = recv(client,buff,512,0);
if(n==SOCKET_ERROR )
{
break;
}
buff[n]=0;
cout << " Received Message: " << buff << "\n";
break;
}
closesocket(client);
return 0;
}
My problem is at the end of MTServerThread(), it calls the accept method on the socket. If you notice, I echo out the IP of the connection immediately after.
However, I want my program to be able to have multiple connections going on, and output the message with the persons IP address. Because of this, I need to have access to the persons IP address when I output the received message.
I tried creating a struct containing the client socket and the ip address from MTServerThread, and passed it into ClientThread, but for some reason it wouldn't allow me to cast the struct as LPVOID (which I find odd because I thought SOCKET was just a struct).
I may be wrong, but it looks as if accepting the connection is important to the threading of the program since it only spawns a new thread when a new connection is found, so moving the accept method into the ClientThread, thus allowing me access to the IP there is a no-go.
Any ideas how I can have access to the IP matching the received message in a multi-socket program?
|
|
|
|
|
I tried creating a struct containing the client socket and the ip address from MTServerThread, and passed it into ClientThread, but for some reason it wouldn't allow me to cast the struct as LPVOID (which I find odd because I thought SOCKET was just a struct).
This can be done (though some precautions have to be made against memory leaks). Could you please post the code to see where the error is?
I may be wrong, but it looks as if accepting the connection is important to the threading of the program since it only spawns a new thread when a new connection is found...
This is not true; you can happily pass the SOCKET to a different thread and let it call accept on it.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I moved the accept method into the the ClientThread, and asside from some misc. cleanup problems with my error out messages, it's working fine, thanks.
On the struct problems... I took it out of my code when it didn't work. Basically, it said my struct was an improper cast to LPVOID, if I remember correctly.
|
|
|
|
|
at time of accept() is not the only time you can determine the endpoint of your connection. See getpeername().
Signature space for rent. Apply by email to....
|
|
|
|
|
So our build department moved the Source Safe server last night. No problem. To make a long story short, I clicked the "no" button when asked whether to attempt to reconnect to source safe in the future.
Now, for the life of me, I can't get my Visual C++ project to connect to Source Safe. When I right-click on a file in File View, I don't get the option to check in/out files, etc.
Does anyone know of a switch to turn source control integration for a project back on?
Thanks,
Jon Sagara
Help me out here, Spock. I don't speak stupid.
|
|
|
|
|
Can't you just get latest version from server?
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
I tried that. It didn't work. I'm looking for something that exists within VS itself, not within my project. Hopefully that something exists.
Jon Sagara
Help me out here, Spock. I don't speak stupid.
|
|
|
|
|
Got it.
Jon Sagara
Help me out here, Spock. I don't speak stupid.
|
|
|
|
|
Well, I downloaded the sdk for MSN Messenger and Windows Messenger; I wanted to tweak the UI, among other things.
From what I can tell, they don't provide for that functionality, however.
Does anyone know if there is any method other than hacking Messenger to create a new UI for it?
(I guess this would be somewhat similar to skinning, but my UI wouldnt just be a different appearance, but also provide for additional functionality.)
Any help, or links to other web sites that might help me in my research, would be most appreciated.
James A Beggs
Microsoft MSN Mobile Component Test Team
|
|
|
|
|
Is there anyway to force a window created using this command to stay on top of its parent window at all times (kind of app modal)?
However, I have a problem with when other windows overlap the parent window of my message. This message sort of pops up in front of the new dialog as well..
Any solutions?
|
|
|
|
|
Did you try with setting pParentWnd parameter of CFrameWnd::Create to AfxGetMainWnd()?
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
Or did you try with setting pParentWnd parameter to NULL?
|
|
|
|
|
I have written a dll that acts as a central location for a specific data set. I've set the following declaration:
#ifdef __cplusplus
#define EXPORT extern "C" __declspec(dllexport)
#else
#define EXPORT __declspec(dllexport)
#endif
My problem is this. I have an array of data that is built and maintained within the DLL. I have a function that returns a pointer to that data set (array). Upon shutdown of the application, I get the following error:
"dbgheap.c line 1011 _CrtIsValidHeapPoint, or an error accessing the heap"
The trace in debug dumps this:
"Heap Block at c50038 modified at c572e0 past requested size of 72a0"
What I believe is happening is the application tries to clean up, but the memory for this data pointer I have is located in the DLL heap, i.e., not local to the app, causing this error.
I thought I could just free the point in the application and all would be fine, but this is not working at all.
Any suggestions? I have no idea on this one. I thought it might be how I'm declaring the function, or dll as stated above, but that doesn't fix the issue.
Any help is GREATLY Appreciated as I am really lost here. Thanks.
Dan
|
|
|
|
|
It seems that you're freeing blocks allocated on another heap. Are you using C runtime in static library?
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
If you want to allocate memory in a Dll and free this memory elsewhere you can use a GlobalAlloc / GlobalFree ( with the GMEM_FIXED flag you only have to change the alloc and the free lines ).
|
|
|
|
|
Hi
I issued this problem week ago but I still haven't solved it. Now I know a bit more about the nature of the problem. I created MFC program (dialog application) and I'm trying to execute such code:
CBitmap Bitmap;<br />
int a = 0;<br />
SetLastError(0);<br />
a = GetLastError();<br />
if( !Bitmap.LoadBitmap( IDB_BITMAP1 ) ) MessageBox("loadbitmap");<br />
a = GetLastError();<br />
SetLastError(0);<br />
if( !OpenClipboard() ) MessageBox("openclipboard");<br />
a = GetLastError();<br />
SetLastError(0);<br />
if( !EmptyClipboard() ) MessageBox("emptyclipboard");<br />
a = GetLastError();<br />
SetLastError(0); <br />
if( !SetClipboardData( CF_BITMAP, Bitmap ) ) MessageBox("setclipboarddata");<br />
a = GetLastError();<br />
SetLastError(0);<br />
if( !CloseClipboard() ) MessageBox("closeclipboard");<br />
a = GetLastError();<br />
SetLastError(0);<br />
Everything works perfect under Win2000, but under Win98 not, so I installed VC6.0 under Win98 to examine the problem. I don't get any runtime errors, program executes smoothly, but when I try to paste from clipboard (in Paint) nothing appears. When I execute my code for second time Paint shows message "Error in acquiring data from clipboard" (that's my translation from polish version of Windows, so it can be a bit different in english version). Someone advised me to empty clipboard before pasting but it doesn't help Anyone have any clue (this is quite urgent unfortunately). Thanks in advance.
Greetings
Mariusz Popiolek
|
|
|
|
|
I discover something. This problem is not connected with clipboard. When I tried to use Bitmap in another way (I made a Static of type bitmap) it also didn't work, but of course on Win2000 it works:
m_Image.SetBitmap( Bitmap );
Static image is changing on Win2000, on Win98 nothing happens. I don't have any idea
greetings
Mariusz Popiolek
|
|
|
|
|
In your previous example, 'Bitmap' variable was local. And CBitmap destructor deletes the bitmap, so handle passed to m_Image becomes invalid.
What happens on W2K when you invalidate the static window? Does it still show the picture?
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
You are right! But I found this solution on my own when I remembered that it helped a time ago when I was trying to set icons in a CTreeCtrl (of course it was your hint if I remember well, thanks once again). After invalidation picture dissapears on Win2000. When I made Bitmap global on win98 finally bitmap works properly. Thanks anyway, but do you know why this problem occurs (I mean why Win98 behaves different from Win2000 in such basic thing in my opinion).
Greetings
Mariusz Popiolek
|
|
|
|
|
Mariusz Popiolek wrote:
mean why Win98 behaves different from Win2000 in such basic thing
Probably W2K invalidates/updates window right after STM_SETIMAGE.
So you were able to fix the problem with clipboard as well?
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
Yes, after a long period of time (I noticed this issue on previous sunday I suppose), but I wasn't really trying to solve it (I was doing more urgent things, but finally I had to fix it). Now my VBA program works correctly on Win98 and Win2000 (I'm using clipboard to create custom toolbar icons in MSOffice, as far as I know that's the only way and the first thought which came to my mind was to do this in dll, so I can combine bitmaps in one dll).
Greetings
Mariusz Popiolek
|
|
|
|
|
I defined 2 classes - A and B;
class A {
public:
B GetB() {
return B();
}
};
class B {
public:
A GetA() {
return A();
}
};
since both classes make use of eachother, i get an "error C2501: 'A::B' : missing storage-class or type specifiers" when I try to compile.
Is this sort of thing supported with C++?
|
|
|
|
|
Someone else may give a better example but this is possible through inheritance.
class A
{
protected:
int Age;
int GetAge()
{
return Age;
}
};
class B:A
{
int f;
void Foo();
};
Access to the variable Age is available as B inherits A
B b;
b::A.Age;
Nick Parker
The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown
|
|
|
|
|
use a forward declaration:
class B;
class A
{
public:
B GetB();
};
class B
{
public:
A GetA();
};
and put implementation in the .cpp file
|
|
|
|