|
Can any move to solve this problem.
After all change I am gotted any solution ...
Please advise me for solving this;)
Regard's
Kaushik
|
|
|
|
|
You dont have any code for write on the if block you have a write to file on the else block.
|
|
|
|
|
I think first time i have seen when WhiteSky has given the code directly instead of link.
Well, I have nothing to do with it. It's good that you are replying and helping the programmers in any way you can. Good.
|
|
|
|
|
Anurag Gandhi wrote: I think first time i have seen when WhiteSky has given the code directly instead of link.
Don't you like links, do you?
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.
|
|
|
|
|
Oh no its not first time it seems to question for example on this question a link arent helpful for asker because he wrote his code but needs to help but for some question if we see an article is better for asker.;)
|
|
|
|
|
Below is the code to save the file that i am using to save the text file.
I hope you will understand each line of it. It is very easy.
CStdioFile file;
if(!file.Open(lpszPathName,CFile::modeCreate | CFile::modeWrite, 0))
{
AfxMessageBox(CString("File cannot be Saved. Please Check if the file is read only."));
return FALSE;
}
long nLen = reinterpret_cast<ceditview*>(m_viewList.GetHead())->GetWindowTextLengthW();
TCHAR* pSaveText = new TCHAR[nLen+1];
reinterpret_cast<ceditview*>(m_viewList.GetHead())->GetWindowText(pSaveText,nLen + 1);
file.WriteString(pSaveText);
file.Close();
|
|
|
|
|
Can u told me in your code
AfxMessageBox(CString("File cannot be Saved. Please Check if the file is read only."));
return FALSE;
When function return type void how we return FALSE ?
Second
What is m_viewList ?? I think its mamber variable of List
What is pSaveText ?? I think Its data which I have to read from file
Regard's
Kaushik
|
|
|
|
|
I am simplifying my answer according to your need.
CStdioFile file;
if(!file.Open(lpszPathName,CFile::modeCreate | CFile::modeWrite, 0))
{
AfxMessageBox(CString("File cannot be Saved. Please Check if the file is read only."));
return;
}
CString strTextToSave = _T("This text will be saved to the file.");
file.WriteString(strTextToSave);
file.Close();
Hope it is clear.
For Your Information:
The code i have given you was from one of my project where I called FileSave function in CProjectDocument Class and was retriving the text from EditView Window.
|
|
|
|
|
Dear Sir
I have write this code for write data on file I can Create file in my user folder but Nothing data is write
Can u give me any correct solution for this OR Told me where I am wrong
CString str;
int ids;
CFileDialog Obj(TRUE);
if(Obj.DoModal() ==IDC_BUTTON3)
{
m_Upload = Obj.GetFileName();
}
str.Empty();
str = Obj.GetPathName();
SetDlgItemText(IDC_EDIT1,str); //write file path with name at edit box
CString strLine = "";
CString buffer = "";
CStdioFile fileObj;
CString fname;
fileObj.Open(str, CFile::modeRead | CFile::shareDenyWrite);
fname = fileObj.GetFileName();
while(fileObj.ReadString(strLine))
{
buffer += strLine + "\r\n";
}
fileObj.Close();
// MessageBox(buffer);
SetDlgItemText(IDC_EDIT3,buffer);////write all data at another edit box
fileObj.Open("c:\\UserFolder\\" + fname + ".txt",CFile::modeCreate,NULL);
CString dataStr;
GetDlgItemText(IDC_EDIT3,dataStr);
CStdioFile file;
if(!file.Open(str,CFile::modeCreate | CFile::modeWrite, 0))
{
AfxMessageBox(CString("File cannot be Saved. Please Check if the file is read only."));
return;
}
CString strTextToSave = _T("This text will be saved to the file.");
file.WriteString(dataStr);
file.Close();
Regard's
Kaushik
|
|
|
|
|
In second last line:
<br />
file.WriteString(dataStr);<br />
You didn't assign any value to dataStr; The default value is empty string that's why you are getting empty string.
|
|
|
|
|
First off all Thanks for your reply
secondly
Sir I think u r not gotted my exact problem. Sir Ji I have my text data
in "dataStr" which i want to save at that file whatever i have create.
According to code I am trying to do this...
When user click browse button whole HD show The user select any one file for saving it in to another folder. [Its work something like File field in HTML ]
Then
Suppose I have select a file D:\Test\document.txt. Now
I have create a file name "document.txt" in UserFolder in C Drive
Now I want to save all contant(data) of D:\Test\document.txt in to
C:\UserFolder\document.txt
Till Now I can create a file in C:\UserFolder\document.txt
but can not write data from D:\Test\document.txt to C:\UserFolder\document.txt I found file in C drive Empty
Can u solve this problem If so ............Please
Regard's
Kaushik
|
|
|
|
|
Debug your application and check where the priblem is.
or
Try something like this: And be sure not to use fileObj.Close() before the following code:
fileObj.SeekToBegin();
while(fileObj.ReadString(strLine))
{
strLine += "\r\n";
buffer += strLine;
file.WriteString(strLine);
}
file.Close();
fileObj.Close();
This is reading one file line by line and writing to another file.
|
|
|
|
|
sir
I am writing this code
CStdioFile file;
if(!file.Open(str,CFile::modeCreate | CFile::modeWrite, 0))
{
AfxMessageBox(CString("File cannot be Saved. Please Check if the file is read only."));
return;
}
file.SeekToBegin();
while(file.ReadString(buffer))
{
buffer += "\r\n";
strLine+= buffer;
file.WriteString(buffer);
}
file.Close();
fileObj.Close();
Program comlpile successfully But when i run it Its Show
File cannot be Saved. Please Check if the file is read only
Message . Can u told me where need to change
Regard's
Kaushik
|
|
|
|
|
Well, the last block of you code, i.e.
if(! myFile.Open( strFileName, CStdioFile::modeCreate | CStdioFile::modeWrite
| CStdioFile::modeNoTruncate, &e ) )
{
...
}
(with very little modifications) works fine on my system.
I suggest, again, to use thew debugger: inspect the myFile object runtime content, m_strFileName member looks interesting.
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.
|
|
|
|
|
woyld u like to Share your little modification with me
so that i can also Implement it
Regard's
Kaushik
|
|
|
|
|
My modifications are of no importance, I had to do them to make that piece of code run on my system, I just changed the myFile path and initialized strLine with a string. Anyway I don't want to hide anything: the code snipped is below:
void CMFCTestDlg::WriteOnFile(LPCSTR strFileName)
{
CStdioFile myFile;
CFileException e;
if(! myFile.Open( strFileName, CStdioFile::modeCreate | CStdioFile::modeWrite
| CStdioFile::modeNoTruncate, &e ) )
{
CString failCause = "Unable to open file. Reason : ";
switch (e.m_cause) {
case CFileException::none:
failCause += "No error occurred.";
break;
case CFileException::generic:
failCause += "An unspecified error occurred.";
break;
case CFileException::fileNotFound:
failCause += "The file could not be located.";
break;
case CFileException::badPath:
failCause += "All or part of the path is invalid.";
break;
case CFileException::tooManyOpenFiles:
failCause += "The permitted number of open files was exceeded.";
break;
case CFileException::accessDenied:
failCause += "The file could not be accessed.";
break;
case CFileException::invalidFile:
failCause += "There was an attempt to use an invalid file handle.";
break;
case CFileException::removeCurrentDir:
failCause += "The current working directory cannot be removed.";
break;
case CFileException::directoryFull:
failCause += "There are no more directory entries.";
break;
case CFileException::badSeek:
failCause += "There was an error trying to set the file pointer.";
break;
case CFileException::hardIO:
failCause += "There was a hardware error.";
break;
case CFileException::sharingViolation:
failCause += "SHARE.EXE was not loaded, or a shared region was locked.";
break;
case CFileException::lockViolation:
failCause += "There was an attempt to lock a region that was already locked.";
break;
case CFileException::diskFull:
failCause += "The disk is full.";
break;
case CFileException::endOfFile:
failCause += "The end of file was reached.";
break;
default:
failCause += "Unknown cause.";
break;
}
AfxMessageBox(failCause);
}
else
{
myFile.SeekToEnd();
CString strLine = "foo";
strLine += "\r\n";
myFile.WriteString(strLine);
myFile.Close();
}
}
and the call follows:
WriteOnFile("MFCFoo.txt");
It outputs the MFCFoo.txt text file containing foo (at each call the file is augmented).
Hope that helps (again, use the debugger)
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.
|
|
|
|
|
Set a breakpoint on the first statement, and then single-step through each successive statement, observing variables along the way. Anything short of that and you are not really asking for help.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
hello to all..
my question :
i have some codes of OPENGL.
now i want to import it in VC++.
|
|
|
|
|
Can you be more specific.
|
|
|
|
|
thank u for reply..
actually below codes are opengraphical language(OpenGL)..
this program should be called in VC++ ..
how i have to call in my program..
help me..
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <gl glut.h="">
/*
* Window properties
*/
#define WINDOW_WIDTH 500
#define WINDOW_HEIGHT 500
#define WINDOW_X 100
#define WINDOW_Y 100
#define WINDOW_TITLE "RGB-ColorCube"
/*
* Perspective properties
*/
#define FOV_ANGLE 30
#define CENTER_X 0.0
#define CENTER_Y 0.0
#define CENTER_Z 0.0
#define VIEWER_X 0.0
#define VIEWER_Y 0.0
#define VIEWER_Z -2.1
#define UP_X 0.0
#define UP_Y 1.0
#define UP_Z 0.0
#define CLIPPLANE_NEAR 1.0
#define CLIPPLANE_FAR 20.0
#define ROTATION_SPEED 2.0
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
GLfloat rot_x = 0.0, rot_y = 0.0;
GLfloat saved_x, saved_y;
/*
* Material colors used for shading
*/
GLfloat red[4] = {.8, 0.0, 0.0, 1.0};
GLfloat white[4] = {.8, .8, .8, 1.0};
/*
* Function prototypes
*/
void usage(void);
void draw_scene(void);
void draw_object(void);
void init(int argc, char **argv, void (*draw)(void));
void save_position(int button, int state, int x, int y);
struct point get_coords(double a, double b);
void vertex(double a, double b);
void rotate(int x, int y);
void set_color(int angle);
int main(int argc, char **argv) {
/*
* Init OpenGL and enter the event loop
*/
init(argc, argv, draw_scene);
return 0;
}
/*
* Handle rotations and buffer swapping and call the function draw_object
* which does the actual drawing
*/
void draw_scene(void) {
static GLfloat old_rot_matrix[16];
static int initialized = 0;
GLfloat new_rot_matrix[16];
/* calculate new rotation matrix */
glPushMatrix();
glLoadIdentity();
glRotatef(rot_x, 1.0, 0.0, 0.0);
glRotatef(rot_y, 0.0, 1.0, 0.0);
glGetFloatv(GL_MODELVIEW_MATRIX, new_rot_matrix);
glPopMatrix();
/* calculate total rotation */
glPushMatrix();
glLoadIdentity();
glMultMatrixf(new_rot_matrix);
if (initialized) {
glMultMatrixf(old_rot_matrix);
}
glGetFloatv(GL_MODELVIEW_MATRIX, old_rot_matrix);
initialized = 1;
glPopMatrix();
glPushMatrix();
glMultMatrixf(old_rot_matrix);
draw_object();
glPopMatrix();
glFlush();
glutSwapBuffers();
}
/*
* Initialize the OpenGL machine
*/
void init(int argc, char **argv, void (*draw)(void)) {
GLfloat light0_pos[] = {100.0, 100.0, 100.0, 1.0};
GLfloat light0_color[] = {1.0, 1.0, 1.0, 1.0};
GLfloat ambient_light[] = {0.8, 0.8, 0.8, 1.0};
glutInit(&argc, argv);
/* Create a window */
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
glutInitWindowPosition(WINDOW_X, WINDOW_Y);
glutCreateWindow(WINDOW_TITLE);
glClearColor(0.0, 0.0, 0.0, 0.0);
/* Set up some light sources */
glLightfv(GL_LIGHT0, GL_POSITION, light0_pos);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_color);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient_light);
glEnable(GL_LIGHT0);
/* glEnable(GL_LIGHTING); */
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
/* Create a viewing frustum */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(FOV_ANGLE, WINDOW_WIDTH/WINDOW_HEIGHT, CLIPPLANE_NEAR,
CLIPPLANE_FAR);
gluLookAt(VIEWER_X, VIEWER_Y, -VIEWER_Z, CENTER_X, CENTER_Y, CENTER_Z,
UP_X, UP_Y, UP_Z);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(VIEWER_X, VIEWER_Y, VIEWER_Z);
glutDisplayFunc(draw);
glutMouseFunc(save_position);
glutMotionFunc(rotate);
glutMainLoop();
/* Not reached */
}
/*
* Save the position of the mouse pointer where the bottun press occured
*/
void save_position(int button, int state, int x, int y) {
if (state == GLUT_DOWN) {
saved_x = x;
saved_y = y;
}
}
/*
* Calculate the angle the object has rotated by since the last update
*/
void rotate(int x, int y) {
rot_y = (GLfloat)(x - saved_x) * ROTATION_SPEED;
rot_x = (GLfloat)(y - saved_y) * ROTATION_SPEED;
saved_x = x;
saved_y = y;
glutPostRedisplay();
}
/*
* Draw a object
*/
void draw_object(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_QUAD_STRIP);
glNormal3f(0,0,1);
glColor3f(0,0,0);
glVertex3f(-0.5,-0.5,-0.5);
glColor3f(0,1,0);
glVertex3f(-0.5,0.5,-0.5);
glColor3f(1,0,0);
glVertex3f(0.5,-0.5,-0.5);
glColor3f(1,1,0);
glVertex3f(0.5,0.5,-0.5);
glNormal3f(1,0,0);
glColor3f(1,0,1);
glVertex3f(0.5,-0.5,0.5);
glColor3f(1,1,1);
glVertex3f(0.5,0.5,0.5);
glNormal3f(0,0,1);
glColor3f(0,0,1);
glVertex3f(-0.5,-0.5,0.5);
glColor3f(0,1,1);
glVertex3f(-0.5,0.5,0.5);
glNormal3f(-1,0,0);
glColor3f(0,0,0);
glVertex3f(-0.5,-0.5,-0.5);
glColor3f(0,1,0);
glVertex3f(-0.5,0.5,-0.5);
glEnd();
glBegin(GL_QUADS);
glNormal3f(0,1,0);
glColor3f(0,1,0);
glVertex3f(-0.5,0.5,-0.5);
glColor3f(0,1,1);
glVertex3f(-0.5,0.5,0.5);
glColor3f(1,1,1);
glVertex3f(0.5,0.5,0.5);
glColor3f(1,1,0);
glVertex3f(0.5,0.5,-0.5);
glEnd();
glBegin(GL_QUADS);
glNormal3f(0,-1,0);
glColor3f(0,0,0);
glVertex3f(-0.5,-0.5,-0.5);
glColor3f(0,0,1);
glVertex3f(-0.5,-0.5,0.5);
glColor3f(1,0,1);
glVertex3f(0.5,-0.5,0.5);
glColor3f(1,0,0);
glVertex3f(0.5,-0.5,-0.5);
glEnd();
}
|
|
|
|
|
I guess you got errors when compile this code,right? it was better you used of pre tags for your code.;)
|
|
|
|
|
Hi
I am preparing an .asmx file that calls a c++ class using its .dll
and generates output in .xml format.But I want output in HTML format.
To ganarate HTML output I have used wsdl "useService" and "callService" functions in html file.
But when i run this from from localhost it gives error "Client Service unavailable" Can anyone tell me plz how to resolve this problem.:
I m giving my html file
//CPPWebService.html
var n = 10;
var iCallID;
var callObj;
function init1()
{
s.useService("http://localhost/MyWebServices/CPPWebService.asmx?WSDL","yyy");
var headObj = new Object();
callObj = s.createCallOptions();
callObj.async = false;
callObj.funcName = "MyMethod";
callObj.SOAPHeader = new Array();
callObj.SOAPHeader[0] = headObj;
oSPAN.innerText = "Number returned is";
iCallID = s.yyy.callService(MyResults, callObj);
MyResults(iCallID);
alert("Over");
alert(iCallID.value);
}
function MyResults(result)
{
alert(result.value);
if(result.error){
var xfaultcode = result.errorDetail.code;
var xfaultstring = result.errorDetail.string;
var xfaultsoap = result.errorDetail.raw;
oSPAN.innerText = xfaultcode + " " + xfaultstring + " " + xfaultsoap;
alert(xfaultcode +xfaultstring +xfaultsoap);
}
else{
// Show the arithmetic
oSPAN.innerText += result.value;
alert(result.value);
}
}
function aaa()
{
alert(event.result.value + ' ' + event.result.id);
}
Equation :
//CPPWebService.asmx
<%@ WebService Language="C#" Class=CPPWebService.MyService %>
it use c++ class
that is as follows
#include "stdafx.h"
#using <mscorlib.dll>
#using "System.Web.dll"
#using "System.Web.Services.dll"
using namespace System;
using namespace System::Web;
using namespace System::Web::Services;
#include "CPPWebService.h"
namespace CPPWebService
{
int MyService::MyMethod()
{
return 42;
}
};
Thax in advance
Pankaj Jain
|
|
|
|
|
Hi,
In my application i need customized menu.(i.e)i need only one menu .
So that i delete the menus already in IDR_MAINFAME like i delete help,view etc.
Thus i leave File menu as it is and delete other than that.
And i coded OnCreateClient() fucntion as
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
CMenu* pMenu = NULL;
if (m_hMenuDefault == NULL)
{
pMenu = GetMenu();
ASSERT(pMenu != NULL);
int iMenu = pMenu->GetMenuItemCount() - 2;
ASSERT(iMenu <= 0);
pMenu = pMenu->GetSubMenu(iMenu);
ASSERT(pMenu == NULL);
}
return CMDIFrameWnd::OnCreateClient(lpcs, pContext);
}
But i got assertion error in CMainFrame::Oncreate().
My requirement is i need only one menu.
How can i get that.Pls help me.
Anu
|
|
|
|
|
Try after putting all your code in or after CMainFrame::Oncreate() function.
I don't know whether the function:
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
is called before or after the OnCreate function. You can access the menu programmatically only after your frame window and menu has been created.
|
|
|
|
|
Try doing this
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
return CMDIFrameWnd::CreateClient(lpcs, NULL);
}
|
|
|
|
|