Click here to Skip to main content
15,891,033 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to exchange message between different pages in tab control? Pin
PJ Arends6-Nov-07 9:45
professionalPJ Arends6-Nov-07 9:45 
GeneralRe: How to exchange message between different pages in tab control? Pin
Maximilien6-Nov-07 9:51
Maximilien6-Nov-07 9:51 
GeneralRe: How to exchange message between different pages in tab control? Pin
Panamk6-Nov-07 10:55
Panamk6-Nov-07 10:55 
GeneralRe: How to exchange message between different pages in tab control? Pin
Panamk6-Nov-07 13:38
Panamk6-Nov-07 13:38 
GeneralRe: How to exchange message between different pages in tab control? Pin
Panamk6-Nov-07 13:39
Panamk6-Nov-07 13:39 
GeneralRe: How to exchange message between different pages in tab control? Pin
Nelek6-Nov-07 21:49
protectorNelek6-Nov-07 21:49 
AnswerRe: How to exchange message between different pages in tab control? Pin
Sam Hobbs6-Nov-07 15:57
Sam Hobbs6-Nov-07 15:57 
QuestionWindows Clipboard in C/C++: Migrating from VB6 to C Pin
Capitanevs6-Nov-07 7:22
Capitanevs6-Nov-07 7:22 
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
MikeBlush | :O

==============================================================================================
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;

}
AnswerRe: Windows Clipboard in C/C++: Migrating from VB6 to C Pin
David Crow6-Nov-07 7:43
David Crow6-Nov-07 7:43 
GeneralRe: Windows Clipboard in C/C++: Migrating from VB6 to C Pin
Capitanevs6-Nov-07 12:22
Capitanevs6-Nov-07 12:22 
GeneralRe: Windows Clipboard in C/C++: Migrating from VB6 to C Pin
Nelek6-Nov-07 21:46
protectorNelek6-Nov-07 21:46 
AnswerRe: Windows Clipboard in C/C++: Migrating from VB6 to C Pin
bob169726-Nov-07 16:53
bob169726-Nov-07 16:53 
AnswerPROBLEM WEIRDLY SOLVED Pin
Capitanevs12-Nov-07 11:33
Capitanevs12-Nov-07 11:33 
QuestionMSCORLIB.DLL Pin
shpid3r6-Nov-07 7:16
shpid3r6-Nov-07 7:16 
AnswerRe: MSCORLIB.DLL Pin
Mark Salsbery6-Nov-07 8:12
Mark Salsbery6-Nov-07 8:12 
GeneralRe: MSCORLIB.DLL Pin
shpid3r6-Nov-07 8:31
shpid3r6-Nov-07 8:31 
GeneralRe: MSCORLIB.DLL Pin
Mark Salsbery6-Nov-07 8:40
Mark Salsbery6-Nov-07 8:40 
GeneralRe: MSCORLIB.DLL Pin
shpid3r6-Nov-07 8:55
shpid3r6-Nov-07 8:55 
GeneralRe: MSCORLIB.DLL Pin
Mark Salsbery6-Nov-07 9:05
Mark Salsbery6-Nov-07 9:05 
QuestionRe: MSCORLIB.DLL Pin
shpid3r6-Nov-07 9:12
shpid3r6-Nov-07 9:12 
AnswerRe: MSCORLIB.DLL Pin
Mark Salsbery6-Nov-07 9:18
Mark Salsbery6-Nov-07 9:18 
GeneralRe: MSCORLIB.DLL Pin
shpid3r6-Nov-07 9:30
shpid3r6-Nov-07 9:30 
GeneralRe: MSCORLIB.DLL Pin
David Crow6-Nov-07 10:49
David Crow6-Nov-07 10:49 
QuestionRe: MSCORLIB.DLL Pin
Maximilien6-Nov-07 9:05
Maximilien6-Nov-07 9:05 
AnswerRe: MSCORLIB.DLL Pin
shpid3r6-Nov-07 9:09
shpid3r6-Nov-07 9:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.