SetClipboardData() not working

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
You need to link with user32.lib
how do i do that? sorry im fairly new to c++
Last edited on
You need to set it up in the link section of your environment. How are you compiling your code?
im using vc 2010 express
Last edited on
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.
sorry im fairly new to c++


You don't seem to know that your posted code is NOT written in C++ language.
thanks a lot kbw it works now and is modoran correct about this not being c++?
Last edited on
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++.
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.