|
///this is just a part of the code its kinda messy i just starting to learn c++/winapi.
SOCKET m_socket[chatter];
else if(msg==WM_SOCKET)
{
switch(WSAGETSELECTEVENT(lParam))
{
case FD_ACCEPT:
char socknum[30];
sprintf(socknum,"%d",sock);
strcat(socknum,"Connection Detected on socket ");
SendtoChat(socknum);
m_socket[sock]=accept(m_socket[0],NULL,NULL);
sock++;
break;
case FD_CLOSE:
SendtoChat("Closing Detected");
//closesocket(m_socket[1]);
break;
case FD_READ:
char str[1000];
memset(str,0,1000);int ctr=1;
while(ctr!=chatter)
{
recv(m_socket[ctr],str,sizeof(str),0);
ctr++;
}
ctr=1;
while(ctr!=chatter)
{
if(send(m_socket[ctr],str,sizeof(str),0)==SOCKET_ERROR)
{
}
ctr++;
}
SendtoChat(str);
//MessageBox(hwnd,str,"",MB_OK);
//free(str);
break;
}
--------
What i want to do is evrytime someone disconnects.. i wanna know which socket got the disconnection... so when soemone try to request connection i will know which index is available for connection and so i could give that index to the connection requesting.... i can just make a loop until it doesnt get an error to see if someone is connected to it or not but then i dont want it to be unorganized.... and another thing sometimes port scanners connects to a winsock program and fools the program for a legitimate connection so i want it to be more organize so i will know whch connection is legitimate or not
Maybe, is there a way to know if someone is connected to one socket?
I have no idea
|
|
|
|
|
What you try to do is implement yur own homemade connection pool, not an easy task if you are new to working with sockets.
The easiest way to make a program, like what it looks like you are doing, is using blocking sockets and use a new thread for each connection. When a client disconnect from the socket you just close it and ends the thread.
When a new client connect, you just spawn a new thread and talk to the client from that thread...
More advanced ways to do it (and faster and better) is to use async sockets...
Take a look at all the articles here on CP, there are plenty both simple samples and more advanced ones...
- Anders
My PhotosWDevs - The worlds first DSP, free blog space, email and more. Now also with forums
|
|
|
|
|
If you havn't yet, you might want to read the articles by Nishant (at CP) on Winsock including Multithreading.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Okay thnks to both ill try your suggestions
I have no idea
|
|
|
|
|
i need to run a big project including 3 little project .dll
and after to run an .exe file
|
|
|
|
|
dov you want to know how to run a exe from inside a dll
if yes use CreateProcess or ShellExecute or LoadModule . . . us eyour imagination
gabby
|
|
|
|
|
So, view may appear differently? I want to pass some parameter to view, these parameter is created at run time. So how can I pass them to view?
A way to work arround is save those parameter in Doc. But it looks not quite right. I hope I can create CView::CView( int A, int B ) there is CView::Cview() already. so when template create view, pass A and B to view, so CView::CView( int A, int B ) is called, instaed of CView::CView( ). I was stuck, Please help me out.
Thank you inadvance.
|
|
|
|
|
Storing it in the document does make since.
You can pass additional information to the veiw of a particular document via
OnUpdateAll(...,lHint,pHint). The lHint, argument can be long value (or a pointer value stored in a long). The pHint can be used if the addition information is stored in a CObject derive object.
Good Luck!
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
It would be easier to store it in document. In your view's OnDraw just call GetDocument() to get the document and then the parameter and simply write your drawing code depending on the parameter
|
|
|
|
|
wwwrabbit1 already knows how to do that but wanted another way (to pass information to CView object) to accomplish the same thing and that is what the hint parameters are for.
I personaly would contenue to store the information in the document, where it (probably) belongs.
What we do not know is what effect the information is supposed to have, other than they effect what is to be shown.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Hello!
I'm currently writing some application, that contains a class A. It loads a DLL and passes a pointer to A to the DLL. The DLL includes the header file of A.
Anyway, when I try to compile this, I get LNK2001: unresolved external symbol errors for all A class function calls...
When I include all *.obj files as library files in the DLL settings, it compiles. But it doesn't really execute the actual functions of the main application then, it just compiles the whole code again into the DLL. It shouldn't do this, it should just call the real functions of the main application.
What must I do that the DLL can execute the functions of A?
Thanks and best regards,
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
write 0xAD to port 0x64
oh wait...
pass a pointer to the function to the DLL.
I know of no "reverse export" mechanism.
we are here to help each other get through this thing, whatever it is Vonnegut jr. boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
So it's impossible? Isn't there some possibility of generating a .lib file of main app or something like that?
How can I write a plugin architecture then? The DLL must be somehow be able to execute class functions of the main app...
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
Wooo! It is more than possible! The person who has the information at the tip of his tong is just not online. If we have not done anything like that in a while, then we have to try to remember enough to figure it out (if we have the time to go through the trouble).
There are articles at CP on plugins, DLLs and COMM (also in the MSDN Library).
When I first read your post (ealier today) the first thing I thought about was callback functions, but that was not what you where asking about. If you can pass a callback function you can pass a class pointer. Heck we pass class pointers and references to DLLs all the time, otherwise we could not use MFC.
Your question is resonable and someone may yet answer it.
I am no expert on DLLs, so I did not try to figure out what the problem was.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
The person who has the information at the tip of his tong is just not online.
Let's hope he'll get online soon
There are articles at CP on plugins, DLLs and COMM (also in the MSDN Library).
I've read most of them, but actually many of them are for C# only and the others for C++ never have the problem that the DLL wants to call something that is in the EXE. They'll just describe how to load and call a DLL, the DLL then does many things, like creating new windows, sending windows messages, etc. but never calls something of the EXE...
Thanks and best regards,
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
I have looked into this quite some time back and I'm afraid I can't remember what the outcome was, but I vaguely recall it was possible. You need to create a lib for the .exe and use that in the DLL. Also declare the functions as exported.
One issue that comes to mind though is DLL's are (can be) shared by .EXE's so which EXE would the exported function be in. I guess this info lives in the export information.
Another way to do this is for the .EXE to expose an array of functions DLL's can call. You could do this with delegates and probably signals and slots. Have a look at the truly excellent FastDelegate here on CP.
In my programmers editor (see sig) I enabled interpreted C functions to call C/C++ functions in my .EXE. This is done by my C compiler resolving function addresses via. the .EXE's MAP file. This works very well and allows extensions to the editor to do most anything that the .exe can.
Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"
|
|
|
|
|
Also declare the functions as exported.
Doh I've searched the whole IDE, all subdialogs, etc. at least 2 hours for a setting to generate a .lib of the .exe file... Didn't find anything. I have almost given it up and then just prefixed some of the functions with __declspec(dllexport). Compiled it, and think what? It generated the .lib, .exp and exported the functions very nicely as one could see in the Dependency Viewer. Yay!!!
Added the .lib to the test plugin project (the DLL), compiled it, and everything works!!
Many many thanks!!!
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
:-DNot bad at all! An expert did not show up but someone who could get you looking in the right direction did. It never occured to me that you were not using export.
:(Now if I can just understand how to do basicaly the same thing via COM thru the IUnknow interface. Thats what I've been working on.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
John R. Shaw wrote:
Not bad at all! An expert did not show up but someone who could get you looking in the right direction did.
Hey who said I'm not an expert.
Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"
|
|
|
|
|
Neville Franks wrote:
Hey who said I'm not an expert.
You know what I mean!
Some one who writes DLLs all the time and can answer questions about them in his sleep. By that deffinition most of us are not experts on DLLs.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Dominik Reichl wrote:
Added the .lib to the test plugin project (the DLL), compiled it, and everything works!!
Many many thanks!!!
Glad to be of help.
Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"
|
|
|
|
|
Well, the most simple way is to move all 'exported' functionality (i.e. that part of the application the plugins should be able to access) into a separate dll itself. Plugins then just need to link to that dll in order to use them, as does the main application. (This would most likely be done via implicit linkage)
That way you also have enforced a modular concept for your application, which I'd recommend anyway as soon as your appication gets complex.
Many of my bigger projects evolved to a main exe that only served as 'launcher' for the dlls that contain the 'real application'.
Hope that helps,
Nick
|
|
|
|
|
I have a proyect in VC++6, and everytime I change ONE file, when I run the proyect, it asks me If I want to compile all the files in the proyect. If I choose 'No' , the changes I made in that file are not compiled (and linked) in the exe.
If I manually compile every modified file, the problem is that its not linked again (so, I have a new .obj, but the .exe is old).
Obviously, if i choose 'Yes' when it asks me, I have no problems, but it compiles the entire proyect every time I modify 1 file...!!
Please Help me!!
Thanks in advance
|
|
|
|
|
VC++ 6 by default only compiles the files affected by the change, unless you have manualy set to up to do otherwise.
(F7 or Build in menu): Compiles (affected files) and Links (Links entire project).
Unless that 1 file is a header that is used in every file, then the whole project should not be being recompiled. But the whole project will be relinked.
If you do not see in the build window
Compiling...
StdAfx.cpp
...
then it is not recompiling the whole project.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
|