eranga262154 22 Junior Poster

Hi all,

I just want to write a simple proxy to redirect client to different URLs. Say all users call the proxy server with the same URL and the proxy server redirect them to different URLs. How can I do such thing, can you please anyone comment on this.

Thanks a lot

eranga262154 22 Junior Poster

I'll checking it. Probably I have installed wrong one here. I'll see and let you know about that.

Thanks for the replay.

eranga262154 22 Junior Poster

Thanks, I do that part.

I found a sample project on following link.

http://sourceforge.krugle.com/kse/projects/7CRbMg3#2

I try to run the project and have a test. Got a run time error.

svn: The VCC property was not found on the resource

I have no idea about that. So please tel me how to fix this error. Please have a test run on that project.

Thanks a lot

eranga262154 22 Junior Poster

Thanks for the replay.

So I.m going to write my own update class.

As the first step I'm going to read a file on the specific location of the server and find the version. If the version is differ do the update process.

So can you give me a hint how can I read a file on the server from the client.

Thanks.

eranga262154 22 Junior Poster

Hi all,

I want to create a Java product developer. That means a tool to update an existing version of an application automatically. You guys/gals have any idea.

If you know any example regarding that, please put a link here to see. I really appreciate that.

Thanks a lot. :)

eranga262154 22 Junior Poster

Google too. Search on the web. You can find thousands of.

eranga262154 22 Junior Poster

Yes, that code is too much to make a try pal. Too boring. Please specify your question with the simple code.

eranga262154 22 Junior Poster

I got all those things to done because of the following example.

XML Writer in C++

Can you just see it.

What I have done is, output stream write to a disk file and then read the file to memory. It's odd.

So i try to directly write that stream to memory. But wired with it, I can't use char buffer for that.

Can you help me to do it. Any clue..

eranga262154 22 Junior Poster

Thanks for the replay.

But I do it using ifstream, and seems it works fine.

eranga262154 22 Junior Poster

But on what I confused is that file data type of TCHAR.

Can I used it as ifstream.

eranga262154 22 Junior Poster

Hi all,

I have a disk file define as

TCHAR szTempFile[MAX_PATH];

What I want to do is, read that file into memory stream. To a buffer. How can I do it.

eranga262154 22 Junior Poster

It's wrong pal. If I append the file, what happened if my application runs thousand times. It's obvious right?

eranga262154 22 Junior Poster

Hi all.

I want to read and update a ini file to do some processing. Here is what I have try.

public static void main(String[] args) {
        // TODO code application logic here
        new ReadINIFile().readIt();
        //new ReadINIFile().writeIt();
    }
    
    private void readIt() {
        try {
            Properties pro = new Properties();
            pro.load(new FileInputStream("temp.ini"));
            
        // Try to display them          
            System.out.println("Key is: " + pro.getProperty("Key"));            
            System.out.println("Here is: " + pro.getProperty("Here"));
            
        }
        catch(Exception ex) {
            System.out.println(ex.getMessage());
        }
    }
    
    private void writeIt() {
        // Try to update values
        try {
            Properties pri = new Properties();
            pri.store(new FileOutputStream("temp.ini"), "Just a comment");
            pri.setProperty("Here", "New");
            
        }
        catch(IOException ioe) {
            System.out.println(ioe.getMessage());
        }
    }

Reading part is ok, it's read all data I want. When I write all content of the ini file is deleted and following is the content.

#Just a comment
#Fri May 09 10:41:51 IST 2008

Can anyone of you tell me where I'm going wrong. Here is the structure of the ini file.

[Head]
Text=Java
Key=14
Name=Old
[More]
Here=New

eranga262154 22 Junior Poster

If you have a reference to the Element you can simply use the Element.setTextContent(String) method. After you have updated all of the DOM elements as needed, just write it back to a file: http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JAXPXSLT4.html

Thanks for the help. I'll see it and let you know what happened :)

eranga262154 22 Junior Poster

Anyone of don't have an idea for me :)

eranga262154 22 Junior Poster

Hi all,

Here is the structure of my XML file.

<?xml version="1.0"?>

	<data>
		<key>468</key>
		<name>pal</name>
		<option>10</option>
	</data>

I want to read the option tag value, then increment it by 4 and write it to the same location. So at the end XML file content like this.

<?xml version="1.0"?>

	<data>
		<key>468</key>
		<name>pal</name>
		<option>14</option>
	</data>

I've read the value as follows.

public static void main(String[] args) {
        // TODO code application logic here
        try{
            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
            
            Document doc = docBuilder.parse (new File("records.xml"));
            
            NodeList ints = doc.getElementsByTagName("option");
            if(ints.getLength() != 0) {
                Element firstKeyElement = (Element)ints.item(0);
                NodeList firstKey = firstKeyElement.getChildNodes();
                
                String value = ((Node)firstKey.item(0)).getNodeValue().trim();
                int intValue = Integer.parseInt(value);
                System.out.println(intValue);
                
            // change the value and write it to the same location after this
 
            }
        }
        catch(SAXParseException ex){
            System.out.println(ex.getLineNumber() + ex.getMessage());
        }
        catch(SAXException ex){
            System.out.println(ex.getException());
        }
        catch(Throwable th){
            th.printStackTrace();
        }
    }

I'm stuck with how to write the new value there. Can you guys comment me on this.

Thanks

eranga262154 22 Junior Poster

Hi all,

How it is possible to make curved vertex of a swing container like JDialog. Say I the property setUndecratoed() to true, so there is just a rectangular shape window I have. I want to curved a vertex there.

Any suggestions really appreciate.

eranga262154 22 Junior Poster

So what should I do. I'm really wired with it now pal.

eranga262154 22 Junior Poster

Hi all,

I use the swing timer to move a dialog from one position to another. Here is the code I have use.

// Set the main window display location
    public void setWindowLocation()
    {
        int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
        int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
        
        int frameHeight = this.getHeight();
        int frameWidth = this.getWidth();
                
        int _xValue = (screenWidth - frameWidth);
        int _yValue = (screenHeight - getTrayheight() );
        int _yEnd = (screenHeight - frameHeight - getTrayheight() );
        
        //this.setLocation((screenWidth - frameWidth), (screenHeight - frameHeight - getTrayheight() - WINDOW_SPACE));
        this.setLocation(_xValue, _yValue);
        
        while(_yValue > _yEnd){
            dialogMotion(this, _xValue, _yValue);
            _yValue -= 1;
        }
 
        // this.dispose();
    }
    
// Dialog motion
    private void dialogMotion(final MainDialog mainDialog, final int x, final int y){
        AbstractAction abAction = new AbstractAction() {
            public void actionPerformed(ActionEvent evnt) {
                mainDialog.setLocation(x, y);
            }
        };
        Timer motionTimer = new Timer(300, abAction);
        motionTimer.setRepeats(false);
        motionTimer.start();
    }
    
// Find the taskbar height to place the main frame in lower-right corner
// of the viewable area of the screen.
    private static int getTrayheight(){
        return (Toolkit.getDefaultToolkit().getScreenSize().height -
                 GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().height);
    }

I think my code is clear to you. After moving the dialog onto the task bar, I want to dispose it. You can see that at the end of the while loop I've try it.

What happened there is, I can't see the dialog moving. it directly dispose. I add a breakpoint at the while loop and check, it iterate until condition is false. But I can't see the motion. If I comment the dispose code line as in my above code, …

eranga262154 22 Junior Poster

Sorry for disturbing. Simply I can do it by diposing by calling dispose()

eranga262154 22 Junior Poster

Hi all,

I want to dispose a JFrame using a click-event. So I simply do this on Netbens.

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}

But it not work. Do you have any idea.

I just want to dispose all the visible JFrames. Actually I have only one JFrame visible. So this should work, but no luck. No any exceptions either on it.

And also I just want to dispose, not to exit the application.

Any idea?

eranga262154 22 Junior Poster

Yes it is. Thanks for the replay. I found it after referring few articles on the web.

Thanks

eranga262154 22 Junior Poster

Hi all,

I already convert a C++ project to C# project. It's fine and working ok.

On C++ I use DWORD data type. But in C# for that I used just a int value. Is that ok. Is there compatible data type which I can use for my project.

Thanks.

eranga262154 22 Junior Poster

Hi all,

I have two C# projects (a service and a windows form) on the same solution. I want to send some parameters to the service on click event of the service start (serviceControllr.Start() method)

How can I do that.

Thanks.

eranga262154 22 Junior Poster

Hi all,

I'll explain my question as follows. I have a server application written using C++. Now I try to automate the server to start it automatically. So I write a .Net service to do that.

It's fine, my service is working fine.

But there is one issue. Actually my server can't run multiple server using the same IP. So I want to find is there any server running on specific IP.

So, I used Mutex.

Here what I have done. First get the each server IP from a data base and on each one test there is any instance going on.

private bool HasMultipleInstance(string IP)
		{
			/*
			 * No need to acquire or release the Mutex in .Net
			 * */
			IPMutex = new Mutex( true, IP + "_mutex_" );
			//IPMutex.WaitOne();	

			if( IPMutex != null )
			{
				EventLog.WriteEntry( "MyService", "Multiple Instances on " + IP );
				//IPMutex.ReleaseMutex(); 
				return false;
			}
			else
				return true;
		}

What is your guys comment on this. Is that ok, since my application is a service?

eranga262154 22 Junior Poster

Anyway thanks for all your guys replay. I've correct my mistake. Used a null-terminated string, and on that I can use adVarChar variable type without any issue.

Sulley's Boo commented: all the best =D +4
eranga262154 22 Junior Poster

Ok, but I want to do it using a Stored Procedure. Actually the issue is about EnumDataType, which should be used in inserting a line of text(a string actually).

Do you know that data type pal?

eranga262154 22 Junior Poster

Actually I use stored procedure for this, to add data to the database. Can you please look at my code on the first post.

eranga262154 22 Junior Poster

Yep, on the line where I write the file name is the error. I can write any other value to the DB. Like int, text etc...

But I can't write a string(file name is a string there) to the database using that variable. Actually using adVarChar I can add a character successfully. I can't use it to add a stream of characters.

eranga262154 22 Junior Poster

Yep, adVarChar is not a mysql data type. Its ADODB enum data type.

eranga262154 22 Junior Poster

By debuging my code I found that, use the wrong data type for the filename adding, that is adVarChar. Do you guys know what should I use for it.

eranga262154 22 Junior Poster

Hi all,

I want to add a string and a character to two columns of a sql database table. To do that I use a Command object rather to use the same connection on different functions. At the same time used a stored procedure to add data.

Hear are some code segments.

// VC++ code use to add data 
void CDbService::AddGData(string& fileName)
{
_CommandPtr pCom;

pCom.CreateInstance(__uuidof(Command));

pCom->ActiveConnection = m_pConn;
pCom->CommandType = adCmdStoredProc;
pCom->CommandText = _bstr_t("sp_GroupState");

// Add file name
pCom->Parameters->Append(pCom->CreateParameter(_bstr_t("FileName"), adVarChar, adParamInput, 50,&fileName));
}

Here is the stored procedure I used

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

CREATE PROCEDURE [dbo].[sp_GroupState] 
@FileName varchar, @State varchar
As
Insert into tblGroupState(DiskFileName, FileState)
Values (@FileName, @State);

But this code not added any data to my table. Here is the table create query I used.

USE [RFDB]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tblGroupState](
	[DiskFileName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[FileState] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF

Can you guys see any mistake I have made. It's really appreciate.

eranga262154 22 Junior Poster

Anyway, I solved it myself after doing some experimental. Just have to followed SubItems on the ListView.

eranga262154 22 Junior Poster

Hi all,

I've created two columns on the list view as follows.

ColumnHeader colHed;

		// Header one
			colHed = new ColumnHeader();
			colHed.Text = "Name";
			colHed.Width = 100;
			this.lwDetails.Columns.Add(colHed);

		// Header two
			colHed = new ColumnHeader();
			colHed.Text = "Address";
			colHed.Width = 200;
			this.lwDetails.Columns.Add(colHed);

Then on a separate function I try to add data to those columns. Name and address of a one person store in a string array named items. I try to add data as follows.

this.lwDetails.Items.Add(items[0]);
			this.lwDetails.Items.Add(items[1]);

lwDetails is the list view. In this case name and address are added to the same column. How can I correct it.

Thanks..

eranga262154 22 Junior Poster

Oh, it's really new thing for me. Thanks pal.

eranga262154 22 Junior Poster

Hi all,

I'm working with some date formating, with local and UTC time format. At the end I've print the result to the console as follows.

cout << stLocal.wMonth << "/" << stLocal.wDay << "/" << stLocal.wYear << " " << stLocal.wHour << ":" << stLocal.wMinute << "\n";

This line of code works fine, but seems this is too dull when passing this time. Actually I want to pass that value as a string(as a single value) and try the following.

ostringstream os;
		os << stLocal.wMonth << "/" << stLocal.wDay << "/" << stLocal.wYear << " " << stLocal.wHour << ":" << stLocal.wMinute << "\t";
		cout << os;//0012FA3C

The thing here the output is just a number, 0012FA3C for all values.

What's wrong with my code.

eranga262154 22 Junior Poster

Here is the part of code where I use the first CStringArray.

void CTimeZoneDlg::GetTM(void)
{
	HKEY hKey, Key;// Key, subkey
	DWORD dwType = REG_SZ;
	int iRet = 0;
	CString strName, strValue, strPath, strKey;

// Set the Times Zones key path
	strPath = _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones");

// Open the main key
	iRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strPath, 0, KEY_READ, &hKey);

// Check the succed of the handler
	if (iRet != ERROR_SUCCESS)
	{
		return;
	}

// For RegQueryInfoKey
    TCHAR    achKey[MAX_KEY_LENGTH];		// buffer for subkey name
    DWORD    cbName;						// size of name string 
    TCHAR    achClass[MAX_PATH] = TEXT(""); // buffer for class name 
    DWORD    cchClassName = MAX_PATH;		// size of class string 
    DWORD    cSubKeys = 0;			// number of subkeys 
    DWORD    cbMaxSubKey;			// longest subkey size 
    DWORD    cchMaxClass;			// longest class string 
	DWORD    cValues;				// number of values for key 
    DWORD    cchMaxValue;			// longest value name 
    DWORD    cbMaxValueData;		// longest value data 
    DWORD    cbSecurityDescriptor;	// size of security descriptor 
    FILETIME ftLastWriteTime;		// last write time

	DWORD i, retCode;

	TCHAR buffer[MAX_PATH];
	DWORD dwSize = sizeof(buffer);

// Get the class name and the value count.
	retCode = RegQueryInfoKey(
		hKey,					// key handle
		achClass,				// buffer for class name
		&cchClassName,			// length of class string
		NULL,					// reserved
		&cSubKeys,				// number of subkeys
		&cbMaxSubKey,			// longest subkey size
		&cchMaxClass,			// longest class string
		&cValues,				// number of values for this key
		&cchMaxValue,			// longest value name
		&cbMaxValueData,		// longest value data
		&cbSecurityDescriptor,	// security descriptor
		&ftLastWriteTime);		// last write time

// Enumerate the child keys, until RegEnumKeyEx fails. …
eranga262154 22 Junior Poster

Actually I don't write that line of code. It is automatically generated when I create the first CStringArray in my application.

eranga262154 22 Junior Poster

Hi all,

I've use a CStringArray to store some CStrings in my application. Now I want to use another CStringArray on the same application. So I add another CStringArray instance on the class view, VC++ .Net 2003.

When I add and compile it don't give any error message. But when I run the code it gives the following error.

Unhandled exception at 0x00414ff3 in TimeZone.exe: 0xC0000005: Access violation writing location 0x00000020.

on following line of code,

m_pMainWnd = &dlg;

Why is that. Can you guys give me a clue.

eranga262154 22 Junior Poster

Ok, I got the point 0 and '0' has two different meaning. ASCII.

eranga262154 22 Junior Poster

Ok, thanks. But if I use it what happened. I mean use of a space.

eranga262154 22 Junior Poster

Thanks Salem, I've just think how to move the buffer directing pointer.. Thanks again.

One more question, to avoid effect of the past values I've clean the buffer as follows.

::memset(tmpBuffer, ' ', 10);

Is that correct, or should I use just zero.

eranga262154 22 Junior Poster

Hi all,

First I create a dynamic buffer and set all element to zero. Then add a int value first to the buffer. Then after that int value add a string to the buffer, actually at the end of int value. But seems my code overwrite each other.

Here is the code,

char* tmpBuffer = new char[10];// Dynamic allocation
	::memset(tmpBuffer, 0, 10);

	::memcpy(tmpBuffer, &iReq, 4);
	::memcpy(tmpBuffer, &strGetName, 6);

How can I avoid this issue.

eranga262154 22 Junior Poster

Thanks for the information.

What I'm going to do is, using Display found the time offset, use a substring to do that, and compared it with the user input.

eranga262154 22 Junior Poster

Hi all,

This question partially related to one of my old question.

Reading the time zone information. Now I'm try to do it in this way. User enter the time offset. Using that value search the registry and find the time zone name. Where I'm stuck is how to search the registry. Here what I'm try up to now.

HKEY hKey;// Handle to the registry
	DWORD dwType = REG_SZ;// Data type

	char buf[255];// Data
	DWORD dwBufSize = sizeof(buf);

	// Sub handle to the registry
	const char* subKey = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\Afghanistan Standard Time";

	// Open the handler
	if(RegOpenKey(HKEY_LOCAL_MACHINE, subKey, &hKey) == ERROR_SUCCESS)
	{
		// Do the processing, find the name
		if(RegQueryValueEx(hKey, "Std", 0, &dwType, (BYTE*)buf, &dwBufSize) == ERROR_SUCCESS)
		{
			AfxMessageBox(buf);
		}
		else
		{
			AfxMessageBox("Error in reading values.", MB_OK);
		}
		// Close the handler
		RegCloseKey(hKey);
	}
	else
	{
		AfxMessageBox("Error in reading registry.", MB_OK);
	}

This code is work for Afghanistan Standard Time. How can I iteratively change until found the correct offset.

eranga262154 22 Junior Poster

Ok, I've solved the question my self. It's so easy. Do it in the constructor and destructor.

eranga262154 22 Junior Poster

Hi all,

I've create a window as follows,

void CRtf::Initialize(void)
{
	HWND	m_hwnd_RTFBox = CreateWindowEx(
							WS_EX_APPWINDOW,
							RICHEDIT_CLASS,
							"RichTextWindow",
							WS_BORDER|ES_MULTILINE,
							0,
							0,
							100,
							100,
							::GetConsoleWindow(),
							NULL,
							0,
							NULL);
}

After doing all the process, I've destroyed the window as well.

My question is this. I use the above handler iteratively within a loop. So all the time call the Initialize() in each processing step. Simply create and destroy to the equal number of looping process. I want to avoid it.

According to the MSDN, if the CreateWindowEx() is succeeds, the return value is a handle to the window. If it is failed the return value is NULL. So I've tried something like this.

while(m_hwnd_RTFBox != NULL)
{
// Do the processing here
}

But it doesn't work. Can you guys give me a clue on this.

eranga262154 22 Junior Poster

I'll explain it little more. If you check on the timezone drop down list of the windows date time properties window, there are large number of timezones are listed. I want to read them and display on a console. Thats it.

eranga262154 22 Junior Poster

Wow, that is real collection. Thanks pal.

I need one more advice from you. How should I take my approach. I mean how should outline my works. One thing is that I want to work with pure C++, not MFC, it should since I'm working with APIs.

Anything special to do by me on this.

eranga262154 22 Junior Poster

Hi all,

I'm going to learn a new subject on C++. Working with Windows API. Since I work with Java there is no API used, but I feel it is better to work a little with APIs.

Here is my attempt for that.

I want to read the system time zones and display on the console. Basically in two columns, City and the Time offset. From where I should start work. Can you guys give some clues. Following week I'm free because of Christmas, so I can do some work on it.

Thanks