|
brucewayn wrote: I'm working on an application where i have a requirement to delete the XML data which is between certain dates. However i was able to get the data within those particular dates given by the user but i have no idea how to delete them.
You mean a xml file, right ?
If that's the case you have to rewrite the full file without the data you want to delete. Now, how to do it really depends on what you are using to read the xml file. In general most of the libraries allow you to also write xml back to a file.
brucewayn wrote: I even used removechild function but the application is getting crashed
removechild ? Where's that coming from ? I guess it is coming from a specific library but it would help a lot if you provide information about what you are using.
|
|
|
|
|
I am giving you idea to delete data from xml, it will be useful to you
MSXML2::IXMLDOMNodeListPtr pNodeList1 = ePtrRootXML->selectNodes("//parentOfDatenode");
while(MSXML2::IXMLDOMNodePtr pTemp = pNodeList1->nextNode())
{
if(pTemp)
{
// if date is given by user no need
MSXML2::IXMLDOMNodePtr pFromDate = pTemp->selectSingleNode(".//fromdate");
MSXML2::IXMLDOMNodePtr pToDate = pTemp->selectSingleNode(".//todate");
strFromDate = (LPCTSTR)pFromDate->text;
strToDate =(LPCTSTR)pToDate->text;
OleDateTime olecurrentdate(COleDateTime::GetCurrentTime());
// convert strFromDate and strToDate to OleDateTime format n compare
if( olecurrentdate<=oleTodate) // delete if success
{
pSection->removeChild(pTemp);
DocptrXML->save(bstrOutputXML);//bstrOutputXML= XML name with full path
}
}
|
|
|
|
|
You said your application crashes, did you use your debugger to see where the problem occurs exactly ? Without using your debugger, you won't be able to go very far...
|
|
|
|
|
I suppose you replied to the wrong post (unsless Sam today is so crazy to call himsel Bruce ).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Oh yes, I mixed the different posts... I guess it was too early in the morning
|
|
|
|
|
Hi All,
HWND FindWindow(LPCTSTR lpClassName,LPCTSTR lpWindowName);
In this function, how to find the lpClassName for particular dialog.
Regards,
Anitha
|
|
|
|
|
I have found WinSpy++ to be useful in finding class names for particular windows, or you could use CP's own WinSpy, part of a demonstration of code injection into another process. They're especially useful when you want to find the class name for Windows components (such as the task bar, for example).
Regards,
--Perspx
"A refund for defective software might be nice, except it would bankrupt the entire software industry in the first year." -Andrew Tanenbaum
"Einstein argued that there must be simplified explanations of nature, because God is not capricious or arbitrary. No such faith comforts the software engineer." -Fred Brooks
|
|
|
|
|
GetClassName
«_Superman_»
|
|
|
|
|
IIRC, all dialogs are of class #32770 .
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi all,
I have made a application in vc2008, I have made a TCHAR variable...
TCHAR prdcode[10];
My problem is i want to assign this value to CString variable...
CString test = prdcode;
but while assigning value it takes some garbage value....
how can i do it...
thanks in advance
|
|
|
|
|
VCProgrammer wrote: but while assigning value it takes some garbage value....
How do you check that ?
In oyur code snippet, you didn't assign anything to prdcode, so it will contain garbage at that time. Show use the code where you write something in it.
|
|
|
|
|
my prcode is getting a value....
and i am assigning that value to my CString variable....
suppose it has 10 characters
starting will be ok but at end it'll show garbage value....
|
|
|
|
|
VCProgrammer wrote: my prcode is getting a value....
Well, where is your code ? Without code, it's difficult to help...
VCProgrammer wrote: starting will be ok but at end it'll show garbage value....
Did you forget the zero termination of the string ?
|
|
|
|
|
TCHAR prdcode[10] = _T("thisvalue");
CString test = prdcode;
«_Superman_»
|
|
|
|
|
Either use _tcscpy() for initializing prdcode or put the string directly to the CString object.
|
|
|
|
|
Well, possibly prdcode contains garbage, you didn't show us how did you fill the array content...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
VCProgrammer wrote: ...it takes some garbage value....
How are you verifying this?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I've been following Beej's Guide to network programming, (which is really great) and when implementing
his streaming socket server ( <a href="http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html#simpleserver">http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html#simpleserver</a>[<a href="http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html#simpleserver" target="_blank" title="New Window">^</a>] )
it works just fine. To test it I opened a Konsole (using Kubuntu) and ran:
<code>
pacific@mainbox $ telnet localhost 3490
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Hello, world!Connection closed by foreign host.
</code>
However, when trying to make a class out of the above code, as shown below, I get a "accept: Bad file descriptor" error, repeatedly.
Not sure if these two functions (which are not part of the class) have anything to do with it:
void sigchld_handler(int s);
void *get_in_addr(struct sockaddr *sa);
Help on this would be much appreciated !!
Gvanto
Sources also here: <a href="http://www.sharedigest.com/socketserver.tar.gz">http://www.sharedigest.com/socketserver.tar.gz</a>[<a href="http://www.sharedigest.com/socketserver.tar.gz" target="_blank" title="New Window">^</a>]
main (WLFeeder.cpp):
<code>
#include <iostream>
#include <cstdlib>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#include "SocketServer.h"
#define DO_MAIN 1
using namespace std;
using namespace wlns;
#ifdef DO_MAIN
int main(int argc, char *argv[]) {
SocketServer *s = new SocketServer();
if( s->initAddrInfo() != SUCCESS ) {
cout << "Error initializing address " << endl;
exit(1);
}
if( s->initBind() != SUCCESS ) {
cout << "Error initializing bind " << endl;
exit(1);
}
if( s->initListen() != SUCCESS ) {
cout << "Error initializing listen " << endl;
exit(1);
}
if( s->clearDeadProcesses() != SUCCESS ) {
cout << "Error clearing dead processes " << endl;
exit(1);
}
if( s->listenForConnections() != SUCCESS ) {
cout << "Error in listening for connections " << endl;
exit(1);
}
return 0;
}
#endif
</code>
SocketServer.h:
<code>
/*
* SocketServer.h
*
* Created on: 11/02/2009
* Author: pacific
*
* Generic, extendable socket-managing class handling
* network communications via sockets
*/
#ifndef SOCKETSERVER_H_
#define SOCKETSERVER_H_
#include <iostream>
#include <cstdlib>
#include <stdio.h>
#include <string>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <sys/wait.h>
#include <signal.h>
#define BACKLOG 10 //no. of pending connections the queue will hold
#define PORT "3490"
using namespace std;
namespace wlns {
static int SUCCESS = 1;
static int FAILURE = 0;
class SocketServer {
private:
int sockfd_, new_fd_; //listen on sock_fd_, new connection on new_fd_
struct addrinfo hints_, *servinfo_, *p_; //hints and actual address
struct sockaddr_storage their_addr_; //connector's address information
socklen_t sin_size_;
struct sigaction sa_;
int yes_;
char s_[INET6_ADDRSTRLEN];
int rv_;
//char *remote_host_, *remote_port_;
public:
SocketServer();
virtual ~SocketServer();
int setLocalPort(char *lp);
char *getLocalPort();
int initAddrInfo();
int initBind();
int initListen();
int clearDeadProcesses();
int listenForConnections();
// int getSocketFileDescriptor();
// int setRemoteHostAndPort(char *host, char *port);
// int connectToRemoteHost();
};
}
#endif /* SOCKETSERVER_H_ */
</code>
SocketServer.cpp:
<code>
/*
* SocketServer.cpp
*
* Created on: 11/02/2009
* Author: pacific
*/
#include "SocketServer.h"
using namespace std;
namespace wlns {
void sigchld_handler(int s)
{
while(waitpid(-1, NULL, WNOHANG) > 0);
}
// get sockaddr, IPv4 or IPv6:
void *get_in_addr(struct sockaddr *sa)
{
if (sa->sa_family == AF_INET) {
return &(((struct sockaddr_in*)sa)->sin_addr);
}
return &(((struct sockaddr_in6*)sa)->sin6_addr);
}
SocketServer::SocketServer() {
yes_ = 1;
memset(&hints_, 0, sizeof hints_);
hints_.ai_family = AF_UNSPEC;
hints_.ai_socktype = SOCK_STREAM;
hints_.ai_flags = AI_PASSIVE; //bind to IP of the host we're running on, p148 Beej's
}
SocketServer::~SocketServer() {
// TODO Auto-generated destructor stub
}
/**
* Populates servinfo with the appropriate
*/
int SocketServer::initAddrInfo() {
cout << "initAddrInfo() :: Initializing address ..." << endl;
if( (rv_ = getaddrinfo(NULL, PORT, &hints_, &servinfo_)) == -1 ) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv_));
return FAILURE;
}
return SUCCESS;
}
int SocketServer::initBind() {
cout << "bindFirstPossible() :: ..." << endl;
for(p_ = servinfo_; p_ != NULL; p_ = p_->ai_next) {
if( (sockfd_ = socket(p_->ai_family, p_->ai_socktype, p_->ai_protocol)) == -1) {
perror("server: socket");
continue;
}
if( setsockopt(sockfd_, SOL_SOCKET, SO_REUSEADDR, &yes_, sizeof(int)) == -1 ) {
perror("setsockopt");
return FAILURE;
}
if (bind(sockfd_, p_->ai_addr, p_->ai_addrlen) == -1) {
close(sockfd_);
perror("server: bind");
continue;
}
break;
}
freeaddrinfo(servinfo_); //done with this struct
if(p_ == NULL) {
fprintf(stderr, "server failed to bind\n");
return FAILURE;
}
return SUCCESS;
}
int SocketServer::initListen() {
cout << "initListen() :: ..." << endl;
if( listen(sockfd_, BACKLOG) == -1 ) {
perror("listen");
return FAILURE;
}
return SUCCESS;
}
int SocketServer::clearDeadProcesses() {
cout << "clearDeadProcesses() :: ..." << endl;
sa_.sa_handler = sigchld_handler; //assign function pointer - not sure if it matters if its not a class method ?
sigemptyset(&sa_.sa_mask);
sa_.sa_flags = SA_RESTART;
if (sigaction(SIGCHLD, &sa_, NULL) == -1) {
perror("sigaction");
return FAILURE;
}
return SUCCESS;
}
int SocketServer::listenForConnections() {
cout << "listenForConnections() :: Listening..." << endl;
int rc = SUCCESS;
while(1) {
sin_size_ = sizeof their_addr_;
cout << "waiting to accept " << endl;
new_fd_ = accept(sockfd_, (struct sockaddr *)&their_addr_, &sin_size_);
if(new_fd_ == -1) {
perror("accept");
rc = FAILURE;
continue;
}
inet_ntop(their_addr_.ss_family, get_in_addr((struct sockaddr *)&their_addr_), s_, sizeof s_);
printf("SocketServer: got connection from %s\n", s_);
if(!fork()) { //this is child process
close(sockfd_);
if (send(new_fd_, "Hello, world!", 13, 0) == -1) {
perror("send");
rc = FAILURE;
}
close(new_fd_);
}
close(new_fd_); //parent doesnt need this
}
return rc;
}
} //end ns
</code>
OUTPUT:
<code>
pacific@mainbox /workspace/WLFeeder/Debug$ ./WLFeeder
initAddrInfo() :: Initializing address ...
bindFirstPossible() :: ...
initListen() :: ...
clearDeadProcesses() :: ...
listenForConnections() :: Listening...
waiting to accept //Here I entered the telnet command again, in a seperate Konsole terminal ...
SocketServer: got connection from ::ffff:127.0.0.1 //works once
waiting to accept
accept: Bad file descriptor // then keeps giving errors ...
waiting to accept
accept: Bad file descriptor
waiting to accept
accept: Bad file descriptor
waiting to accept
accept: Bad file descriptor
waiting to accept
</code>
Find Your Dream Job in Australia, Free!
http://www.WebCV.com.au
|
|
|
|
|
The one thing I notice is that your fork ed process doesn't exit (unlike the equivalent code in Beej's guide)?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks a million Stuart, that did it !
I thought exit(0) was only to exit from a main routine or something,
did not realize it would exit from the if( ) { } routine ...
Gvanto
|
|
|
|
|
gvanto wrote: exit(0) was only to exit from a main routine or something
No, it exits the current process - of course, which process is 'current' can get confusing with *nix, as the fork function creates a new process by duplicating the caller, so you have to track the two code paths, the parent process (where fork returns the child PID) and the child process (wehere fork returns zero).
In some ways it's easier to work with than Win32's CreateProcess , in other ways not.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Ah ic, yeah that's what kind of got me I think. Not quite got the hang of these socket processes (and I'm pretty new to C++)
so still got a way to go. and a loooooooooong way before I start coding c++ in windows !
Thanks again for the help Stuart, much appreciated !
Best,
gvanto
|
|
|
|
|
hi all,
can anybody help me build an application having multilingual support using VC++.
thanks!!
Varun Bhatt
|
|
|
|
|
Check this[^]
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Thanks a lot Sarath,
but i had already tried this and lots of other examples on code project and codeguru.com and on various other sites but not really useful to get an clear idea about how to do this.
THough, now i have an obscure idea about the steps but can you tell me the stepwise procedure to proceed. i was trying the following example
ddj.com/184404314?pgno=1
but atlast it resulted the following error
d:\varun\mltest\mltest\mltest.h(10) : fatal error C1083: Cannot open include file: 'MLDLL\resource.h': No such file or directory
MLTestDlg.cpp
d:\varun\mltest\mltest\mltest.h(10) : fatal error C1083: Cannot open include file: 'MLDLL\resource.h': No such file or directory
i have tried a lot to solve this but failed, can you suggest any solution?
Varun Bhatt
|
|
|
|
|