|
-
August 31st, 2011, 03:54 AM
#1
Copy to clipboard
Hi,
I'm triying to copy some information to clipboard but I have a problem when I want open the file "temporal.dat". The aplication never open the file. I have other application with the same code and everything run perfectly. Could you help me?
This is my code
Code:
void CAdestView::CopiarVariables()
{
int sel=-1; // Nos indicara el elemento que esta seleccionado
CString aux_nomb; // Almacena el nombre para comparar
FILE *fichero; // Nombre del fichero temporal
int x=0; // Numero de elementos copiados
CString nombre_b; // Nombre temporal de la variable para copiar en el fichero
CString ausente_b; // Valor ausente temporal de la variable para copiar en el fichero
CString etiqueta_b; // Etiqueta temporal de la variable para copiar en el fichero
CString labels_b; // Labels char labels_b[30]; //
CString datostxt;
int t=0;
// Se abre el fichero para escritura
fichero= fopen("\\temporal.dat","wb");
// Se obtiene un puntero de la clase view
CAdestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(!fichero)
{
MessageBox(_T("No se pudo abrir el fichero"), _T("Error"), 0x10010);
return;
}
// Bucle para determinar el numero de elementos a copiar
do
{
sel = m_Lista.GetNextItem(sel,LVNI_SELECTED);
aux_nomb=m_Lista.GetItemText(sel,0);
if (sel!=-1)
x++;
}while (sel != -1);
// Abro el portapapeles
if(!OpenClipboard())
{
MessageBox(_T("No se pudo abrir el portapapeles"), _T("Error"), 0x10010);
return;
}
// Registro el formato Datos Adest
UINT cf= RegisterClipboardFormat(_T("Variables Adest"));
const char *text3 = "";
HGLOBAL hText = GlobalAlloc(GMEM_MOVEABLE |GMEM_DDESHARE, strlen(text3)+1);
char *ptr = (char *)GlobalLock(hText);
strcpy(ptr, text3);
GlobalUnlock(hText);
SetClipboardData(cf, hText);
// Cierro el portapapeles
CloseClipboard();
// Se situa el puntero del fichero donde apunta el cursor
fseek(fichero,sizeof(int),SEEK_SET);
// Se escribe el numero de elementos a copiar
fwrite(&x,sizeof(int),1,fichero);
INT_PTR contador=0;
contador=pDoc->Variables.GetSize();
// Bucle para copiar todos los elementos seleccionados
do
{
sel = m_Lista.GetNextItem(sel,LVNI_SELECTED);
aux_nomb = m_Lista.GetItemText(sel,0);
for (int i=0;i<contador;i++)
{
CDatos* pDat = (CDatos*)pDoc->Variables.GetAt(i);
// El nombre debe coincidir
if (pDat->Nombre == aux_nomb)
{
// Se copia el nombre a la variable temporal del fichero
nombre_b=pDat->Nombre;
// Se escribe en el fichero el tamaño
fwrite(&pDat->Tam,sizeof(int),1,fichero);
// Se escribe en el fichero el nombre
fwrite(&nombre_b,sizeof(CString)*30,1,fichero);
// Se escribe en el fichero el tipo
fwrite(&pDat->Tipo,sizeof(int),1,fichero);
// Dependiendo del tipo de variable se escribe en el
// fichero unos u otros datos
if(pDat->Tipo==0)
{
for(t=0;t<pDat->Tam;t++)
//Se escriben los datos en el fichero
fwrite(&pDat->Datos[t],sizeof(double),1,fichero);
}
else
{
for(t=0;t<pDat->Tam;t++)
{
//Se escriben los datos en el fichero
datostxt=pDat->Dat_Txt[t];
fwrite(&datostxt,sizeof(CString)*20,1,fichero);
}
}
// Se copia el dato ausente a la variable temporal del fichero
ausente_b=pDat->Ausente;
// Se escribe en el fichero el dato ausente
fwrite(&ausente_b,sizeof(CString)*10,1,fichero);
// Se escribe en el fichero la escala
fwrite(&pDat->Escala,sizeof(int),1,fichero);
// Se copia la etiqueta a la variable temporal del fichero
etiqueta_b=pDat->Etiqueta;
// Se escribe en el fichero la etiqueta temporal
fwrite(&etiqueta_b,sizeof(CString)*100,1,fichero);
// Se copia las labels a la variable temporal del fichero
labels_b=pDat->Labels;
// Se escribe en el fichero las labels temporal
fwrite(&labels_b,sizeof(CString)*80,1,fichero);
// Se escribe en el fichero la precision
fwrite(&pDat->Precision ,sizeof(int),1,fichero);
}
}
}while (sel != -1);
// Se cierra el fichero
fclose(fichero);
}
-
August 31st, 2011, 04:11 AM
#2
Re: Copy to clipboard
 Originally Posted by a343
Hi,
I'm triying to copy some information to clipboard but I have a problem when I want open the file "temporal.dat". The aplication never open the file.
...
This is my code
Code:
void CAdestView::CopiarVariables()
{
...
// Se abre el fichero para escritura
fichero= fopen("\\temporal.dat","wb");
...
// Se cierra el fichero
fclose(fichero);
}
You write you "want to open the file "temporal.dat". But in your code you are trying to open the "\\temporal.dat" file!
Victor Nijegorodov
-
August 31st, 2011, 04:25 AM
#3
Re: Copy to clipboard
I meant "\\temporal.dat". I'm sorry.
-
August 31st, 2011, 04:29 AM
#4
Re: Copy to clipboard
 Originally Posted by a343
I meant "\\temporal.dat". I'm sorry.
But does the file \temporal.dat exist? 
Try to open (just copy/paste this name) \temporal.dat in Windows explorer or in cmd console...
Victor Nijegorodov
-
August 31st, 2011, 04:48 AM
#5
Re: Copy to clipboard
I can't find the file how "\\temporal.dat" or "\temporal.dat" but I look in windows explorer how "temporal.dat" and I find the file in C:\Users\Antonio\AppData\Local\VirtualStore
But in other aplicattion I have the same code with "\\temporal.dat" and everything run perfectly.
What happen?
How I must to edit my code?
Last edited by a343; August 31st, 2011 at 05:17 AM.
-
August 31st, 2011, 07:16 AM
#6
Re: Copy to clipboard
Why are you putting the slash in front of the file name?
-
August 31st, 2011, 10:09 AM
#7
Re: Copy to clipboard
Becouse is the direction of this file. That mean that the file is in the unit C: or the unit where is the windows file
-
August 31st, 2011, 10:30 AM
#8
Re: Copy to clipboard
Are you sure it is correct?
Where did you read any info about such a meaning of backslash?
Victor Nijegorodov
-
August 31st, 2011, 11:23 AM
#9
Re: Copy to clipboard
I'm not sure, I had this code from other person who did my project before.
If you know other way to do this function, tell me
Maybe it is not like this, but I saw in this web something like that
http://copstone.com/2009/12/abrir-ap...ernas-desde-c/
Last edited by a343; August 31st, 2011 at 11:26 AM.
-
August 31st, 2011, 11:35 AM
#10
Re: Copy to clipboard
Putting a (forward) / before a path indicates it is an absolute path on Linux/Unix. I don't know whether or not \ has a similar meaning on Windows.
-
August 31st, 2011, 11:38 AM
#11
Re: Copy to clipboard
 Originally Posted by a343;2031377Maybe it is not like this, but I saw in this web something like that
[url
http://copstone.com/2009/12/abrir-aplicaciones-externas-desde-c/[/url]
I don't see anything similar to the file name beginning with backslash in the site you referred to.
If you see - please, post the quote.
Victor Nijegorodov
-
August 31st, 2011, 12:33 PM
#12
Re: Copy to clipboard
Now, I put my path, where is the file, "C:\\Users\Antonio\AppData\Local\VirtualStore", but it can't open the file. Why???
-
August 31st, 2011, 12:37 PM
#13
Re: Copy to clipboard
 Originally Posted by a343
Now, I put my path, where is the file, "C:\\Users\Antonio\AppData\Local\VirtualStore", but it can't open the file. Why???
This path is wrong.
Please, show the exact code snippet where you pass in the path and file name to open the file.
Victor Nijegorodov
-
August 31st, 2011, 12:40 PM
#14
Re: Copy to clipboard
 Originally Posted by a343
Now, I put my path, where is the file, "C:\\Users\Antonio\AppData\Local\VirtualStore", but it can't open the file. Why???
How would we know?? From MSDN "Always check the return value to see if the pointer is NULL before performing any further operations on the file. If an error occurs, the global variableerrno is set and may be used to get specific error information. For further information, see errno."
I think Victor is alluding to the possibility that you're not using escape characters correctly in your string literal.
What does this problem have to do with your thread title?
-
August 31st, 2011, 01:34 PM
#15
Re: Copy to clipboard
Please read the code of the function, it copies informations to clipboard.
Victor, you are right. But my aplication will run in several computer, and I need some way to put the path in general way not only my path
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|