ktsangop 23 Junior Poster in Training

That's it!
I can't thank you enough pritaeas!

Not important now but, as far as i understand this could be done also with LEFT JOIN as you mentioned before right?
I' ll try it myself just for practice... I won't bother you anymore!!!
:)

Thanks again!

ktsangop 23 Junior Poster in Training

Of course!
This is the TransactionLog table but the names are quite different.

pcname = PCNum
gameday = Vardia
player = Customer
for credit_a use trans_in and ommit the other SUMS just one is enough to check the validity

ktsangop 23 Junior Poster in Training

Tried:

LEFT JOIN TransactionLog AS t2
    ON t1.gameday=t2.gameday AND t2.player=t1.player

But no luck. Same results.

Sorry for being boring!
:S

ktsangop 23 Junior Poster in Training

All right i tried this one :

SELECT 
    t1.PCNAME,
    t1.player, 
    SUM(t1.credit_a) AS SumA, 
    SUM(t1.credit_b) AS SumB, 
    SUM(t1.credit_c) AS SumC, 
    SUM(t1.credit_d) AS SumD, 
    t1.gameday
FROM TransactionLog AS t1 
LEFT JOIN TransactionLog AS t2
    ON t1.PCNAME=t2.PCNAME
WHERE t1.player IN ('NICK', 'PETER')
AND t1.gameday IN (
    SELECT * FROM(
        SELECT DISTINCT gameday
        FROM TransactionLog 
        ORDER BY gameday DESC LIMIT 3) 
    alias)
GROUP BY t1.player, t1.gameday
ORDER BY t1.player, t1.gameday DESC

But it is completely wrong...
:S
The sums are wrong and the PCNAME is shown in the same way as before.

ktsangop 23 Junior Poster in Training

I would like a little more help regarding the above query.
:)

I want to add the PCNAME column in the SELECT statement, so as to be able to see in which PC was the player logged in the last time he played.

If i just add the PCNAME in the SELECT statement, it does not correspond to that.
On the contrary, i get a "kind of random" PCNAME in which the player was logged. By random i mean one of the PCs he was logged but not the last one, in respect to the GAMEDAY column.

Is there any way to achieve that?

Below is a query response in accordance to the data table i provided above:

data3

The marked in red cell is wrong. Although NICK was logged both in PC23 and PC16, it was PC16 the last one he did on gameday 5.

So my question is how does mysql pick the PCNAME and how can i change it.

I hope i made it clear enough, thanks in advance!

ktsangop 23 Junior Poster in Training

Wooow that was fast!!!!

Though i got a weird error at once:
Error Code: 1235. This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'

After a fast search i changed it to: (Don't ask me why i wouldn't know!)

SELECT 
    player, 
    SUM(credit_a) AS SumA, 
    SUM(credit_b) AS SumB, 
    SUM(credit_c) AS SumC, 
    SUM(credit_d) AS SumD, 
    gameday
FROM TransactionLog
WHERE player IN ('NICK', 'PETER')
AND gameday IN (
    SELECT * FROM(
        SELECT gameday
        FROM TransactionLog 
        ORDER BY gameday DESC LIMIT 3) 
    alias)
GROUP BY player, gameday
ORDER BY player, gameday DESC

This one worked BUT result set was only for the last gameday so i added the DISTINCT keyword and voila!

SELECT 
    player, 
    SUM(credit_a) AS SumA, 
    SUM(credit_b) AS SumB, 
    SUM(credit_c) AS SumC, 
    SUM(credit_d) AS SumD, 
    gameday
FROM TransactionLog
WHERE player IN ('NICK', 'PETER')
AND gameday IN (
    SELECT * FROM(
        SELECT DISTINCT gameday
        FROM TransactionLog 
        ORDER BY gameday DESC LIMIT 3) 
    alias)
GROUP BY player, gameday
ORDER BY player, gameday DESC

Thanks very much!
I admire the way database developers think. I couldn't figure it out although i know all of the functions you used here...
:)

I have another one quite simpler, but i will try it myself first and then maybe i'll come back with another question!
^_^

ktsangop 23 Junior Poster in Training

Hi everyone, i would like some help with a couple of mysql queries.
I have a table of data which looks like this :
grid1

And represents a transaction log for players of a game.

The ID is the primary key (auto incremented).
DATETIME is the date and time of the transaction.
USERNAME is useless. :D
PCNAME is a description of the physical computer in which the player was when the trasaction was made. MAX number of PCs is 30 so values can be PC1-PC30.
PLAYER is the name of the player.
CREDIT_A, B, C, D are game values, all Unsigned integers.
GAMEDAY is a value representing the virtual "in-game" DAY.

What i want to ask the Database is :
Given a list of player names (PLAYER column) , lets say (NICK, PETER), calculate the SUM of each credit type (CREDIT_A,CREDIT_B,CREDIT_C,CREDIT_D) for the last 3 game days (GAMEDAY) and show it seperately for each of those gamedays.
So the resulting table will look like :
grid2

Can i achive it somehow?

Thanks in advance!

ktsangop 23 Junior Poster in Training

Hello i'd like to ask a quick one.

-Mfc VC++ 6 application.
-NO Unicode support by design.
-Greek characters appear fine in all dialogs since OS is Windows Greek version (?)
-Greek text is both hard coded in c++ source files and retrieved from mysql database.
-ONE specific Edit Box combines mysql data with greek text and hard coded in source files strings, to form a kind of report, and print it on paper.

but:

If i copy text from an Edit Box and paste it in notepad for example, the greek characters appear scrambled.
If i print on paper the contents of the specified Edit Box, the greek characters appear scrambled.

and :
If i print to pdf using pdfcreator the contents of the specified Edit Box, the greek characters appear OK!
If i output the contents of the specified Edit Box to a txt file using CStdioFile class, the greek characters appear OK!

I cannot re-build with _UNICODE macro defined because there are hundreds of code lines that need to be changed to support wide character strings. I just want that specific edit box ONLY to be printed correctly in paper...
:S

Thanks!

ktsangop 23 Junior Poster in Training

How do you know your threads are done computing before your main function starts printing their values?

You have to implement some kind of signaling between the threads and the main function.
Perhaps use a global volatile BOOL variable e.g. ThreadIsDone; set it FALSE when the thread starts and TRUE when the computations are done.

Then place the ThreadIsDone evaluation inside a while loop to get informed when the thread is done before starting printing data.

Your code is working by luck, for values < 90000.

You could also check WaitForSingleObject winapi function in msdn.

ktsangop 23 Junior Poster in Training

Hello everyone!

I have a rather mysterious problem.
I have a mfc dialog based application (running on win xp sp3), and at the same time another mfc app that installs a global keyboard hook capturing the ESC key (this one is always hidden).

SOMETIMES when i press ESC key (with the dialog based application on top + focused) the dialog closes normally but it seems like it never returns the focus to the desktop (or any other window that is shown on screen).

I realize that because the keyboard hook does not respond to the ESC press after that UNLESS i click with my mouse on some desktop area.
:S

Is this something that should happen at all??
Can it be that when a dialog is destroyed the focus is lost for the entire desktop??

Not really hoping for a definete answer but maybe someone has faced a similar problem.

Thanks in advance!

ktsangop 23 Junior Poster in Training

As for worker threads, you can put a message pump into them so that they can receive messages. Not usually done though.

Nice to know that.

Anyway i found this:
http://forums.codeguru.com/showthread.php?393149.html
and it seems to work. SetTimer actually works on a CWinThread, i just had to override it and declare a message map. I thought since it was not a class member it wouldn't work but it does!

I just hope it doesn't blow up in my hands eventually!
:)

Thanks for the insight!

ktsangop 23 Junior Poster in Training

CreateTimerQueue

Perhaps CreateTimerQueue, CreateTimerQueueTimer, DeleteTimerQueueTimer would do what you want. Plus it's easy to wrap them into a class.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682483%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms687003%28v=vs.85%29.aspx

Thanks i will try that.

Not to worry, SetTimer() is a global win32 api function, so just call that in CWinThread.

Did try it but no WM_TIMER messages ever arived in the PreTranslateMessage.

Messages are thread specific, one thread can not get another thread's messages. See Remarks here

I don't want to get another thread's message. I want my CWinThread to be able to accept messages through PostThreadMessage.

CWinThread is not going to help you with that. Just create a worker thread and call PostThreadMessage()

I think not. Worker threads have no message queue as far as i understand.

ktsangop 23 Junior Poster in Training

Hello everyone.

As the title suggests i need to implement a type of timer based function inside a UI Thread in MFC.
Although CWinThread is a UI Thread and has a message pump it does not have a Timer function as CWnd::OnTimer

Is there any way i can implement a timer based function inside a CWinThread, being also able of course to accept messages coming from other threads?

I tried using a while loop (with or without a Sleep() call) inside CWinThread::Run function but it appears that this technique is preventing the messages to be received. (I've overriden PreTranslateMessage and it's never being called)

I also tried to utilize the CWinThread::OnIdle but the results are kind of the same.

In conclusion there is no way to implement a timer based check inside a CWinThread and be able to receive messages from other threads at the same time.
Or is it?

You could ask me why i do not use a worker thread instead (since i don't actually create any graphical content inside my CWinThread), but i would like to send messages to the thread, and avoid using shared/global variables for communication.

So is there anyway to handle this?
I would like any suggestions.

I hope my description is clear enough.
:D

Thanks in advance!

ktsangop 23 Junior Poster in Training

I am updating a legacy application. It's really difficult to transfer the project to VS 2012.
I just wanted something similar to .net's data binding technique to help me going.

If noone else has any suggestions then case closed.

Thanks a lot!

ktsangop 23 Junior Poster in Training

Thanks, but it is not any different.

I would like to avoid this kind of coding for example :
http://www.softwareandfinance.com/Visual_CPP/MFC_CListCtrl_InsertColumnItem.html

Having to create loops to identify and insert each row and column of the data set.

I am looking for something like this from .net
http://csharp.net-informations.com/datagridview/csharp-datagridview-sql-server.htm

a DataSet-like object.

I know it's probably too much for an outdated tool like that...
:)

Thanks.

ktsangop 23 Junior Poster in Training

I've been trying Mfc Grid Control from codeproject but i can't find it any more helpful than the standard List Control.

What i really need i suppose, is an easy way to insert sql query results to the grid.
I know how to do it the hard way, but i would rather not!
:)
I think i am missing something really essential. It can't be that hard...
:S

ktsangop 23 Junior Poster in Training

Hello everyone!

I am building a mfc dialog based application in visual c++ 6 and using mysql c api to connect to a database.

What i need is a simple type of data grid to show mysql query results in a dialog.
I do not need to edit, update, save etc data from the dialog. Just show them on screen.
I've checked libraries such as Ultimate Grid but they seem really complicated for my needs.

I would prefer using built in mfc controls but don't really know if there are any suitable.
Is there anything you could suggest as a simple approach to this problem?

Thanks in advance.

ktsangop 23 Junior Poster in Training

Listen to WaltP.
Forget my answer, i didn't read your code carefully!
:-S

this will help you i suppose :
http://www.cplusplus.com/reference/iostream/ifstream/

ktsangop 23 Junior Poster in Training

All your function declarations have the file path variable as a char argument.
for example :

double slopec (double dinner, double douter, char inputfilename)

But the char variable holds only one character. and you declare inputfilename as:
char inputfilename[50];
which is a 50 character array.

So first of all read this first and try to replace char arguments with either char arrays or pointers.

http://www.cs.bu.edu/teaching/c/string/intro/

ktsangop 23 Junior Poster in Training

Have you tried to open NameOfProject.rc file with a text editor to see its contents?
If no, this file usually reside to the NameOfProject\res\ directory.

Open it with notepad and search for IDR_MAINFRAME declaration.

There should be a line something like :

IDR_MAINFRAME           ICON    DISCARDABLE     "res\\NameOfProject.ico"

Also in the costructor of your main Dialog there should be a line like :

m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

And finally there it should be defined in your resource.h file :

#define IDR_MAINFRAME                   128

I bet LoadIcon is not called, since on both of the other occasions you would have a compilation error or something..

Good luck!

ktsangop 23 Junior Poster in Training

In the end i was too bored to backup my files, so i did this:
Installed Windows 7 from dvd, and chose to format only C: partition so that the other ones where left un-touched.

I don't know if the restore partition can be used now but at least i skipped the boring backup process...
:)

Thanks for the answers!

ktsangop 23 Junior Poster in Training

I 've searched on hp's support site but it's a bit blurry over there too...

I would backup my data, if i had any free space.... :D but for the time being it's not an option. Neither is burning discs for 120GB.
:S

Thanks

ktsangop 23 Junior Poster in Training

Thanks mate..
Any other suggestions would be thankful!
anyone ever tried it actually?

ktsangop 23 Junior Poster in Training

Hello everyone,

I would like to use HP's system recovery (F11 on boot menu, not the windows application) to revert my laptop to its factory state.
The thing is that i have created a disk partition to keep my data which wasn't present by default.

Will the recovery delete my partition or will it simply re-install windows on system (C:) partition?
(Laptop model is HP compaq 6730s)

Thanks in advance!

ktsangop 23 Junior Poster in Training

Ohhh shooot...
Just figured it out! Always do, a couple of minutes after i post...

I had to change the current working directory, or else the java app cannot find the java libraries etc...

Just Added : SetCurrentDirectory("c:\mypath\etc\");
and problem solved...

Thanks and sorry for the waste of bytes..
:)

ktsangop 23 Junior Poster in Training

Hi everybody!

I am having some trouble running a detached process using CreateProcess function in C++.

I have been using the following function to spawn processes in c++ for years now havnig no trouble. I have used it with console applications, mfc apps, dialog based ... etc :

StartProc(char *callprogram, bool blshow)
{
        //callprogam = full path to executable
        //blshow = show or hide application's window
         STARTUPINFO startInfo;
         PROCESS_INFORMATION procInfo;
         DWORD       creationFlags;
         startInfo.cb = sizeof(STARTUPINFO);
         startInfo.lpReserved = NULL;
         startInfo.lpDesktop = NULL;
         startInfo.lpTitle = NULL;
         startInfo.dwFlags = STARTF_USESHOWWINDOW;
         if (blshow==true) startInfo.wShowWindow = SW_SHOW;
                 else startInfo.wShowWindow = SW_HIDE;
         startInfo.cbReserved2 = 0;
         startInfo.lpReserved2 = NULL;
         creationFlags = DETACHED_PROCESS | NORMAL_PRIORITY_CLASS;
        //-----------------
                 printf("%s",callprogram);
        if( !CreateProcess(NULL,callprogram, NULL, NULL, TRUE, 
        creationFlags, NULL, NULL, &startInfo, &procInfo) )
            AfxMessageBox("Process create failed",MB_ICONERROR, NULL);
}

For the first time i have trouble executing a java application which is wrapped to an executable using jsmooth.
CreateProcess returns no errors but the java app exits immediately after creation.

The java application is a fullscreen application using Java OpenGL wrapper.

I messed around with dwFlags and creation flags but no luck...

Any advice?
Thanks in advance.

ktsangop 23 Junior Poster in Training

Actually i have found a great class which does what i want here :
Redirecting an arbitrary Console's Input/Output

I have tested it with thsark and it seems pretty robust.
It uses pipes to redirect both stdin and stdout of a process that is created as a child.

Haven't fully understood yet how the waiting/buffering system works between the parent - child processes but it seems that the parent waits until the console can send it's output.

When i set tshark's output to packet mode (each packet is flushed by itself) then after each packet, the console passes the handling to the parent which is free to do whatever computing necessary.

If set tshark's output to continuous stream mode, then the console passes the handling to the parent when a certain buffer (this is what i didn't understand yet) is full and the console's output is forced to be flushed.

The size of that buffer is little more than 4Kbytes (!?), and here is an article that describes how it works :
CreateNamedPipe function

Just wanted to share the above knowledge to anyone interested in the topic.
Any comments on the buffering system are still welcome, though i found my solution.

Thanks for helping me out!

ktsangop 23 Junior Poster in Training

I am sorry but could you be more specific please?

Do you suggest that i execute it like that :

> thsark -parameters | MyApplication.exe

so i can redirect tsharks ouput to my application?

The thing that bothers me mostly is how i can keep the continuous stream of tshark' s data open and read from it without closing the pipe or whatever connects them even once in while, and thus loosing data...?

I can't figure it out in my head. I am looking for an algorithmic approach, not a coding practice. Sorry if i wasn't clear enough.

By the way i found a nice example on pipe-ing. Anyone interested in the subject could read it:

Microsoft : Standard Input/Output Redirection

ktsangop 23 Junior Poster in Training

Hello everyone!

I want to monitor my network using wireshark 's tshark command line tool.
What i want to accomplish is to redirect tshark's output to a c++ application, so i can examine data and output a more comprehensive analysis without keeping a huge amount of data.

I am working on windows, and usually code in mfc. So i would like any info on how to get the command line stream into my program, in order to analyze it.

Anyway, all i want, is tips on how to get a continuous stream of data from a command line application.

Any help appreciated.
Thanks!

ktsangop 23 Junior Poster in Training

Hi everyone!
I have a quick question.

Is there any way i can update python package for cygwin manually?
The setup.exe which handles cygwin installation and updates, prompts me to update the whole cygwin installation to 1.7.x but i would like to keep using the older version (1.5.25).

I only want to upgrade to the newest python available for cygwin.

Thanks in advance!
:)

ktsangop 23 Junior Poster in Training

Hi everyone!

I'm having trouble on my hp laptop.
The system won't post, instead i get a blank screen and CAPS LOCK + NUM LOCK leds blinking twice, then pause, then blinking twice repeatedly.

According to hp support website this indicates : BIOS CORRUPTION
http://h10025.www1.hp.com/ewfrf/wc/document?lc=en&dlc=d&cc=dk&docname=c01443366

So i tried to clear CMOS the old way (remove CMOS battery etc...) but no hope.
After research i found out that the new UEFI/BIOS system stores extra information on a hidden hard drive partition and there is no documented way to flash your bios outside windows, neither on hp's website nor on Insyde's.

[I][B]from Wikipedia : [/B][/I]
Extensions to EFI can be loaded from virtually any non-volatile storage device attached to the computer. For example, an original equipment manufacturer (OEM) can distribute systems with an EFI partition on the hard drive, which would add additional functions to the standard EFI firmware stored on the motherboard's ROM.

Googling around i found that there is an emergency bios recovery method using a usb flash drive on boot.

http://www.bios-mods.com/forum/Thread-Recovering-From-A-Bad-Insyde-Bios-Flash

Anyway after a lot of struggle finding the right BIOS images etc, i couldn't manage to recover my BIOS.
According to the procedure mentioned above and on other websites when bios recovery completes the machine would shut down.
Mine doesn't...
:(

So i am pretty sure that, either i got the wrong bios file (quite impossible as i downloaded all available versions from …

ktsangop 23 Junior Poster in Training

easier still (and much more secure) to just buy one of the plethora of available commercial products to handle license key generation and distribution...

Unfortunately this is not an option. I already have a USB dongle in order to lock the application and buying also another type of commercial security product would raise the cost too much.

And it's a lot more fun having to do this on your own!
Either way if someone wants it really bad, he will "crack" it.
:)

ktsangop 23 Junior Poster in Training

Since my licences are 4 : 15, 30, 60 and 90 days i think that i could bitshift the Activation key by 3, 6, 9 and 12 digits respectively and provide a tottaly different key which includes the days of licence.

The client side algorithm will try the four bitshift operations and compare the resulted keys with the original activation key wich includes no licence days.

The shift operation that succeeds will provide also the days of licence.

I think that this level of security is pretty enough for the licence days, since in any way, the number of days could not be more than 90.
The worst that could happen is that a given licence of 15 days will be "hacked" and give the client 90 days.

Well good luck hackers!
:)

Thanks again Greywolf333

ktsangop 23 Junior Poster in Training

Well that's what i was looking for!
I've never implemented anything like that so this guide is definetely a useful starting point!

In fact, i already made an algorithm using bitwise calculations on paper.
:)

... often with cool techno music to accompany it.

Still laughing!!!Hahaa!!Btw why do they always do that??

One last question...
I would like to "include" the days of the new licence in the activation key.
Is it too obvious if i place for example 50 days of licence like this:

Key : 923024903113993
Activation : 92302490(50)3113993

of course without the parenthesis!!
:)

Thank you very much!

ktsangop 23 Junior Poster in Training

Sorry i didn't make that clear.
The user is responsible of sending me the key via phone, sms or even email but this has nothing to do with the application. The machine on which the application runs could have no internet access.

I'll try to break it down.

Let's say you gave me a key number like 584663214796.
And this number contains a "hidden" information of how we both should compute the activation number. So i calculate it using my private app, and send it back to you.
You compare the number i sent you with your calculation and if they match.. licence is updated.

ktsangop 23 Junior Poster in Training

Hello everyone!
I want to add a licence expiration feature in my application (written in visual c++).
When the licence expires i would like my application to generate a random numerical key which will be sent to me by the user.

Using this key and a personal key-generator i would like to send back to the user an activation code.
The key/activation-code combination should not be stored anywhere in either sides. They must be as random as they can get.
The user should not need any kind of internet connectivity (my previous activation was web-based and i want to remove it).

What kind of algorithm can i use?
I would like some guidelines or any links to useful information if available.

I am not looking anything that is related on how i could "lock" my application with third party software or anything that has to do with hardware serial numbers etc...

Thanks in advance!

ktsangop 23 Junior Poster in Training

Ohh shoot...!
I always get the best ideas after posting a question..
:)

For anyone iterested i went to :
Flash Player 11 Support
and downloaded :
1.Windows Flash Player 11.0 Projector content debugger
2.Windows Flash Player 11.0 Projector
And placed them respectively to :
1. C:\Program Files\Adobe\Adobe Flash CS5.5\Players\Debug\ (rename it to FlashPlayerDebugger.exe)
2. C:\Program Files\Adobe\Adobe Flash CS5.5\Players (rename it to FlashPlayer.exe)
and C:\Program Files\Adobe\Adobe Flash CS5.5\Players\Release (rename it to FlashPlayer.exe)

Hope that helps someone else too...!
:)

ktsangop 23 Junior Poster in Training

Hello everyone.

I am trying to publish a win projector (.exe) for a flash project using CS5.5 and Flash Player 11.
I downloaded the following extension :
Flash Player 11 support for CS5

and therefore i can use Flash Player 11 in publish settings.

When i publish swf and load it on browser the browser detects the version correctly and uses flashplayer 11.

But when i publish it as windows projector (.exe) it keeps using flash player 10.

Is there anything i can do to force the projector to use flash player 11 or i must wait for CS6?

Thanks in advance!

ktsangop 23 Junior Poster in Training

For what is worth i switched to udp sockets and solved my problem using the following library which i found extremely helpful.

Practical Sockets

Thanks for the help!

ktsangop 23 Junior Poster in Training

Thanks for the answer. I have no experience with socket programming so my code is mostly from tutorials.

I changed my code but still i get the same error when connecting with my client, but not with an external TCP tester i downloaded. Now it seems that i should change my client.

I think that my client shouldn't terminate/destroy the socket either but it's really hard to change the structure of my client now..
:(

I will try to work around this and if i find anything intersting i will post it.
Else, i will just mark this thread as solved sooner or later..

Any other suggestions still welcome..

Thanks!
:)

ktsangop 23 Junior Poster in Training

Hi there!
I would like a little help regarding the following code.

The following code will wait for a non-blocking socket connection, and then wait to receive a certain packet. When the packet arrives, it will do something and then close connection and reinitialize it in order to be able to accept again. The client side closes it's connection also that's why i completely shutdown this one's also.

The problem is that the first time of the loop the operation is successful, but on second attempt, it cannot accept a socket connection and blocks on accept().

On client side i when i try to connect second time, i get a WSAECONNREFUSED error.

I am quite sure that this is the server's side problem because i used a couple of TCP socket testers available online and they all get a connection refused on the second attempt. That's why i didn't post the client side.

while(1)
{

	WSADATA WsaDat;
	if(WSAStartup(MAKEWORD(2,2),&WsaDat)!=0)
	{
		TRACE("---------WSA Initialization failed!----------\r\n");
		WSACleanup();
		return 0;
	}
	
	SOCKET Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
	if(Socket==INVALID_SOCKET)
	{
		TRACE("---------Socket creation failed.----------\r\n");
		WSACleanup();
		return 0;
	}
					
	SOCKADDR_IN serverInf;
	serverInf.sin_family=AF_INET;
	serverInf.sin_addr.s_addr=INADDR_ANY;
	serverInf.sin_port=htons(2224);

	///TRY TO REUSE ADDRESS
	char reuse_add = '1';
	int reuseerr = setsockopt(Socket, SOL_SOCKET, SO_REUSEADDR, &reuse_add, sizeof (reuse_add));
	///TRY TO REUSE ADDRESS
					
	if(bind(Socket,(SOCKADDR*)(&serverInf),sizeof(serverInf))==SOCKET_ERROR)
	{
		TRACE("------------Unable to bind socket!-----------\r\n");
		WSACleanup();
		return 0;
	}
		
	int err = listen(Socket,1);
					
	SOCKET TempSock=SOCKET_ERROR;
	while(TempSock==SOCKET_ERROR)
	{
		TRACE("-----------Waiting for incoming connections...-----------\r\n");
		TempSock=accept(Socket,NULL,NULL);
	}
	
	
	// If iMode!=0, non-blocking mode is enabled.
	u_long iMode=1;
	ioctlsocket(Socket,FIONBIO,&iMode);
					
	Socket=TempSock;
	TRACE("---------------Client connected!----------------\r\n");

	while(1)
	{
		char buffer[1000]; …
ktsangop 23 Junior Poster in Training


Returning error codes or flags is an outdated method that is not recommended unless you are writing C code or writing functions that are exported from a DLL or .so file.

I might have to implement it as a DLL so not sure right now about what kind of error detection i am going to use.

If you are serious about loading/saving object data to a file, you should look into the topic of "serialization", that's the formal name for this. Look, for a good example, at the Boost.Serialization library.

Thanks for the suggestion. I haven't thought of serialization so i should read libxml's documentation thoroughly to see how to address that issue.

ktsangop 23 Junior Poster in Training

What i had in mind is the Object("some_file.xml").
Since there is nothing to consider, i will probably use it, and call load_config in the constructor.
As for error handling load_config should return an error value (to a public variable) if it cannot parse the file and i will check the value like this:

myclass Object("some_file.xml");
if (Object.error_val == -1)
     delete Object;
     //or raise exception or terminate program...don't know yet!
ktsangop 23 Junior Poster in Training

Hi everyone!

I am trying for the first time to write "proper" object oriented c++ (ANSI) code.
Up until now everything was made easy to me using visual studio and working with mfc or .net which both handle a lot of the "dirty" stuff...

To the point : I want to build a class that all it's member variables are initialized by parsing an xml file (seperate file for each object).
To parse xml files i use libxml2 library http://xmlsoft.org/.
I have already made a function to parse the xml files and store the data to my variables and this is going to be a member function of my class.

Now how should i design my class for better functionality - portabiliy?
Should i call the xml parse function inside the constructor of my class or leave the constructor "clean" and call the function outside class declaration?

Is there anything i should consider before using the one way or the other?

Thanks in advance.

ktsangop 23 Junior Poster in Training

You can run your executable either at system shutdown or at user logoff using group policy editor. It works smoothly i use it all the time.

Type gpedit.msc at a command line prompt, and navigate either to :
computer settings-> windows settings -> scripts (startup / shutdown)
or
user settings-> windows settings -> scripts - >(logon / logoff)

There you can add a batch script or vbscript that simply executes your application.

If you application runs on the background and you want it to get notified when system is being terminated, then probably the only role of the script could be to notify your application (by p.e. writing something to a file).

Ancient Dragon commented: good info :) +17
Arbus commented: nice! +6
ktsangop 23 Junior Poster in Training

In order to mark this thread as solved i add the following.

I didn't manage to understand why the application i want to block isn't working.
But i concluded to 2 possible answers :
1) Either it loads it's own keyboard driver (or filter driver)
2) Or it's a directx's feature to manage hooks in a way that they are not affected by the technique i applied

In the end it turns out that i will have to write my own low level keyboard filter driver because neither scancode mappings through registry works!
:)

This is possible using the WDK (Windows driver Kit), which has sample code for keyboard filter drivers among others.
Never written a driver before so i'm reading documentation atm..

For what it's worth, thanks to everyone that helped.

ktsangop 23 Junior Poster in Training

Well i just figured it out.

The callback function is executed twice on every keypress.
One for keyboard down (WM_KEYDOWN) message and one for keyboard up message (WM_KEYUP).

I wanted to execute my code ONLY once in a keypress. So i distinguished those with the help of the lParam bitmask calculation.
Eventually, bit 31 of lParam DOES tell you wether you have a keyup or keydown event. I don't know if it this is a workaround or the real thing, but it works because lParam looks like this:

The lParam is = 0x1f0001   //KEY DOWN
The lParam is = 0xc01f0001 //KEY UP

On every Key Up callback the lParam has c0 as the two msbits. The other part is the same and contains probably scancode information.

So applying the bitmask :

//KEY_DOWN
(00000000000)111110000000000000001 //values on parentheses are implied
AND (bitwise)
  10000000000000000000000000000000 (FALSE)
=
  00000000000000000000000000000000


//KEY UP
11000000000111110000000000000001
AND (bitwise)
10000000000000000000000000000000
=
10000000000000000000000000000000 (TRUE)

So if i change my dll code to the following :

_declspec(dllexport) LRESULT CALLBACK KBHookProc(int Code, WPARAM wParam, LPARAM lParam)
{
	
	if (Code < 0) return(CallNextHookEx(hhook, Code, wParam, lParam));

			if((wParam==VK_F2) && (lParam & (1 << 31)))
			{
				keystrokes = 2;
				keytime=GetTickCount();
				return(CallNextHookEx(hhook, Code, wParam, lParam));
			}
			else if ((wParam == VK_F3) && (lParam & (1 << 31)))
			{
				keystrokes = 3;
				keytime=GetTickCount();
				return(CallNextHookEx(hhook, Code, wParam, lParam));
			}
			else if ((wParam == VK_F4) && (lParam & (1 << 31)))
			{
				keystrokes = 4;
				keytime=GetTickCount();
				return(CallNextHookEx(hhook, Code, wParam, lParam));
			}
			else …
ktsangop 23 Junior Poster in Training

> Bit 31 in lparam tells whether a key is down.

What gives you such idea?

Try an experiment: set a breakpoint at line 6. Press buttons few times. Pay attention to lparam. Be surprised that it doesn't change. Then read documentation, and realize that lParam is a pointer is disguise, and that wParam is press/release info.

Aahhhh shhoooot... well that's what you get when you're tired of reading proper documentation and start reading users' documentation.. It's seems so easy in the beginning but always hides most of the truth.
:)

It's generally considered bad form for one application to steal events from all other applications. I'm betting (with good cause) that you can do what you need, which means making sure that the keyboard events are passed to your application -before- they're passed to the application that currently has focus ... if you don't want to (or can't) tell the system that your application should keep focus until it says otherwise (or terminates). Depending on why you need the F5 keypress event sent only to your special application, there may be some other way to achieve the same end. I'm not going to pry, but if this were easy to do, the solution would be ubiquitous and well-documented, and probably none of your applications would work correctly because some other application would be stealing the events it wants. :)

I totally understand what you're trying to say.
But having to work with kiosk machines means …

ktsangop 23 Junior Poster in Training

Thanks both for the answers.

Bit 31 in lparam tells whether a key is down.
And as for the logging i used printfs and i am quite sure that both return statements (in lines : 30 and 43) are executed when line 43 is not commented.

You made me think that maybe the callback function is executed twice when a key press occurs. Once on the keydown event and once more on keyup event.

But changing my code to the following had the same results :

_declspec(dllexport) LRESULT CALLBACK KBHookProc(int Code, WPARAM wParam, LPARAM lParam)
{
	
	if (Code < 0) return(CallNextHookEx(hhook, Code, wParam, lParam));

		if (lParam & (1 << 31)) 
		{
			if(wParam==VK_F2)
			{
				keystrokes = 2;
				keytime=GetTickCount();
				return(CallNextHookEx(hhook, Code, wParam, lParam));
			}
			else if (wParam == VK_F3)
			{
				keystrokes = 3;
				keytime=GetTickCount();
				return(CallNextHookEx(hhook, Code, wParam, lParam));
			}
			else if (wParam == VK_F4)
			{
				keystrokes = 4;
				keytime=GetTickCount();
				return(CallNextHookEx(hhook, Code, wParam, lParam));
			}
			else if (wParam == VK_F5)
			{
				keystrokes = 5;
				keytime=GetTickCount(); //I WANT TO BLOCK F5 so i do not return callnexthookex
				return -1;
			}
//... OTHER KEYS I WANT TO BE PROCESSED

//....

			else 
                        {   
                            keystrokes = 0;
                            return(CallNextHookEx(hhook, Code, wParam, lParam));
                        }
		}
// EDIT HERE: 
        else  //Any other event such as keyup won't be passed to the hook chain
        {
	    return -1; // If i keep this line ALL keys are blocked
	//return(CallNextHookEx(hhook, Code, wParam, lParam)); // if i keep this line all keystrokes pass including F5 i am trying to …
ktsangop 23 Junior Poster in Training

Hi everyone!

I am using a dll to hook keyboard strokes for my application.
The hook works fine, but now i want to disable some keystrokes while my application is running.

So i did the following :

_declspec(dllexport) LRESULT CALLBACK KBHookProc(int Code, WPARAM wParam, LPARAM lParam)
{
	
	if (Code < 0) return(CallNextHookEx(hhook, Code, wParam, lParam));

		if (lParam & (1 << 31)) 
		{
			if(wParam==VK_F2)
			{
				keystrokes = 2;
				keytime=GetTickCount();
				return(CallNextHookEx(hhook, Code, wParam, lParam));
			}
			else if (wParam == VK_F3)
			{
				keystrokes = 3;
				keytime=GetTickCount();
				return(CallNextHookEx(hhook, Code, wParam, lParam));
			}
			else if (wParam == VK_F4)
			{
				keystrokes = 4;
				keytime=GetTickCount();
				return(CallNextHookEx(hhook, Code, wParam, lParam));
			}
			else if (wParam == VK_F5)
			{
				keystrokes = 5;
				keytime=GetTickCount(); //I WANT TO BLOCK F5 so i do not return callnexthookex
				return -1;
			}
//... OTHER KEYS I WANT TO BE PROCESSED

//....

			else 
                        {   
                            keystrokes = 0;
                            return(CallNextHookEx(hhook, Code, wParam, lParam));
                        }
		}
	return -1; // If i keep this line ALL keys are blocked
	//return(CallNextHookEx(hhook, Code, wParam, lParam)); // if i keep this line all keystrokes pass including F5 i am trying to block.
}

So as you see on the comments above i try for example to block F5 keystroke by "breaking" the hook chain.
The last to lines as stated above, both produce unwanted effects.

Is there anyway i could sort this out? Has anyone done this before? I searched really thorougly through the net and couldn't find anything. Using another technique (such as other applications or …