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 COM

COM_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 diretorio

WinExec("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 randomicamente

h = 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 Desktop

hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,

IID_IActiveDesktop, (void**)&pActiveDesktop);

//Insert code to call the IActiveDesktop methods

pActiveDesktop->SetWallpaper(_bstr_t(str), 0);

pActiveDesktop->ApplyChanges(AD_APPLY_ALL);

// Call the Release method

pActiveDesktop->Release();

return 0;

}

and this one is from the window form project (form1.h):

#pragmaonce

#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 randomicamente

str = dirPath->Text + file[r_num];

//Create an instance of the Active Desktop

hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,

IID_IActiveDesktop, (void**)&pActiveDesktop);

lpStr = StrToLPCWSTR(str);

//Insert code to call the IActiveDesktop methods

pActiveDesktop->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>

#pragmaregion 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();

}

#pragmaendregion

private: 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

[35598 byte] By [Monstro] at [2007-12-22]
# 1

I suggest you isolate COM based routines in unmanaged, by using #pragma managed (push, off) and #pragma managed (pop) as described here

http://msdn2.microsoft.com/en-us/library/0adb9zxe.aspx

and also add the necessary libraries to link to.

Ted. at 2007-8-30 > top of Msdn Tech,Visual C++,Visual C++ General...
# 2
Okay, i've managed to isolate the COM based routines just fine. But i can't find where i'm supposed to add the necessary libraries to link. I already went to the project configuration properties, in the linker tab, but i didn't find a place to include new libraries, and i don't really now what libraries i'm supposed to include.
The error that the compiler gives now is the following:

Error 3 error LNK2020: unresolved token (0A00000C) CLSID_ActiveDesktop teste.obj
Error 4 error LNK2020: unresolved token (0A00000D) IID_IActiveDesktop teste.obj
Error 5 error LNK2028: unresolved token (0A00000E) "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 "int __clrcall wallchanger(void)" (?wallchanger@@$$FYMHXZ) teste.obj
Error 6 error LNK2028: unresolved token (0A000012) "extern "C" short __stdcall GetAsyncKeyState(int)" (?GetAsyncKeyState@@$$J14YGFH@Z) referenced in function "int __clrcall mainFunction(char *,char * *,int,bool)" (?mainFunction@@$$FYMHPADPAPADH_N@Z) teste.obj
Error 7 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 "int __clrcall wallchanger(void)" (?wallchanger@@$$FYMHXZ) teste.obj
Error 8 error LNK2001: unresolved external symbol IID_IActiveDesktop teste.obj
Error 9 error LNK2001: unresolved external symbol CLSID_ActiveDesktop teste.obj
Error 10 error LNK2019: unresolved external symbol "extern "C" short __stdcall GetAsyncKeyState(int)" (?GetAsyncKeyState@@$$J14YGFH@Z) referenced in function "int __clrcall mainFunction(char *,char * *,int,bool)" (?mainFunction@@$$FYMHPADPAPADH_N@Z) teste.obj
Error 11 fatal error LNK1120: 8 unresolved externals E:\Documents and Settings\Rep\Meus documentos\Visual Studio 2005\Projects\wallpaperchanger_v2\Debug\wallpaperchanger_v2.exe 1

thx.
Monstro at 2007-8-30 > top of Msdn Tech,Visual C++,Visual C++ General...
# 3

You need to link to shell32.lib ole32.lib user32.lib and possibly others

you need to add these libraries under: project - configuration properties - Linker - Input - Additional Dependencies

you still appear to be compiling part of the code managed (errors 3 to 6). It should be all unmanaged.

Ted. at 2007-8-30 > top of Msdn Tech,Visual C++,Visual C++ General...
# 4
thx, i added the libraries to the project, but i'm still getting two errors about unresolved token and unresolved external symbol. I'm including the codes below so you can see what i've done.

this is the teste.cpp file:

#pragma unmanaged
#include "stdafx.h"
//#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>
#include "teste.h"

/*struct COM_INIT{//To manage COM
COM_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;
char **strArray;
char dir[100];

int mainFunction(char *str1, char**strArray1, int numFiles1, bool edit)
{
srand(time(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;
LPWSTR dirUni;

r_num = rand()%nfiles;
strcpy_s(dir,100,str);
strcat_s(dir, 100, strArray[r_num]);

//Create an instance of the Active Desktop
hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
IID_IActiveDesktop, (void**)&pActiveDesktop);

//Insert code to call the IActiveDesktop methods
MultiByteToWideChar( CP_ACP, 0, dir, strlen(dir)+1, dirUni, sizeof(LPWSTR)*100);
pActiveDesktop->SetWallpaper(dirUni, 0);
pActiveDesktop->ApplyChanges(AD_APPLY_ALL);

// Call the Release method
pActiveDesktop->Release();

return 0;
}
#pragma managed


this is the form1.h file:
#pragma once
#include "teste.h"
#include <iostream>
#include <stdlib.h>
#include <string>

#include "vcclr.h"
/* LPCWSTR StrToLPCWSTR(String^ sString)
{
LPCWSTR lpsConverted;
lpsConverted = static_cast<LPCTSTR>(const_cast<void*>(static_cast<const void*>(System::Runtime::InteropServices::Marshal::StringToHGlobalUni(sString))));
return lpsConverted;
}*/
namespace wallpaperchanger_v2 {

using namespace System;
using namespace System::IO;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace 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>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
char *aux;
char **auxArray;
InitializeComponent();
//
//TODO: Add the constructor code here
//
file = Directory::GetFiles(str);
StrToChar(dirPath->Text, &aux);
StrArrayToCharArray(file, &auxArray);
mainFunction(aux, auxArray, file->Length, dirPath->Enabled);
}

void *StrToChar(String^ orig, char **aux)
{
pin_ptr<const wchar_t> wch = PtrToStringChars(orig);

// Convert to a char*
size_t origsize = wcslen(wch) + 1;
const size_t newsize = 100;
size_t convertedChars = 0;
//char nstring[newsize];
(*aux) = (char *)malloc(sizeof(char)*100);
wcstombs_s(&convertedChars, (*aux), origsize, wch, _TRUNCATE);
return 0;
}

void StrArrayToCharArray(array<String^>^ vet, char ***aux)
{
int i;

(*aux) = (char **)malloc(sizeof(char *)*vet->Length);
for(i = 0; i < vet->Length; i++)
{
StrToChar(vetIdea, &(*aux)Idea);
}
}

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: 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(204, 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(16, 49);
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 endregion
private: 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) {
button1->Enabled = true;
dirPath->Enabled = true;
}
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
button1->Enabled = false;
dirPath->Enabled = false;
}
};
}


When i compile i get the following errors:

Error 3 error LNK2020: unresolved token (0A00000C) CLSID_ActiveDesktop teste.obj
Error 4 error LNK2020: unresolved token (0A00000D) IID_IActiveDesktop teste.obj
Error 5 error LNK2001: unresolved external symbol IID_IActiveDesktop teste.obj
Error 6 error LNK2001: unresolved external symbol CLSID_ActiveDesktop teste.obj
Error 7 fatal error LNK1120: 4 unresolved externals E:\Documents and Settings\Rep\Meus documentos\Visual Studio 2005\Projects\wallpaperchanger_v2\Debug\wallpaperchanger_v2.exe 1

I don't know why they're ocurring. I thought these were because of not including the necessary libraries or .dll files. does anybody knows what's wrong in my code know?
thx

Monstro at 2007-8-30 > top of Msdn Tech,Visual C++,Visual C++ General...
# 5
Make sure you disable pre-compiled headers for your unmanaged source files in project settings (it may be ignoring that #pragma directive) - try adding some more #pragma unmanaged throughout the file until you get it working.
Ted. at 2007-8-30 > top of Msdn Tech,Visual C++,Visual C++ General...
# 6
i did a little cheating and added the following lines to the code (teste.cpp) and it worked:

extern const IID IID_IActiveDesktop = {
0xf490eb00,0x1240,0x11d1, {
0x98,0x88,0x00,0x60,0x97,0xde,0xac,0xf9 }
};

extern const IID CLSID_ActiveDesktop = {
0x75048700,0xef1f,0x11d0, {
0x98,0x88,0x00,0x60,0x97,0xDE,0xac,0xf9}
};


Thx for all the helps people. \o/
Monstro at 2007-8-30 > top of Msdn Tech,Visual C++,Visual C++ General...