SetClipboardData() not working
Aug 21, 2012 at 6:21pm UTC
i have a problem
i tried using setclipboarddata() here is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include <string>
#include <iostream>
#include <Windows.h>
#using <System.DLL>
#using <System.Windows.Forms.DLL>
using namespace std;
using namespace System;
using namespace System::Windows::Forms;
int copystr(const char * clipoutput)
{
const size_t len = strlen(clipoutput) + 1;
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, len);
memcpy(GlobalLock(hMem), clipoutput, len);
GlobalUnlock(hMem);
OpenClipboard(0);
EmptyClipboard();
SetClipboardData(CF_TEXT, hMem);
MessageBox::Show("String has been copied to clipboard!" , "Copied" , MessageBoxButtons::OK, MessageBoxIcon::Information);
CloseClipboard();
return 0;
}
and then i called it here:
1 2 3 4 5 6 7 8 9 10 11 12 13
private : System::Void Decrypt(System::Object^ sender, System::EventArgs^ e) {
extern string ES;
ES.reserve(1000);
System::String^ ESd;
decrypt(ES, p, ESd);
System::Windows::Forms::DialogResult copy;
copy = MessageBox::Show(ESd + ". Copy? \n" , "Encrypted String" , MessageBoxButtons::YesNo, MessageBoxIcon::Information);
if (copy == System::Windows::Forms::DialogResult::Yes)
{
MessageBox::Show("String copied to clipboard!" , "Sorry" , MessageBoxButtons::OK, MessageBoxIcon::Information);
copystr(ES.c_str());
}
}
and i get the following errors:
1
1 2 3 4 5 6 7 8 9
>CrypterGUI.obj : error LNK2028: unresolved token (0A00006C) "extern " C" int __stdcall CloseClipboard(void)" (?CloseClipboard@@$$J10YGHXZ) referenced in function "extern " C" int __clrcall copystr(char const *)" (?copystr@@$$J0YMHPBD@Z)
1>CrypterGUI.obj : error LNK2028: unresolved token (0A00006E) "extern " C" void * __stdcall SetClipboardData(unsigned int,void *)" (?SetClipboardData@@$$J18YGPAXIPAX@Z) referenced in function "extern " C" int __clrcall copystr(char const *)" (?copystr@@$$J0YMHPBD@Z)
1>CrypterGUI.obj : error LNK2028: unresolved token (0A00006F) "extern " C" int __stdcall EmptyClipboard(void)" (?EmptyClipboard@@$$J10YGHXZ) referenced in function "extern " C" int __clrcall copystr(char const *)" (?copystr@@$$J0YMHPBD@Z)
1>CrypterGUI.obj : error LNK2028: unresolved token (0A000070) "extern " C" int __stdcall OpenClipboard(struct HWND__ *)" (?OpenClipboard@@$$J14YGHPAUHWND__@@@Z) referenced in function "extern " C" int __clrcall copystr(char const *)" (?copystr@@$$J0YMHPBD@Z)
1>CrypterGUI.obj : error LNK2019: unresolved external symbol "extern " C" int __stdcall CloseClipboard(void)" (?CloseClipboard@@$$J10YGHXZ) referenced in function "extern " C" int __clrcall copystr(char const *)" (?copystr@@$$J0YMHPBD@Z)
1>CrypterGUI.obj : error LNK2019: unresolved external symbol "extern " C" void * __stdcall SetClipboardData(unsigned int,void *)" (?SetClipboardData@@$$J18YGPAXIPAX@Z) referenced in function "extern " C" int __clrcall copystr(char const *)" (?copystr@@$$J0YMHPBD@Z)
1>CrypterGUI.obj : error LNK2019: unresolved external symbol "extern " C" int __stdcall EmptyClipboard(void)" (?EmptyClipboard@@$$J10YGHXZ) referenced in function "extern " C" int __clrcall copystr(char const *)" (?copystr@@$$J0YMHPBD@Z)
1>CrypterGUI.obj : error LNK2019: unresolved external symbol "extern " C" int __stdcall OpenClipboard(struct HWND__ *)" (?OpenClipboard@@$$J14YGHPAUHWND__@@@Z) referenced in function "extern " C" int __clrcall copystr(char const *)" (?copystr@@$$J0YMHPBD@Z)
1>C:\C++\Projects\Debug\CrypterGUI.exe : fatal error LNK1120: 8 unresolved externals
can someone please tell me what i did wrong?
thanks in advance!
Last edited on Aug 21, 2012 at 7:45pm UTC
Aug 21, 2012 at 11:04pm UTC
You need to link with user32.lib
Aug 22, 2012 at 5:49pm UTC
how do i do that? sorry im fairly new to c++
Last edited on Aug 22, 2012 at 5:49pm UTC
Aug 22, 2012 at 9:06pm UTC
You need to set it up in the link section of your environment. How are you compiling your code?
Aug 22, 2012 at 9:28pm UTC
im using vc 2010 express
Last edited on Aug 22, 2012 at 9:29pm UTC
Aug 23, 2012 at 10:46pm UTC
1. Select your project in Project Explorer.
2. Press the Properties button at the top of the control.
3. Select Configuration Properties->Linker->Input
4. Change Configuration to All Configurations
5. Add user32.lib to Additional Dependencies .
Aug 24, 2012 at 3:41am UTC
sorry im fairly new to c++
You don't seem to know that your posted code is NOT written in C++ language.
Aug 24, 2012 at 7:07pm UTC
thanks a lot kbw it works now and is modoran correct about this not being c++?
Last edited on Aug 24, 2012 at 7:14pm UTC
Aug 24, 2012 at 7:16pm UTC
actually no i know this is c++. first of all as far as i know, c does not use ::. and second of all, when i say fairly new, i dont mean im completely inept in c++.
Aug 24, 2012 at 8:44pm UTC
It's C++/CLI, which is C++ for the .Net environment. It's tweaked in places for that environment.
Topic archived. No new replies allowed.