dubeyprateek 26 Junior Poster

You reminded me one of my interviews (that did not go that well :) ). Yes this is how you need to do it.

dubeyprateek 26 Junior Poster

Introduction
There are many times when we try to create a binary search tree of many different data types. This article explains creation of a template library CTree. template <class T>class CTree can be used to create a binary search tree (BST) of any data type.

Features
This class support all basic operations on the tree, other then basic operations it includes

bool TreeInorderWalk(CNode<T>*) ;

bool TreePreorderWalk(CNode<T>*) ;

bool TreePostorderWalk(CNode<T>*) ;

bool TreeInorderWalk(T & ) ;

bool TreePreorderWalk(T & ) ;

bool TreePostorderWalk(T & ) ;

These functions performs various walks on the tree and they prepare a lnk list of all the nodes in the order they incounter. Pointer of thses link list is a public data member of ths CTree class.

1 - CLinkList<T> *m_pListInorder ;

Pointer to the link list prepared by calling TreeInorderWalk.

2 - CLinkList<T> *m_pListPreorder ;

Pointer to the link list prepared by calling TreePreorderWalk.

3 - CLinkList<T> *m_pListPostorder ;

Pointer to the link list prepared by calling TreePostorderWalk.

This list further supports a number of operations like

bool AddToFirst(T &);

bool AddToLast(T &);

bool DeleteFirst();

bool DeleteLast();

bool GetNode(T &, CListNode<T> **) ;

How to use
using is class is very simple, just copy all the header files

Node.h

ListNode.h"

LinkList.h

Tree.h

Treelib.h

to your project folder and inlude TreeLib.h in your application. …

dubeyprateek 26 Junior Poster

For connection oriented UDP (like in your case), it is important to bind

dubeyprateek 26 Junior Poster
int DisplayMessageBox()
{
    int msgboxID = MessageBox(
        NULL,
        (LPCWSTR)L"Sample",
        Cap,
        MB_YESNOCANCEL 
    );

    switch (msgboxID)
    {
    case IDCANCEL:
        // TODO: add code
        break;
    case IDYES:
        // TODO: add code
        break;
    case IDNO:
        // TODO: add code
        break;
    }

    return msgboxID;
}
MosaicFuneral commented: phear da bears u feed! -1
dubeyprateek 26 Junior Poster
dubeyprateek 26 Junior Poster

Posted what just happened but then shouldnt I not be able to run shutdown.exe if i didnt have the required access?

I really think this is a vista problem? Anyone else using vista?

It is not a Vista problem. Vista uses same APIs to shutdown the system.
You certainly have required permissions and privileges if you can shutdown the system by Shutdown.exe

You just need to be more careful that you need to *enable* shutdown privilege before you call ExitWindowEx API. By default, this privilege is disabled for all users. The code on MSDN enable this privilege and calls the API.

2 prerequisites
a) You must have the shutdown privilege (It is not 'permission' it is called 'privilege')
b) You must have this privilege enabled.

Many times this privilege is present but not enabled. You would need additional programming effort to enable it.

Also, you can try turning off the UAC and running your application to see if that makes any difference to you.

Off the records::
If that doesnot work, open a support incident with Microsoft I will have a dedicated engineer work with you. If it is idenified as a Vista problem Microsoft will not charge you!

dubeyprateek 26 Junior Poster

Shutdown.exe uses InitiateSystemShutdownEx.

I have used this code on Vista and it works for me.

dubeyprateek 26 Junior Poster

1) Your code lacks the required privilage. You would need Shutdown Privilage enabled for the process which initiates the shutdown.
2) On server OS not everyone has shutdown privilage, you need to make sure that you are Admin if you are using server version.
3) This MSDN example is complete.

dubeyprateek 26 Junior Poster

how about trying this

#include <Windows.h>

BOOL MySystemShutdown()
{
	HANDLE hToken; 
	TOKEN_PRIVILEGES tkp; 

	// Get a token for this process. 

	if (!OpenProcessToken(GetCurrentProcess(), 
		TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) 
		return( FALSE ); 

	// Get the LUID for the shutdown privilege. 

	LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, 
		&tkp.Privileges[0].Luid); 

	tkp.PrivilegeCount = 1;  // one privilege to set    
	tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 

	// Get the shutdown privilege for this process. 

	AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, 
		(PTOKEN_PRIVILEGES)NULL, 0); 

	if (GetLastError() != ERROR_SUCCESS) 
		return FALSE; 

	// Shut down the system and force all applications to close. 

	if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 
		SHTDN_REASON_MAJOR_OPERATINGSYSTEM |
		SHTDN_REASON_MINOR_UPGRADE |
		SHTDN_REASON_FLAG_PLANNED)) 
		return FALSE; 

	return TRUE;
}
int _tmain(int argc, _TCHAR* argv[])
{
	MySystemShutdown();
	return 0;
}
dubeyprateek 26 Junior Poster

About Messages and Message Queues

This talks about everything. Please let us know if you have any question.

dubeyprateek 26 Junior Poster

The WM_SHOWWINDOW message is sent to a window when the window is about to be hidden or shown.

I suspect the window you are trying to hide processes this message and prevents itself from hiding.

You might use Spy++ to see wheather or not this notification is send to the target Window.

dubeyprateek 26 Junior Poster

Does it happens with all the Windows or with any specefic Window ?
Are you trying to hide any window which you have created or any other applciaiton's Window ?

dubeyprateek 26 Junior Poster

I corrected minor syntactical errors in your code. I did not check the logic. Check following code.

#include<stdio.h>
#include<stdlib.h>

int find_transpose(int n, double **a, double **b)
{
	int i,j;
	for (i=0; i<n; i++)
	{
		for (j=0; j<n; j++)
			b[i][j] = a[i][j];
	}
	for (i=0; i<n; i++)
	{
		for (j=0; j<n; j++)
			b[i][j] = a[j][i];
	}
	return 0;
}


int main (void)
{

	int i, j, p=3;
	double **in, **out;

	in = (double **)malloc(p * sizeof(int *));
	out = (double **)malloc(p * sizeof(int *));

	for (i=0; i<p; i++){
		in[i]= (double *)malloc(p * sizeof(int *));
		out[i]= (double *)malloc(p * sizeof(int *));}

	for (i=0; i<p; i++)
	{
		for (j=0; j<p; j++)
		{in[i][j]= 10./(i+1);
		printf("in[%i][%i] = %f\n", i, j, in[i][j]);
		}
	}

	find_transpose(p, in, out);

	for (i=0; i<p; i++)
	{
		for (j=0; j<p; j++)
			printf("in[%i][%i] = %f\n", i, j, in[i][j]);
	}

	for (i=0; i<p; i++)
	{
		for (j=0; j<p; j++)
			printf("out[%i][%i] = %f\n", i, j, out[i][j]);
	}

	return 0;
}
dubeyprateek 26 Junior Poster

What does not work? Does it gives you compile errors? Does it crashes?

dubeyprateek 26 Junior Poster

You may not need to lear about .Net framework as such for your project. It is a underline layer which helps managed code to run your system(It is not the only thing it does).

Sometime Windows update can install new framework for you.

dubeyprateek 26 Junior Poster

What is the error? You can always redifine _WIN32_WINNT as per your target OS

dubeyprateek 26 Junior Poster

How long did you wait after the hung? Does it hang your machine?
What is the .NET framework you are using? It takes longer if you have installed new version of framework sometimes as long as five minutes, subsequent builds will be faster.

dubeyprateek 26 Junior Poster

If you are targetting Windows.You will need to have Windows SDK to build your application. Windpws SDK comes with all the required header files.
You can download the letest SDK from http://www.microsoft.com/downloads/details.aspx?familyid=C2B1E300-F358-4523-B479-F53D234CDCCF&displaylang=en

dubeyprateek 26 Junior Poster

Hello Jason,

Simply speaking you cannot execute any application on a remote machine. There are many problems doing this. Apart from the implementation limitations there are some major security risks.

However, you can use a utility called PSEXEC(http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx) to do this. It internally installs a service on the remote computer and ports your executable there and runs it.

dubeyprateek 26 Junior Poster

What is the error? Linking errors are different than syntactical error one can't find them looking at the code.

dubeyprateek 26 Junior Poster

You need to catch the exception. You need to write a catch block. If you let OS to handle your first chance exception it is going to simply terminate the process because OS does not know which way you want to terminate.
You can try writing the catch block and exit from there.

dubeyprateek 26 Junior Poster

@sivaslieko++ is it the 'if' not working or your logic is not working?

One unfortunate thing associated with computer is, it does not work the way you want it to work it works the way it should work!! :)
I am a victim !! :D

dubeyprateek 26 Junior Poster

@cdijuste
You knew it didn't you?? "less or equal to" "<=" :)

dubeyprateek 26 Junior Poster

@obscured47 You can do anything once you catch the exception.
Why do you want to throw an exception to pause the execution? There could be better ways to do that.
Can you post small segemt of your code and let us know the behaviour you are expecting ?

dubeyprateek 26 Junior Poster

You may like to overload couple of operators in MyStr class to make it friendly.

dubeyprateek 26 Junior Poster

@Max_Payne
You can not initialize arrays the way you are trying. However, you have exposed a good problem. How to initialize a constant string inside a class?
I have been facing these kinds of problems during my carrier and every time I implement a work around which suits to my requirements.

Look at the following implementation. I don’t know if it can help you but this is something you can try.

class MyClass {
	class MyStr {
	public:
		char	m_szArray[100] ;
		MyStr(const char *szPtr) {
			strcpy(m_szArray,szPtr);
		}
	};
	int		m_iInt;
	const MyStr m_MyStr ;
public:
	MyClass(int i, const char *szPtr):m_iInt(i),m_MyStr(szPtr)
	{

	}
};
dubeyprateek 26 Junior Poster

Which page are you talking about, web page ?

dubeyprateek 26 Junior Poster

How this problem is related with C++?

Install letest update and try to repair it.

dubeyprateek 26 Junior Poster

See this and this

dubeyprateek 26 Junior Poster

Are you trying to write a balanced binary tree??
You should explore how AVL trees work.