|
Is your sockets app running on a machine with an IP that is accesible from outside?
Nish
One Nish is trouble enough.
Imagine 16 of me, dancing wild...
:jig::jig::jig::jig:
:jig::jig::jig::jig:
:jig::jig::jig::jig:
:jig::jig::jig::jig:
|
|
|
|
|
Hi!
Can you use a submenu of your dlg's main menu(like edit or file) as a popup menu too, using TrackPopUpmenu()? If so, will the command and updatecommand messages be handled automatically?
NC
|
|
|
|
|
NC wrote:
Can you use a submenu of your dlg's main menu(like edit or file) as a popup menu too, using TrackPopUpmenu()? If so, will the command and updatecommand messages be handled automatically?
Yes you can use a sub menu. The correct handlers will get called too.
Nish
One Nish is trouble enough.
Imagine 16 of me, dancing wild...
:jig::jig::jig::jig:
:jig::jig::jig::jig:
:jig::jig::jig::jig:
:jig::jig::jig::jig:
|
|
|
|
|
Hi!
Thanks for replying. The command msg handler is getting called, but not the Update_UI.. msg handler. Can you think af any reasons why?
Thanks so much,
NC
|
|
|
|
|
I just downloaded some sourcecode from Internet and found this source code requires tlogstg.h, dose anyone know which SDK I should install to have this header file? TIA
|
|
|
|
|
Its part of IE 6.0
I copied this from a page in MSDN.
http://msdn.microsoft.com/downloads/samples/internet/default.asp?url=/Downloads/samples/Internet/libraries/ie6_lib/default.asp
Here is the insert, but you'll need the lib and .dll to go with it.
I got this information by searching for tlogstg on the msdn website. Look there for more info.
[code]
//+---------------------------------------------------------------------------
//
// Microsoft Windows
// Copyright (C) Microsoft Corporation, 1999-2000.
//
// File: Tlogstg.idl
//
// Contents: TravelLog public interfaces
//
// Classes:
//
// Functions:
//
// History: 10-DEC-99 Sifrim (Silviu Ifrim) - created
//
//----------------------------------------------------------------------------
cpp_quote("//=--------------------------------------------------------------------------=")
cpp_quote("// tlogstg.h")
cpp_quote("//=--------------------------------------------------------------------------=")
cpp_quote("// (C) Copyright 1999-2000 Microsoft Corporation. All Rights Reserved.")
cpp_quote("//")
cpp_quote("// THIS CODE AND INFORMATION IS PROVIDED \"AS IS\" WITHOUT WARRANTY OF")
cpp_quote("// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO")
cpp_quote("// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A")
cpp_quote("// PARTICULAR PURPOSE.")
cpp_quote("//=--------------------------------------------------------------------------=")
cpp_quote("")
cpp_quote("#pragma comment(lib,\"uuid.lib\")")
cpp_quote("")
cpp_quote("//---------------------------------------------------------------------------=")
cpp_quote("// ITravelLogStg Interface.")
cpp_quote("")
cpp_quote("#define SID_STravelLogCursor IID_ITravelLogStg ")
import "objidl.idl";
import "oleidl.idl";
// ITravelLogEntry
[
object,
uuid(7EBFDD87-AD18-11d3-A4C5-00C04F72D6B8), //IID_ITravelLogEntry
helpstring("ITravelLogEntry interface"),
local
]
interface ITravelLogEntry : IUnknown
{
[helpstring("Get page title"), helpcontext(0x0000)]
HRESULT GetTitle([out] LPOLESTR *ppszTitle);
[helpstring("Get URL"), helpcontext(0x0000)]
HRESULT GetURL([out] LPOLESTR *ppszURL);
};
//IEnumTravelLogEntry
[
object,
uuid(7EBFDD85-AD18-11d3-A4C5-00C04F72D6B8), //IID_IEnumTravelLogEntry
helpstring("IEnumTravelLogEntry interface"),
helpcontext(0x0000),
local,
]
interface IEnumTravelLogEntry : IUnknown
{
[helpstring("Get the next items in the enumeration sequence"), helpcontext(0x0000)]
HRESULT Next(
[in] ULONG cElt,
[out,
size_is(cElt),
length_is(*pcEltFetched)] ITravelLogEntry **rgElt,
[out] ULONG* pcEltFetched);
[helpstring("Skip over the next cElt elements"), helpcontext(0x0000)]
HRESULT Skip(
[in] ULONG cElt);
[helpstring("Reset the enumeration sequence"), helpcontext(0x0000)]
HRESULT Reset(void);
[helpstring("Creates a copy of the current state of enumeration"), helpcontext(0x0000)]
HRESULT Clone(
[out] IEnumTravelLogEntry **ppEnum);
};
[
uuid(7EBFDD80-AD18-11d3-A4C5-00C04F72D6B8), // IID_ITravelLogStg
object,
pointer_default(unique),
local,
]
interface ITravelLogStg : IUnknown
{
// care on these, they should match TLMENUF_xxx
enum
{
TLEF_RELATIVE_INCLUDE_CURRENT = 0x00000001,
TLEF_RELATIVE_BACK = 0x00000010,
TLEF_RELATIVE_FORE = 0x00000020,
TLEF_INCLUDE_UNINVOKEABLE = 0x00000040,
TLEF_ABSOLUTE = 0x00000031,
};
typedef DWORD TLENUMF;
[helpstring("Insert a dummy entry in the travel log"), helpcontext(0x0000)]
HRESULT CreateEntry(
[in] LPCOLESTR pszUrl,
[in] LPCOLESTR pszTitle,
[in] ITravelLogEntry *ptleRelativeTo,
[in] BOOL fPrepend,
[out] ITravelLogEntry **pptle);
[helpstring("Navigate to an entry"), helpcontext(0x0000)]
HRESULT TravelTo(
[in] ITravelLogEntry *ptle);
[helpstring("Create enumerator for travel log entries"), helpcontext(0x0000)]
HRESULT EnumEntries(
[in] TLENUMF flags,
[out] IEnumTravelLogEntry **ppenum);
[helpstring("Search for all entries with given URL"), helpcontext(0x0000)]
HRESULT FindEntries(
[in] TLENUMF flags,
[in] LPCOLESTR pszUrl,
[out] IEnumTravelLogEntry **ppenum);
[helpstring("Number of entries in the travel log"), helpcontext(0x0000)]
HRESULT GetCount(
[in] TLENUMF flags,
[out] DWORD *pcEntries);
[helpstring("Delete from travel log"), helpcontext(0x0000)]
HRESULT RemoveEntry(
[in] ITravelLogEntry *ptle);
[helpstring("Get entry from the travel log"), helpcontext(0x0000)]
HRESULT GetRelativeEntry(
[in] int iOffset,
[out] ITravelLogEntry **ptle);
};
[/ccode]
Good Luck,
Bill
|
|
|
|
|
Hi Everyone,
I handle/trap the Up-Arrow key press in my CView class. How do I pass along this message so that some of the other classes are also aware that the Up-Arrow key has been pressed? For example I want both the CView and my data grid class to handle this message.
Any help is greatly appreciated.
Thanks,
Al
|
|
|
|
|
In general, you can post the message to the target control/window. You should ensure that doing so won't cause an infinite loop.
CMyView::OnKeyDown
(UINT nChar,
UINT nRepCnt,
UINT nFlags) {
targetWnd.PostMessage (WM_KEYDOWN, ...);
} /ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
The loop condition would occur if the target window also passed the key stroke to MyView. The way to avoid the loop is to send a different message. In the target window, catch Keydown and call the handler for uparrow. Mirror this process in the other window.
in Window 1
OnKeyDown
If key is UpArrow
call OnUpArrow
post UPARROW message to window 2
OnUpArrow
Do whatever
In Window 2
OnKeyDown
If key is UpArrow
call OnUpArrow
post UPARROW message to window 1
OnUpArrow
Do whatever
Hope this helps,
Bill
|
|
|
|
|
if I have to pass a runtime class to a function:
RUNTIME_CLASS(CMyForm)
does this mean i have no way of setting initial values for this class? this class needs to take in a filename, as well as some other parameters.
is the only way to do this by setting global variables before passing the runtime class, and then having the runtime class read from the global variables? This sounds like a bad idea for OOP, is there a better way?
thanks in advance!
-dz
|
|
|
|
|
Hi!
Could anybody suggest a good book on C++ which concentrates on classes, templates and other cool c++ specific stuff? I need an intermediate level book, not for a beginner and not for a C++ expert either.
Thanks,
NC
|
|
|
|
|
Do you know Bruce Eckel's Thinking in C++? I don't know if it's your target type of book, but as it is downloadable for free you might want to have a look at it.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi!
Thanks for replying.
I just looked at the table of contents. I was looking for something like that itself. Would you happen to know of any books with emphasis on Templates and STL?
Thanks,
NC
|
|
|
|
|
Then you probably want Stroustrup's "The C++ programming language"
I myself think the book is rather boring, and it is definitly not something you want to read straight through. It is, however, probably the best book if you really want to understand the language, and it's a great reference.
/moliate
|
|
|
|
|
Hi,
Try "C++ How to Program", Deitel & Deitel. Probably covers most of what you need.
|
|
|
|
|
Please read the following sample code:
In CTestDlg....
BOOL CTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
.
.
.
// TODO: Add extra initialization here
mp_Server = (CServer*)
AfxBeginThread(RUNTIME_CLASS(CServer), THREAD_PRIORITY_NORMAL,
0, CREATE_SUSPENDED);
mp_Server->ResumeThread();
return TRUE; // return TRUE unless you set the focus to a control
}
void CTestDlg::OnOK()
{
// TODO: Add extra validation here
char buff[1024];
strcpy(buff, "This is a test of Simple Socket");
CSocket Client;
Client.Create();
Client.Connect("127.0.0.1",5001);
Client.Send(buff,strlen(buff));
}
In CServer.....
int CServer::Run()
{
// TODO: Add you specialized code here and/or call the base class
char buff[1024];
strcpy(buff, "This is the look before receive the socket");
CSocket socket;
if ( svrSocket.Accept(socket))
AfxMessageBox("Socket is created Succesfully");
socket.Receive(buff,sizeof(buff))
AfxMessageBox((CString)buff);
return 0;
}
This is a sample code for CSocket (posted by my professor in university). But I don't quite understand how CSocket works. When I execute the program, a dialog pop up, and a message box "This is the look before receive the socket" pop up. When I click OK button, it will pop up "Socket is created Successfully" and then "This is a test of Simple Socket".
However, when I click the OK button one more time, there is no response!!! I can put a AfxMessageBox() in OnOK(), and I found that there is execution in OnOK() at that time (messagebox pop up). Why Run() doesn't do anything as I did send the socket to there.....
Please help!!!!
|
|
|
|
|
It's difficult to say without the full source code, but could it be that the thread has terminated, so it can not respond to the "Connect..." ?
in other words, once the run exits, the thread disappear, and there is no more server .
this line:
if ( svrSocket.Accept(socket))
is probably blocking your thread waiting for a connection, thats the reason it only works once.
Andres Manggini.
Buenos Aires - Argentina.
|
|
|
|
|
Thanks for your reply!!
So, if i add a loop to contain "if ( svrSocket.Accept(socket))", then i can ask Run() to keep checking if there is more socket arrived.......is that right?
Also, how the parameter in this function "Client.Connect("127.0.0.1",5001);" come from?
ONe more question, can the Run() in CServer can block the process in OnOK() after Run() receives a socket from OnOK(). For example, OnOK() sends a socket to Run() and "if ( svrSocket.Accept(socket))" receives it. Because how some information from this socket(or packet), Run() has to block (or pause) the process in OnOK()....can it do happen?
|
|
|
|
|
ChiYung wrote:
So, if i add a loop to contain "if ( svrSocket.Accept(socket))", then i can ask Run() to keep checking if there is more socket arrived.......is that right?
Yes, that's correct.
ChiYung wrote:
Also, how the parameter in this function "Client.Connect("127.0.0.1",5001);" come from?
first string is the IP Address, since the computer is connecting to itself, it's using 127.0.0.1 which is the same as localhost (or THIS computer
ChiYung wrote:
ONe more question, can the Run() in CServer can block the process in OnOK() after Run() receives a socket from OnOK(). For example, OnOK() sends a socket to Run() and "if ( svrSocket.Accept(socket))" receives it. Because how some information from this socket(or packet), Run() has to block (or pause) the process in OnOK()....can it do happen?
I am not quite sure to understand the question, but i'll tell you this, if
CServer is running on a different thread it shouldn't block OnOK(), but, OnOK will be blocked cause of :
CSocket Client;
Client.Create();
Client.Connect("127.0.0.1",5001);
Client.Send(buff,strlen(buff));
So, OnOK will be blocked until Client.Send(..) returns.
Hope this clarifies a bit, if you have more questions, post them here.
Andres Manggini.
Buenos Aires - Argentina.
|
|
|
|
|
THANK YOU VERY MUCH!!!!! YOU GAVE ME LOTS OF HINTS!!!!
Andres Manggini wrote:
I am not quite sure to understand the question, but i'll tell you this, if
CServer is running on a different thread it shouldn't block OnOK(), but, OnOK will be blocked cause of :
CSocket Client;
Client.Create();
Client.Connect("127.0.0.1",5001);
Client.Send(buff,strlen(buff));
So, OnOK will be blocked until Client.Send(..) returns.
Ok....how can i prevent Client.Send(..) returns..... is it suspend the thread of Run()...or......
Maybe I give you more detail....
I need to implement a DBMS program that simulate the Lock management. I use socket in CServer to implement the scheduler that handle the lock. It is one thread...... then there are hundreds of users to "access" the database object, so there are hundreds of threads. Each threads(uses) requires to get a lock permit from scheduler (CServer) in order to "access' the DB Object. This is what i'm going to do.
Why I need to block some process, because for example, thread A is trying to access the DB Object X, while thread B is reading something in Object X. Scheduler (CServer) requires to "block" thread A until thread B finished. At this time, thread A will be put in "waitqueue" (this is another issue).
|
|
|
|
|
ChiYung wrote:
THANK YOU VERY MUCH!!!!! YOU GAVE ME LOTS OF HINTS!!!!
Great .
ChiYung wrote:
Ok....how can i prevent Client.Send(..) returns..... is it suspend the thread of Run()...or......
Do you mean prevent Client.Send even after all the data has been sent ?
Cause, if you just want to prevent the return UNTIL all the data has been sent, that's already how it works, so don't have to do anything.
Andres Manggini.
Buenos Aires - Argentina.
|
|
|
|
|
Andres Manggini wrote:
Do you mean prevent Client.Send even after all the data has been sent ?
Cause, if you just want to prevent the return UNTIL all the data has been sent, that's already how it works, so don't have to do anything
I think I want the CServer to....let say suspend awhile (e.g. 20s) before the OnOK() receives the return signal from Client.Send()...........(it can make the OnOK() to suspend 20s too....right?
Sorry...I know I'm stupid.....;P
|
|
|
|
|
I don't know of you can do that just with the CSocket methods, i guess you'll have to implement a form on synchronization between the server and the clients..
maybe using socket as well, set up a small protocol between server and client to communicate (protocol as defined messages sent to each other)
not sure this is the solution for you here..
And.. you're no stupid, far from it .
Regards,
Andres Manggini.
Buenos Aires - Argentina.
|
|
|
|
|
To avoid blocking sockets you might want to use CAsyncSocket in place of CSocket.
Nish
One Nish is trouble enough.
Imagine 16 of me, dancing wild...
:jig::jig::jig::jig:
:jig::jig::jig::jig:
:jig::jig::jig::jig:
:jig::jig::jig::jig:
|
|
|
|
|
Anyone know how I can take a dialog box with 3 buttons that have no function at all and change the background colours of 2 of them to red and one gray??
Thanks.
|
|
|
|
|