|
Vicord Chrane wrote:
My question is... Is there also only one shared copy of Normal member-functions (nonstatic and not-inlined, even nonvirtual) for all objects of a given class type?
Yes. There is only one instance of each member function per class. If the function is virtual, each object stores a pointer to the function, but the function itself is only defined once.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Can some one point me to an article that shows you how to enumerate the active internet ports, and retrieve information like the client/host ip and port number, like netstat.exe does on windows
|
|
|
|
|
I have a problem connecting to a server that I'm writing in C.
I'm working on this client program in C, but it can never connect to the server. The Server is coded in C as well, but it is in UNIX, this is for my work. Basically they want me to code the client program in Windows so they can have a windows version running, however, I can never get it to get authorization from the server. The part where it rejects me is below
Code:
// server.c
/* The client makes a simple identification */
if(fgets(line,MAXLINE,fdr) == NULL) goto finish;
/*if(sscanf(line,"%s %s %s",who,passwd,version) != 3) goto finish;*/
strcpy(interface, "stpc");
if(sscanf(line, "%s %s %s %s",who,passwd,version,interface) < 3) goto finish;
// this printf ensures that line has an interface
// for the logs
sprintf(line, "%s %s %s %s\n",who,passwd,version,interface);
if(strcmp(passwd,PASSWD) != 0) goto finish;
fprintf(stplog," %s %s %s",timestamp(),whoami,line);
fflush(stplog);
/* Let the client know we are connected */
fprintf(fdw,"CONNECTED\n");
fflush(fdw);
that was the server portion, and now below is the one I am trying to code, which is in windows.
Code:
fd_rd = _open_osfhandle(ws_sockfd, 0);
if (fd_rd == -1) exit(-1);
ws_fdr= fdopen(fd_rd,"r");
ws_fdw= fdopen(fd_rd,"w");
if( ws_fdr == NULL || ws_fdw == NULL)
err(FATAL,"STP: cannot open ws_fdw/ws_fdr\n");
/* send authorization */
printf("Sending authorization!\n");
sprintf(line,"%s %s %s %s\n","STP",PASSWD,VERSION,"stpc"); // sets line to the ip, password, version, and interface
ws_putline(line);
fflush(ws_fdw);
printf("Authorization sent, awaiting confirmation!\n");
/* get connection acknowledgement */
/*
Below is where we get our
Connection failures
*/
ws_getline(line,MAXLINE);
if(strcmp(line,"CONNECTED\n") != 0) {
err(WARN,"STP: Connection rejected by waveserver - %s\n", line);
continue;
}
Basically it's trying to send the server the info, which are the password, version, interface and STP. and then the server should verify it and then say OK, and copy "CONNECTED\n" into line, and the we should be connected. On UNIX, both the client program and Server work fine. Please help, thanks.
|
|
|
|
|
How can I find out whether MSWord, MSExcel,MS PowerPoint application is open.
I know a function that can tell me whether MSExcel is open or not. However, I dont 'know the Word and PowerPoint application name to find.
<br />
FindWindow("XLMAIN");<br />
Thank you
|
|
|
|
|
FindWindow() would not be my first choice in doing what you want. First, the caption or class of the window can change, or may not be unique, at any time. Second, sending a WM_GETTEXT message to a window whose thread may be blocked could result in deadlock.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
You could use a process viewer, or make one yourself
there is one that comes with Visual Studio 6
if you installed the tools
there are some example ones here at code project
and i recently made one for my self, that lists all open process, and allows you to terminate them, i also added a tab in it to enumerate windows, tell you whether they're hidden or visible, and allows to close/hide/show the window
|
|
|
|
|
I have a fairly complex CArray object built where problems seem to be happening.
The CArray object looks as follows
<code>
class Items
{
public:
Items(){}
Items::Items(const Items &pCopy)
{
operator= (pCopy);
}
Items& Items::operator =(const Items& Array)
{
ItemGroup = Array.ItemGroup;
ItemCategory = Array.ItemCategory;
ItemCode = Array.ItemCode;
ItemDescription = Array.ItemDescription;
ItemAmount = Array.ItemAmount;
return *this;
}
CString ItemGroup;
CString ItemCategory;
CString ItemCode;
CString ItemDescription;
int ItemAmount;
};
class StartingItems
{
public:
StartingItems(){}
StartingItems::StartingItems(const StartingItems &pCopy)
{
operator= (pCopy);
}
StartingItems& StartingItems::operator =(const StartingItems& Array)
{
for(int i=0; i<Array.m_Items.GetSize(); i++)
m_Items.Add(Array.m_Items.GetAt(i));
Era = Array.Era;
Age = Array.Age;
EraCode = Array.EraCode;
AgeCode = Array.AgeCode;
return *this;
}
CArray<Items, Items> m_Items;
CString Era;
CString Age;
CString EraCode;
CString AgeCode;
};
</code>
Then I define the following variable
CArray<StartingItems,StartingItems> m_pItemsMap;
Now when I add StartingItems objects to m_pItemsMap I can see the array growing. But when I add objects to m_pItemsMap[index].m_Items nothing happens. I've noticed that the copy constructor is getting called numerous times in the StartingItems object and when it is called there is nothing the Copy parameter is empty of any values. Kinda like putting stuff in a bag with no bottom. You can see the stuff going in but the bag is always empty.
My adding code is the following
StartingItems pSI;
pSI.Age = AgeDescription;
pSI.Era = EraDescription;
ItemIndex = m_pItemsMap.Add(pSI);
Items pI;
pI.ItemAmount = atoi(Amount);
pI.ItemCategory = ItemCategoryCode;
pI.ItemCode = ItemCode;
pI.ItemDescription = Description;
pI.ItemGroup = ItemGroupCode;
pSI.m_Items.Add(pI);
pSI.Age = AgeCode;
pSI.Era = EraCode;
m_pItemsMap.SetAt(ItemIndex, pSI);
Does anyone see anything wrong? Am i using this object correctly. Obviously I must be doing something incorrectly.
Thanks!
|
|
|
|
|
brchris wrote:
I've noticed that the copy constructor is getting called numerous times in the StartingItems object and when it is called there is nothing the Copy parameter is empty of any values.
I set a breakpoint in both copy constructors. In each instance the parameter pCopy had the expected values.
Setting a breakpoint on the pSI.m_Items.Add(pI) statement, you'll see the m_Items array grow.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Thanks! From there taking the assumption it works fine I noticed an interesting problem.
<br />
m_pItemsMap.GetAt(i).m_Items.Add(Item);<br />
note: I didn't include this in the previous example which was another red flag.
This was the issue. I can't explain it very well, but if I assigned m_pItemsMap.GetAt(i) to a variable of type StartingItems then went
<br />
pSI.m_Items.Add(Item);<br />
m_pItemsMap.SetAt(Index, pSI);<br />
that fixed it. Thanks for the heads up!
|
|
|
|
|
in registry where should i add the variable in order to add
my custom application menu when you select a file and right click
for pop up menu
for folder you have to create a varaible at
HKEY_CLASSES_ROOT\DIRECTORY\SHELL\yourappname\Command
how about for files?
Thanks in advance
|
|
|
|
|
Add a key to HKEY_CLASSES_ROOT\exefile\shell. Under that key, add another key that will show up in the context menu (e.g., Process). Under that key, add a key named command. Change the (Default) value for the command key to the path\name of your application. If your application will require the name of the file that was clicked on, which it most likely will, supply %1 in double quotes.
So if I wanted Process to show up when I right-click an exe file, my registry key would look like:
HKEY_CLASSES_ROOT\exefile\shell\Process\command
For demo purposes, the value for (Default) was calc.exe. Now when I right-click a file and select Process from the context menu, the Windows calculator comes up!
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Thanks for your tip now it works!
But why the value for command always has to come with %1
if you select a number of files what you get is the first file
in argument, right? Is there any switch/option to send all the
parameters to exe?
Thank
|
|
|
|
|
skoizumi29110 wrote:
Is there any switch/option to send all the
parameters to exe?
I believe it is %*.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
unfortunately,
I can't pass to any value with %* option
|
|
|
|
|
skoizumi29110 wrote:
I can't pass to any value with %* option
What exactly does this mean?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
hello. I am trying to make a program that sets a system whide CBT hook withouth the use of
a dll that is attached to all the processes.I am using tyhe CreateThred function to
achieve this.I have already made a program that sets a system whide Keyboard hook and it
works so I know that this method has potential.
I do like this:
this is the main function:
[code]
WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
int c;
MSG msg;
Module = GetModuleHandle(NULL);
CBTlogfile="e:\\zama.txt";
DWORD CBTTID=0;
/* Already installed CBT we have */
if (dejaCBT)
{
MessageBox(GetDesktopWindow(),"CBT deja pornit","oaleao",MB_OK);
}
/* Create thread */
CBTCapThread = CreateThread(NULL,0, CBTThread,NULL, 0, &CBTTID);
if(CBTCapThread == NULL)
{
MessageBox(GetDesktopWindow(),"nu se poate sa se porneasca
CBTul","oaleao",MB_OK);
}
do
{
GetMessage(&msg,0,0,0);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
while((msg.message!=WM_QUIT||msg.message!=WM_DESTROY||msg.message!=WM_CLOSE)!=0);
}
[/code]
This is my thread function:
[code]
DWORD WINAPI CBTThread(LPVOID param)
{
MSG msg;
int i;
/* We are now recieving from CBT*/
dejaCBT = 1;
MessageBox(GetDesktopWindow(),"am ajuns shi aici","sunt ciumeg",MB_OK);
/* Make sure we have a writable file ready */
fd = _open(keylogfile, _O_WRONLY|_O_CREAT|_O_EXCL, _S_IWRITE);
_close(fd);
/* Open the file again for appending */
if ((fd = _open(keylogfile, _O_WRONLY|_O_APPEND)) == -1)
{
MessageBox(GetDesktopWindow(),"nu pot sa deschid fishieru pt
append","oaleao",MB_OK);
return (1);
}
CBT = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTProc, Module, 0);
/* Loop forever and read from CBT */
while (Logging) {
while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
GetMessage(&msg,NULL,0,0);
DispatchMessage(&msg);
}
Sleep(1);
}
UnhookWindowsHookEx(CBT);
CBTCapThread = NULL;
_close(fd);
return (0);
}
[/code]
and this is my hook function:
[code]
LRESULT CALLBACK CBTProc(int code, WPARAM wParam, LPARAM lParam)
{
if(code==HCBT_ACTIVATE)
{
//at the time there is nothing written here and still it doesn't work
//whatever I write here results are the same so let's just say this does nothing
}
return CallNextHookEx(CBT, code, wParam, lParam);
}
[/code]
Now, this program compiles and links flawlessly but when I run it it shut's down the
program it is first run in, for exemple windows explorer or Visual Studio and then it
doesn't do anything. it just sits there.
Please help. Also if you have a better way of doing this I am open to suggestions.
|
|
|
|
|
Is the thread created successfully?
What is the return value from SetWindowsHookEx() ?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Also, you use C runtime library calls in your thread.
If should carefully examine notes about CreateThread versus beginthreadex, you would observe the warning that you should use beginthreadex instead of Createthread to start your threads if you use the C runtime library calls, less you run into init errors and memory leaks.
|
|
|
|
|
|
if all global hook functions must be in a dll how come my keyboard hook works?
SetWindowsHookEx works because I put MessageBox(bla bal bal) inside the CBT hook proc and I got lots of message boxes so I'm guessing it works, I dodn't check what it returns, however the program still crashes the program it is being run from, like explorer and visual studio).
|
|
|
|
|
Hello everyone!
I have an MDI application (using VC++ 6), which utilizes several document templates as well as just dialogs. Recently I started adding the context help feature (just control-related popup windows and the "?" button functionality). It works fine for simple dialogs, but how to add the same to a CView? I have CTreeView-based CView and would like to have the same "?" button there too in order to preserve the UI consistency...
Thank you for help in advance
Mike
Mike
|
|
|
|
|
Hi guys, i'm a final year computer engineering student currently developing a software to extract messages from instant messengers as part of my final year project.
I would need some opinions on the architecture i had researched on. Currently i proposed the popular method of getting the handle of the message window once it is activated retrieve the text from the messagebox. This method is widely implemented i believe, for its simplicity and straightforward programming. My supervisor in charge however commented that this is not very stable as it is too dependent on the application itself. He said a solution that will be less dependent will be better.
I believe another way will be to go into the lower level instead of the application level, such as WinSock, to retrieve the message. However i think this might be too complex and at the end of the day, not that feasible.
Does anyone has any opinions that can help me? Personally i think the first method is still the better one. I would really appreciate anybody who can comment on this such as the pros and cons or even if the 2nd method is viable. Thank you all in advance .
|
|
|
|
|
peachieboy wrote:
Currently i proposed the popular method of getting the handle of the message window once it is activated retrieve the text from the messagebox. This method is widely implemented i believe, for its simplicity and straightforward programming. My supervisor in charge however commented that this is not very stable as it is too dependent on the application itself. He said a solution that will be less dependent will be better.
Agreed. If the window caption or class changed, your method of finding the window would cease to function.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Have you looking into other instant messangers? there are some libraries that you could use that might fill your needs. Look up GAIM, and koPete, and ask the developers.
Those are two instant messangers for unix that come to mind, not saying they are any good. If nothing else you can read their source, and leverage that into the backend for your project. I think they both use some common libraries to do the task.
The above is a suggestion. I'm not clear on exactly what your goal is. It might be useless.
|
|
|
|
|
If I created a class inwhich I grabbed some registry settings and moved them to a memory variable in my class. What is the best way to pass these settings back to the calling main app?
And will the destructor destroy and memory variables when it leaves that class to go back to the calling app?
One last question. How come if I return a pointer to a memory variable, back to the calling app, the destructor does not destroy that. Does this mean that that data will reside in memory until the main app is exited?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|