|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Dec 2006
Messaggi: 314
|
[c++] errore pezzo di codice
sto realizzando un programma che cambia lo sfondo del desktop. Questo è il codice:
Codice:
#include <Windows.h>
#include <WinInet.h>
#include <ShlObj.h>
//Main window procedure WinMain
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iShowCmd)
{
CoInitialize (NULL) ;
HRESULT hr;
IActiveDesktop *pActiveDesktop;
//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
LPCWSTR wcPath = L"Insert File Path Here" ;
if (pActiveDesktop -> SetWallpaper (wcPath, 0) != S_OK)
{
//The method has failed...
}
// Call the Release method
pActiveDesktop -> ApplyChanges (AD_APPLY_ALL) ;
pActiveDesktop->Release();
CoUninitialize () ;
return 0 ;
}
ma nella riga in bold mi da questo errore Codice:
11 C:\Documents and Settings\xxxx\Desktop\progetto\main.cpp `IActiveDesktop' undeclared (first use this function) |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Nov 2005
Città: TO
Messaggi: 5206
|
Il tuo codice così come è compila senza problemi sul VC++.net 2003.
__________________
Andrea, SCJP 5 (91%) - SCWCD 5 (94%) |
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Mar 2007
Messaggi: 1792
|
Probabilmente stai usando MinGW (GCC), in tal caso l'interfaccia IActiveDesktop non risulta dichiarata negli header del compilatore.
Per cambiare lo sfondo del desktop ti conviene richiamare la funzione SystemParametersInfo con il parametro SPI_SETDESKWALLPAPER. |
|
|
|
|
|
#4 | |
|
Senior Member
Iscritto dal: Dec 2006
Messaggi: 314
|
Quote:
per andbin.. allora cambio compilatore ps:non capisco il francese Ultima modifica di Rsk : 27-08-2007 alle 11:39. |
|
|
|
|
|
|
#5 | |
|
Senior Member
Iscritto dal: Nov 2005
Città: TO
Messaggi: 5206
|
Quote:
Sì, forse è meglio: VC++ 2005 Express ad esempio.
__________________
Andrea, SCJP 5 (91%) - SCWCD 5 (94%) |
|
|
|
|
|
|
#6 | |
|
Senior Member
Iscritto dal: Dec 2006
Messaggi: 314
|
Quote:
|
|
|
|
|
|
|
#7 |
|
Senior Member
Iscritto dal: Mar 2007
Messaggi: 1792
|
Basta includere windows.h e linkare libuser32.
|
|
|
|
|
|
#8 |
|
Senior Member
Iscritto dal: Nov 2005
Città: TO
Messaggi: 5206
|
#include <Windows.h>
__________________
Andrea, SCJP 5 (91%) - SCWCD 5 (94%) |
|
|
|
|
|
#9 |
|
Senior Member
Iscritto dal: Dec 2006
Messaggi: 314
|
lho inclusa come potete vedere dal codice. Ma dev c++ da errore per quanto riguarda IActivedesktop come da codice postato
|
|
|
|
|
|
#10 | |
|
Senior Member
Iscritto dal: Mar 2007
Messaggi: 1792
|
Quote:
I suggerimenti si riferivano a SystemParametersInfo. |
|
|
|
|
|
|
#11 |
|
Senior Member
Iscritto dal: Dec 2006
Messaggi: 314
|
|
|
|
|
|
|
#12 | |
|
Senior Member
Iscritto dal: Nov 2005
Città: TO
Messaggi: 5206
|
Quote:
__________________
Andrea, SCJP 5 (91%) - SCWCD 5 (94%) |
|
|
|
|
|
|
#13 | |
|
Senior Member
Iscritto dal: Mar 2007
Messaggi: 1792
|
Quote:
utilizzare Visual C++ Express Edition con Microsoft Platform SDK. |
|
|
|
|
|
|
#14 |
|
Senior Member
Iscritto dal: Dec 2006
Messaggi: 314
|
ok grazie ho risolto.
ma come la richiamo la funzione Codice:
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iShowCmd) |
|
|
|
|
|
#15 |
|
Senior Member
Iscritto dal: Mar 2007
Messaggi: 1792
|
Non capisco il senso della tua domanda... La funzione WinMain "è" il main!
Compila il programma e lancia l'eseguibile. |
|
|
|
|
|
#16 | |
|
Senior Member
Iscritto dal: Dec 2006
Messaggi: 314
|
Quote:
ma quando tento di avviare il debug ricevo questo errore Codice:
Collegamento in corso... MSVCRTD.lib(crtexe.obj) : error LNK2019: riferimento al simbolo esterno _main non risolto nella funzione ___tmainCRTStartup C:\Documents and Settings\rsk\Desktop\cambiosfondo\prova\Debug\prova.exe : fatal error LNK1120: 1 esterni non risolti |
|
|
|
|
|
|
#17 |
|
Senior Member
Iscritto dal: Mar 2007
Messaggi: 1792
|
Quale modello di progetto hai scelto nella creazione del programma? Applicazione CONSOLE?
|
|
|
|
|
|
#18 | |
|
Senior Member
Iscritto dal: Dec 2006
Messaggi: 314
|
Quote:
Codice:
Compilazione in corso...
stdafx.cpp
Compilazione in corso...
desk.cpp
c:\documents and settings\rsk\desktop\desk2\desk\desk\desk.cpp(201) : error C3861: 'CoInitialize': identificatore non trovato
c:\documents and settings\rsk\desktop\desk2\desk\desk\desk.cpp(204) : error C2065: 'IActiveDesktop': identificatore non dichiarato
c:\documents and settings\rsk\desktop\desk2\desk\desk\desk.cpp(204) : error C2065: 'pActiveDesktop': identificatore non dichiarato
c:\documents and settings\rsk\desktop\desk2\desk\desk\desk.cpp(207) : error C2065: 'CLSID_ActiveDesktop': identificatore non dichiarato
c:\documents and settings\rsk\desktop\desk2\desk\desk\desk.cpp(207) : error C2065: 'CLSCTX_INPROC_SERVER': identificatore non dichiarato
c:\documents and settings\rsk\desktop\desk2\desk\desk\desk.cpp(208) : error C2065: 'IID_IActiveDesktop': identificatore non dichiarato
c:\documents and settings\rsk\desktop\desk2\desk\desk\desk.cpp(207) : error C3861: 'CoCreateInstance': identificatore non trovato
c:\documents and settings\rsk\desktop\desk2\desk\desk\desk.cpp(212) : error C2227: l'elemento a sinistra di '->SetWallpaper' deve puntare a un tipo classe, struttura, unione o generico
il tipo è ''unknown-type''
c:\documents and settings\rsk\desktop\desk2\desk\desk\desk.cpp(218) : error C2227: l'elemento a sinistra di '->ApplyChanges' deve puntare a un tipo classe, struttura, unione o generico
il tipo è ''unknown-type''
c:\documents and settings\rsk\desktop\desk2\desk\desk\desk.cpp(218) : error C2065: 'AD_APPLY_ALL': identificatore non dichiarato
c:\documents and settings\rsk\desktop\desk2\desk\desk\desk.cpp(219) : error C2227: l'elemento a sinistra di '->Release' deve puntare a un tipo classe, struttura, unione o generico
il tipo è ''unknown-type''
c:\documents and settings\rsk\desktop\desk2\desk\desk\desk.cpp(221) : error C3861: 'CoUninitialize': identificatore non trovato
Il log di generazione è stato salvato in 'file://c:\Documents and Settings\rsk\Desktop\desk2\desk\desk\Debug\BuildLog.htm'
desk - 12 errore/i, 0 avviso/i
Ultima modifica di Rsk : 27-08-2007 alle 18:06. |
|
|
|
|
|
|
#19 |
|
Senior Member
Iscritto dal: Dec 2006
Messaggi: 314
|
potete provare se riuscite a farlo funzionare?
Codice:
#include <Windows.h>
#include <WinInet.h>
#include <ShlObj.h>
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iShowCmd)
{
CoInitialize (NULL) ;
HRESULT hr;
IActiveDesktop *pActiveDesktop;
//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
LPCWSTR wcPath = L"%SYSTEMROOT%\\Web\\Wallpaper\\Amico.jpg" ;
if (pActiveDesktop -> SetWallpaper (wcPath, 0) != S_OK)
{
//The method has failed...
}
// Call the Release method
pActiveDesktop -> ApplyChanges (AD_APPLY_ALL) ;
pActiveDesktop->Release();
CoUninitialize () ;
return 0 ;
}
|
|
|
|
|
|
#20 |
|
Senior Member
Iscritto dal: Mar 2007
Messaggi: 1792
|
Ho compilato il sorgente da linea di comando (cl /EHsc test.cpp ole32.lib) senza riscontrare problemi. Non avendo Visual C++ Express 2005 non so quali tipologie di progetto sono disponibili.
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 23:57.




















