windows forms X win32 console application
Hi there, i'm a little new to VC++ and i'm having some problems... I have a program i made to change my desktop through a combination of keys. I used the win32 console application project in the visual studio 2005. Now i'm trying to make a GUI for the program through the windows forms appplication project from VS2005, but i'm getting some strange errors.
The codes from the 2 versions are below:
This one is from the win32 application:
#include
<comdef.h>#include
<stdlib.h>#include
<stdio.h>#include
<time.h>#include
<string.h>#include
<windows.h>#include
<wininet.h>#include
<shlobj.h>#include
<winuser.h>struct
COM_INIT{//To manage COMCOM_INIT(){CoInitialize(0);}
~COM_INIT(){CoUninitialize();}
}COM_INIT_;
HRESULT hr;
IActiveDesktop *pActiveDesktop;
//variavel que representa o desktop atual.WALLPAPEROPT wpo;
FILE *pf;
int
nfiles;HANDLE h;
WIN32_FIND_DATA info;
int
i;char
str[50];char
blah[30];int
mainFunction(bool *editting){
srand(time(NULL));
//pra saber o numero de arquivos no diretorioWinExec(
"e:\\wallpapers\\wallpaperchanger\\numfiles.bat", 0);fopen_s(&pf,
"e:\\wallpapers\\wallpaperchanger\\qntoffiles.txt","r");if(pf != NULL){
fscanf_s(pf,
"%d", &nfiles);fclose(pf);
wallchanger();
while(1){
Sleep(10);
if(GetAsyncKeyState(0x11) < 0 && GetAsyncKeyState(0x10) < 0 && GetAsyncKeyState(0x44) < 0){
wallchanger();
}
else{
if(GetAsyncKeyState(0x11) < 0 && GetAsyncKeyState(0x10) < 0 && GetAsyncKeyState(0x51) < 0){
break;}
}
}
}
return 0;}
int
wallchanger(){
int r_num;r_num = rand()%nfiles;
//pegando o nome de um arquivo randomicamenteh = FindFirstFile(_bstr_t(
"e:\\wallpapers\\*.*"), &info);if (h != INVALID_HANDLE_VALUE){
for(i = 0; i < (r_num + 2); i++)FindNextFile(h, &info);
FindClose(h);
}
WideCharToMultiByte( CP_ACP, 0, info.cFileName, -1, blah, 30, NULL, NULL );
strcpy_s(str,50,
"e:\\wallpapers\\");strcat_s(str, 50, blah);
//Create an instance of the Active Desktophr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
IID_IActiveDesktop, (
void**)&pActiveDesktop);//Insert code to call the IActiveDesktop methodspActiveDesktop->SetWallpaper(_bstr_t(str), 0);
pActiveDesktop->ApplyChanges(AD_APPLY_ALL);
// Call the Release methodpActiveDesktop->Release();
return 0;}
and this one is from the window form project (form1.h):
#pragma
once#include
<stdlib.h>#include
<stdio.h>#include
<time.h>#include
<string.h>#include
<windows.h>#include
<wininet.h>#include
<shlobj.h>#include
<winuser.h>namespace
wallpaperchanger_v2 {usingnamespace System;usingnamespace System::IO;usingnamespace System::ComponentModel;usingnamespace System::Collections;usingnamespace System::Windows::Forms;usingnamespace System::Data;usingnamespace System::Drawing;///<summary>/// Summary for Form1////// WARNING: If you change the name of this class, you will need to change the/// 'Resource File Name' property for the managed resource compiler tool/// associated with all .resx files this class depends on. Otherwise,/// the designers will not be able to interact properly with localized/// resources associated with this form.///</summary>publicrefclass Form1 :public System::Windows::Forms::Form{
public:Form1(
void){
InitializeComponent();
////TODO: Add the constructor code here//mainFunction();
}
public :int mainFunction(){
file = Directory::GetFiles(dirPath->Text);
wallchanger();
while(1){
Sleep(10);
if(GetAsyncKeyState(0x11) < 0 && GetAsyncKeyState(0x10) < 0 && GetAsyncKeyState(0x44) < 0){
wallchanger();
}
else{
if(GetAsyncKeyState(0x11) < 0 && GetAsyncKeyState(0x10) < 0 && GetAsyncKeyState(0x51) < 0){
break;}
}
}
return 0;}
public :int wallchanger(){
int r_num;IActiveDesktop* pActiveDesktop;
r_num = rand()%file->Length;
//pegando o nome de um arquivo randomicamentestr = dirPath->Text + file[r_num];
//Create an instance of the Active Desktophr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
IID_IActiveDesktop, (
void**)&pActiveDesktop);lpStr = StrToLPCWSTR(str);
//Insert code to call the IActiveDesktop methodspActiveDesktop->SetWallpaper(lpStr, 0);
pActiveDesktop->ApplyChanges(AD_APPLY_ALL);
// Call the Release method//pActiveDesktop.Release();//IActiveDesktop::SetWallpaper(lpStr, 0);//IActiveDesktop::ApplyChanges(AD_APPLY_ALL);return 0;}
public:LPCWSTR StrToLPCWSTR(String^ sString)
{
LPCWSTR lpsConverted;
lpsConverted =
static_cast<LPCTSTR>(const_cast<void*>(static_cast<constvoid*>(System::Runtime::InteropServices::Marshal::StringToHGlobalUni(sString))));return lpsConverted;}
protected:///<summary>/// Clean up any resources being used.///</summary>~Form1()
{
if (components){
delete components;}
}
private: System::Windows::Forms::Label^ label1;private: System::Windows::Forms::TextBox^ dirPath;private: System::Windows::Forms::FolderBrowserDialog^ folderBrowserDialog1;private: System::Windows::Forms::Button^ button1;private: System::Windows::Forms::Button^ button2;private: System::Windows::Forms::Button^ button3;//private: int editting;private: HRESULT hr;private: FILE *pf;private:int nfiles;private: HANDLE h;private:int i;private: String^ str;private:array<String^>^ file;private: LPCWSTR lpStr;private: System::Windows::Forms::Timer^ timer1;private: System::Windows::Forms::NotifyIcon^ notifyIcon1;private: System::Windows::Forms::Button^ button4;private: System::Windows::Forms::CheckBox^ checkBox1;private: System::ComponentModel::IContainer^ components;protected:private:///<summary>/// Required designer variable.///</summary>#pragma
region Windows Form Designer generated code///<summary>/// Required method for Designer support - do not modify/// the contents of this method with the code editor.///</summary>void InitializeComponent(void){
this->components = (gcnew System::ComponentModel::Container());this->label1 = (gcnew System::Windows::Forms::Label());this->dirPath = (gcnew System::Windows::Forms::TextBox());this->folderBrowserDialog1 = (gcnew System::Windows::Forms::FolderBrowserDialog());this->button1 = (gcnew System::Windows::Forms::Button());this->button2 = (gcnew System::Windows::Forms::Button());this->button3 = (gcnew System::Windows::Forms::Button());this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));this->notifyIcon1 = (gcnew System::Windows::Forms::NotifyIcon(this->components));this->button4 = (gcnew System::Windows::Forms::Button());this->checkBox1 = (gcnew System::Windows::Forms::CheckBox());this->SuspendLayout();//// label1//this->label1->AutoSize =true;this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,static_cast<System::Byte>(0)));this->label1->Location = System::Drawing::Point(12, 9);this->label1->Name = L"label1";this->label1->Size = System::Drawing::Size(186, 20);this->label1->TabIndex = 0;this->label1->Text = L"Diretório dos Wallpapers:";//// dirPath//this->dirPath->Enabled =false;this->dirPath->Location = System::Drawing::Point(204, 12);this->dirPath->Name = L"dirPath";this->dirPath->Size = System::Drawing::Size(223, 20);this->dirPath->TabIndex = 1;//// button1//this->button1->Enabled =false;this->button1->Location = System::Drawing::Point(433, 10);this->button1->Name = L"button1";this->button1->Size = System::Drawing::Size(75, 23);this->button1->TabIndex = 2;this->button1->Text = L"procurar";this->button1->UseVisualStyleBackColor =true;this->button1->Click +=gcnew System::EventHandler(this, &Form1::button1_Click);//// button2//this->button2->Location = System::Drawing::Point(68, 114);this->button2->Name = L"button2";this->button2->Size = System::Drawing::Size(75, 23);this->button2->TabIndex = 3;this->button2->Text = L"Edit";this->button2->UseVisualStyleBackColor =true;this->button2->Click +=gcnew System::EventHandler(this, &Form1::button2_Click);//// button3//this->button3->Location = System::Drawing::Point(328, 113);this->button3->Name = L"button3";this->button3->Size = System::Drawing::Size(75, 23);this->button3->TabIndex = 4;this->button3->Text = L"Accept";this->button3->UseVisualStyleBackColor =true;this->button3->Click +=gcnew System::EventHandler(this, &Form1::button3_Click);//// notifyIcon1//this->notifyIcon1->Text = L"Wallpaper changer v2.0";this->notifyIcon1->Visible =true;//// button4//this->button4->Location = System::Drawing::Point(244, 201);this->button4->Name = L"button4";this->button4->Size = System::Drawing::Size(75, 23);this->button4->TabIndex = 5;this->button4->Text = L"Change";this->button4->UseVisualStyleBackColor =true;//// checkBox1//this->checkBox1->AutoSize =true;this->checkBox1->Location = System::Drawing::Point(162, 281);this->checkBox1->Name = L"checkBox1";this->checkBox1->Size = System::Drawing::Size(158, 17);this->checkBox1->TabIndex = 6;this->checkBox1->Text = L"Trocar de 30 em 30 minutos";this->checkBox1->UseVisualStyleBackColor =true;//// Form1//this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;this->ClientSize = System::Drawing::Size(520, 440);this->Controls->Add(this->checkBox1);this->Controls->Add(this->button4);this->Controls->Add(this->button3);this->Controls->Add(this->button2);this->Controls->Add(this->button1);this->Controls->Add(this->dirPath);this->Controls->Add(this->label1);this->Name = L"Form1";this->Text = L"Form1";this->ResumeLayout(false);this->PerformLayout();}
#pragma
endregionprivate: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {folderBrowserDialog1->ShowDialog();
dirPath->Text = folderBrowserDialog1->SelectedPath;
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {//editting = 1;button1->Enabled =
true;dirPath->Enabled =
true;}
private
: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {//editting = 0;button1->Enabled =
false;dirPath->Enabled =
false;}
};
}
When I try to compile the second one i get the following errors
Error 1 error LNK2020: unresolved token (0A000038) CLSID_ActiveDesktop wallpaperchanger_v2.obj
Error 2 error LNK2020: unresolved token (0A000039) IID_IActiveDesktop wallpaperchanger_v2.obj
Error 3 error LNK2028: unresolved token (0A00003A) "extern "C" long __stdcall CoCreateInstance(struct _GUID const &,struct IUnknown *,unsigned long,struct _GUID const &,void * *)" (?CoCreateInstance@@$$J220YGJABU_GUID@@PAUIUnknown@@K0PAPAX@Z) referenced in function "public: int __clrcall wallpaperchanger_v2::Form1::wallchanger(void)" (?wallchanger@Form1@wallpaperchanger_v2@@$$FQ$AAMHXZ) wallpaperchanger_v2.obj
Error 4 error LNK2028: unresolved token (0A00003D) "extern "C" short __stdcall GetAsyncKeyState(int)" (?GetAsyncKeyState@@$$J14YGFH@Z) referenced in function "public: int __clrcall wallpaperchanger_v2::Form1::mainFunction(void)" (?mainFunction@Form1@wallpaperchanger_v2@@$$FQ$AAMHXZ) wallpaperchanger_v2.obj
Error 5 error LNK2019: unresolved external symbol "extern "C" long __stdcall CoCreateInstance(struct _GUID const &,struct IUnknown *,unsigned long,struct _GUID const &,void * *)" (?CoCreateInstance@@$$J220YGJABU_GUID@@PAUIUnknown@@K0PAPAX@Z) referenced in function "public: int __clrcall wallpaperchanger_v2::Form1::wallchanger(void)" (?wallchanger@Form1@wallpaperchanger_v2@@$$FQ$AAMHXZ) wallpaperchanger_v2.obj
Error 6 error LNK2001: unresolved external symbol IID_IActiveDesktop wallpaperchanger_v2.obj
Error 7 error LNK2001: unresolved external symbol CLSID_ActiveDesktop wallpaperchanger_v2.obj
Error 8 error LNK2019: unresolved external symbol "extern "C" short __stdcall GetAsyncKeyState(int)" (?GetAsyncKeyState@@$$J14YGFH@Z) referenced in function "public: int __clrcall wallpaperchanger_v2::Form1::mainFunction(void)" (?mainFunction@Form1@wallpaperchanger_v2@@$$FQ$AAMHXZ) wallpaperchanger_v2.obj
Error 9 fatal error LNK1120: 8 unresolved externals E:\Documents and Settings\Rep\Meus documentos\Visual Studio 2005\Projects\wallpaperchanger_v2\Debug\wallpaperchanger_v2.exe 1
I have no idea why this is happening... can somebody help me?
thx

