|
One possibility is to use the document. I think the MFC Document/View architecture is desiged such that you can use the document as a common place to hold the data. There might be times when the document needs to get data from the view, such as when the data is being saved, and that is possible but a little more complicated than you might hope. What you can do is that very time the page is changed, the old page could update the document and the new page can refresh the data from the document. I hope you understand.
|
|
|
|
|
Hi!
I've a working VB6 code whose purpose is to set a file handle to Windows clipboard,
just as the system does when you select a file in Explorer and give the "Copy" command.
My function, SetClipboardFiles wants a string() [VB6] or vector<string> [C++] as input
argument, containing a list of valid Fully Qualified Paths.
VB6 code works correctly, which means that if you set in clipboard an existing
file and then you perform a "paste" operation in the windows Explorer the
file is correctly copied.
I've migrated it to C++, but it really doesn't work. Why??
Can anyone help me??
I attach the code, without specifying all dependencies.
If someone wants to get more involved in the subject, I will.
Tnx
Mike
==============================================================================================
VB6 Original working CODE
==============================================================================================
Public Function SetClipboardFiles(file_names() As String) As Boolean
'from http://www.vb-helper.com/howto_get_set_clipboard_files.html
Dim file_string As String
Dim drop_files As DROPFILES
Dim memory_handle As Long
Dim memory_pointer As Long
Dim i As Long
' Clear the clipboard.
Clipboard.Clear
' Open the clipboard.
If OpenClipboard(0) Then
' Build a null-terminated list of file names.
For i = LBound(file_names) To UBound(file_names)
file_string = file_string & file_names(i) & _
vbNullChar
Next
file_string = file_string & vbNullChar
' Initialize the DROPFILES structure.
drop_files.pFiles = Len(drop_files)
drop_files.fWide = 0 ' ANSI characters.
drop_files.fNC = 0 ' Client coordinates.
' Get global memory to hold the DROPFILES
' structure and the file list string.
memory_handle = GlobalAlloc(GHND, Len(drop_files) + _
Len(file_string))
If memory_handle Then
' Lock the memory while we initialize it.
memory_pointer = GlobalLock(memory_handle)
' Copy the DROPFILES structure and the
' file string into the global memory.
CopyMem ByVal memory_pointer, drop_files, _
Len(drop_files)
CopyMem ByVal memory_pointer + Len(drop_files), _
ByVal file_string, Len(file_string)
GlobalUnlock memory_handle
' Copy the data to the clipboard.
SetClipboardData CF_HDROP, memory_handle
ClipboardSetFiles = True
End If
' Close the clipboard.
CloseClipboard
End If
End Function
==============================================================================================
C++ Migrated Code (NOT WORKING)
==============================================================================================
int cCLIPBOARD::SetClipboardFiles(vector<string> svFQPath)
{
/*
Creates CF_HDROP objects according to elements
of svFQPath
This Function IS NOT OPERATIVE. Ci manca davvero poco, vacca!
*/
string file_string; //buffer to be passed to win-clip
int file_string_sz;
vector<string>::iterator iter;
DROPFILES drop_files;
int drop_files_sz;
HGLOBAL memory_handle;
LPVOID memory_pointer;
DROPFILES* pMem;
DROPFILES* pMem2;
void *memory_pointer_2;
int _return;
if (OpenClipboard(0) !=0)
{
// Pulizia clipboard
if (EmptyClipboard()== false){cout << "CRITICAL ERROR: EmptyClipboard call failed";}
// Builds a null-terminated list of filenames
for (iter = svFQPath.begin(); iter < svFQPath.end(); iter++)
{file_string = file_string + *iter + '\0' ;}
file_string = file_string + '\0';
file_string_sz = file_string.size(); //13
// Initilalises DROPFILES struct
drop_files_sz = sizeof(drop_files); //20
drop_files.pFiles = drop_files_sz;
drop_files.fWide = 0; //ANSI CHARACTERS
drop_files.fNC = 0; //Client Coordinates
drop_files.pt.x =0 ;
drop_files.pt.y=0;
debug << "\n drop_files_sz = " << drop_files_sz;
// Get global memory to hold the DROPFILES structure and the file list string
memory_handle = GlobalAlloc(GHND,
drop_files_sz + file_string_sz);
if (memory_handle !=0)
{
// Lock the memory while we initialize it.
memory_pointer = LPVOID(GlobalLock(memory_handle));
// Copy 'drop_files' and "file_string'
//into the global memory
memcpy(memory_pointer,
&drop_files,
sizeof(drop_files));
memory_pointer_2 =reinterpret_cast<void*>(int(memory_pointer)
+ drop_files_sz) ; //drop_files_sz;
memcpy(memory_pointer_2,
file_string.c_str(),
file_string_sz);
pstr = (char*) memory_pointer_2;
// Releasing memory
GlobalUnlock(memory_handle);
// Copying the data from memory_handle to win-clip
if (SetClipboardData(CF_HDROP, HANDLE(memory_handle))!= 0)
_return = 1;
}
else
{_return = 0;}
CloseClipboard();
}
return 1;
}
|
|
|
|
|
So where's the problem? Please do not paste a whole wad of code and expect us to wade through it. Narrow it down to a few statements and we'll focus on those.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Actually, I don't know where the problem is!
I simply translated the VB6 code in C++, but it doesn't work (though no error is given).
An alternative solution would be: does anyone know how to set a CF_HDROP data type
to WINDOWS CLIPBOARD? I found lot of examples with text and images, but not with
file handles...
I put code chunks cause they should give exactly the same result, but they don't.
The idea was comparing them...
|
|
|
|
|
If your VB code works ok, but your C code doesn't work (although no compiling errors), why don't you try to execute both codes debugging step by step and compare intern variables, returns and so on. That way you should be able to isolate where the problem exactly is, and with this section, then come back to forum. Im sure that you will have a perfect answer to help you from anyone of the good programmers that are here.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
What exactly is _return being used for?
|
|
|
|
|
I SOLVED THE PROBLEM!
MSDN says EmptyClipboard() call provides the Win Clipboard
being released from avery thread previously attached to
it. Therefore, the OpenClipboard(NULL) call I perform
is vanified by subsequent EmptyClipboard(), and
I need one more OpenClipboard call.
THE STRANGE THING IS THAT THIS IS PERFECTLY TRUE IN C++,
BUT NOT IN VB6, FROM WHICH I WAS MIGRATING THE CODE!!!
mAH?
|
|
|
|
|
hello!
I`m not a choleric person, but this time i`m 2 steps away from madness!
I need to copy a file from one folder to another, so I`ve learned that i have to use
File.Copy, which is found in mscorlib.dll
I cannot find mscorlib.dll. Moreover, I don`t know how to link a lib to my project, so I usually simply "add existing item..." to my solution, and things just work. Only that this time it seems I can`t find the right mscorlib.dll
I have installed Visual Studio 2005, SP1, SDK for SmartDevices (WIN CE 5.0 and 6.0) - needed for some applications.
Visual Studio is installed in D:\Program Files\
I`ve seen that I have to download .NET Framework 2.0 (or 3.0), and I have downloaded them both from microsoft`s site.
Now, by searching my computer, i find 3 results of mscorlib.dll, in:
D:\Program Files\Microsoft Visual Studio 8\SmartDevices\SDK\CompactFramework\2.0\v1.0\WindowsCE
C:\Program Files\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE
C:\Program Files\Microsoft.NET\SDK\CompactFramework\v2.0\Debugger\BCL
(.Net installs itself without configuring the path)
(Where the hell is v3.0 ?!)
Long story short, how can I get to use File.Copy ?
I have seen that I must write:
<br />
#using <mscorlib.dll><br />
using namespace System;<br />
using namespace System::IO;<br />
By simply writing those lines, without any adding of that lib to my project (or adding any of those 3) I get errors on "identifiers not found".
I `ve seen that mscorlib.dll appears in many System related functions, so I hope someone will know how to make it work...
While waiting for this answer, I`m using fopen to continue working with the data, but I can`t finish my application without create folder and file.copy.
Many thanks for any suggestion!
Shpid3r
|
|
|
|
|
You shouldn't need to pull in mscorlib.dll - it's done automatically.
It looks to me like you're trying to use .NET classes in a native application.
Please post EXACT error messages so we don't have to guess
Also, if you're really writing managed code, please post your questions here:
(Managed) C++/CLI[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Right... It does seem like i`m trying to use native/managed code. But that is not true. This time, it`s a win32 application, not intended for a smart device. Those WinCE findings are simply because I have installed the SDK for native coding.
Anyway, i`m adding my code and my errors:
Code:
<br />
#using < mscorlib.dll ><br />
using namespace System;<br />
using namespace System::IO;<br />
[...].br />
<br />
FileStream^ xmlRegister = File::OpenRead("Settings.ini");<br />
Errors:
<br />
.\ADN FixDlg.cpp(99) : error C2065: 'FileStream' : undeclared identifier<br />
.\ADN FixDlg.cpp(99) : error C2065: 'xmlRegister' : undeclared identifier<br />
.\ADN FixDlg.cpp(99) : error C2653: 'File' : is not a class or namespace name<br />
.\ADN FixDlg.cpp(99) : error C3861: 'OpenRead': identifier not found<br />
Build log was saved at "file://c:\Documents and Settings\Vlad\My Documents\Visual Studio 2005\Projects\ADN Fix\ADN Fix\Release\BuildLog.htm"<br />
ADN Fix - 4 error(s), 0 warning(s)<br />
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========<br />
|
|
|
|
|
Huh?
shpid3r wrote: it`s a win32 application,
To me, a Win32 application is native code. In that case you can't use .NET classes.
Everything you're showing is managed/.NET-related.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Then let me explain how I am creating the project:
First of all, i select visual c++
From there, i select MFC ( if I had chosen Smart Devices, it would have been managed )
Then, MFC Application
After that, I start configuring my application - dialog based, winsockets etc
I am afraid I don`t understand what you mean by .NET classes ... I have seen that mscorlib.dll functions are descriped on a page with a note that the info applies to .NET Framework 3.0 and which provides links to .NET Framework 2.0 and 1.1 for the same information (please see the first link in my initial question)
Shpid3r
|
|
|
|
|
mscorlib is part of the .NET framework.
The System.IO.FileStream class is also in the .NET framework.
The only way you can use classes in the .NET framework from C++ is
using managed code - code compiled to CLR.
An MFC application, by default, is a native application - not compiled to CLR.
There's plenty of ways to access files without using the .NET framework, but
if you want to use .NET, you have to compile the code which uses it to CLR.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Well then, that`s an A answer...
This being told... how can I copy a file without using .net framework ? i don`t 'want' to use .net... I simply thought I had to...
|
|
|
|
|
shpid3r wrote: how can I copy a file without using .net framework ?
A variety of ways...
If you're not concerned with ANSI C++ portablility and you're targeting Windows
You could use CopyFile()[^], CopyFileEx()[^], SHFileOperation()[^]
There's also numerous ways to open, read, write, close files if you want to do the work yourself.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Many thanks, Mark!
Problem solved
Shpid3r
|
|
|
|
|
Mark Salsbery wrote:
There's also numerous ways to open, read, write, close files if you want to do the work yourself.
'Twas one of my first C programs. What a rush that was!
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
What version of visual studio are you using ? one of the "express" versions ? If that's one of those, then you cannot do MFC.
|
|
|
|
|
Actually I`m using VS 8 Pro... and I`m able to download anything (i`m a student and my university is a member of MSDN Academic Alliance)
|
|
|
|
|
Mark Salsbery wrote: You shouldn't need to pull in mscorlib.dll
that's correct you need to reel it in.
|
|
|
|
|
|
Hi
Is there class or function set for working with INI sections not in file, but in set of strings?
I have some database with one text field which contains content of INI file. But I haven't possibility to write this to file on disk and read it after that.
Rgds,
Ernst
|
|
|
|
|
have you searched the web before asking ?
is CIni[^] of any help ?
|
|
|
|
|
toxcct wrote: is CIni[^] of any help ?
Doesn't this class require a file to operate on?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Can I set an application to run each time with a certain priority without chainging from Windows task manager?
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|