Hello,
I am trying to convert my Poasm code to Pelles C :
#include <windows.h>
#include <shlobj.h>
#include <shlguid.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
HRESULT hr;
IActiveDesktop *pAD;
CoInitialize(0);
hr = CoCreateInstance(&CLSID_ActiveDesktop,
0,
CLSCTX_INPROC_SERVER,
&IID_IActiveDesktop,
(void**) &pAD);
pAD->Release();
CoUninitialize();
return 0;
}
The compiler reports the following error message :
SetWallpaper.c(10): error #2048: Undeclared identifier 'IActiveDesktop'.
SetWallpaper.c(10): error #2048: Undeclared identifier 'pAD'.
The IActiveDesktop interface is defined in shlobj.h How to solve the problem above?
I found this article :
PRB: ActiveDesktop Compilation Errors Under Visual C++ 6.0 MFC
http://support.microsoft.com/kb/196342/en-us
Adding #include <wininet.h> is solving the problem.
Correct this line too:
pAD->lpVtbl->Release(pAD);
Hi Timo,
Thanks. This time, I have other problems :
#include <windows.h>
#include <wininet.h>
#include <shlobj.h>
#include <shlguid.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
HRESULT hr;
IActiveDesktop *pAD;
WALLPAPEROPT wpo;
LPCWSTR file1 = L"Test.bmp";
CoInitialize(0);
hr = CoCreateInstance(&CLSID_ActiveDesktop,
0,
CLSCTX_INPROC_SERVER,
&IID_IActiveDesktop,
(void**)&pAD);
wpo.dwSize=sizeof(WALLPAPEROPT);
wpo.dwStyle=WPSTYLE_CENTER;
pAD->lpVtbl->SetWallpaper(file1,0);
pAD->lpVtbl->SetWallpaperOptions(&wpo,0);
pAD->lpVtbl->ApplyChanges(AD_APPLY_ALL);
pAD->lpVtbl->Release(pAD);
CoUninitialize();
return 0;
}
SetWallpaper.c(26): error #2140: Type error in argument 1 to 'function'; expected 'LPACTIVEDESKTOP' but found 'const wchar_t *'.
SetWallpaper.c(26): error #2070: Insufficient number of arguments to 'function'.
SetWallpaper.c(28): error #2140: Type error in argument 1 to 'function'; expected 'LPACTIVEDESKTOP' but found 'LPWALLPAPEROPT'.
SetWallpaper.c(28): error #2070: Insufficient number of arguments to 'function'.
SetWallpaper.c(30): error #2140: Type error in argument 1 to 'function'; expected 'LPACTIVEDESKTOP' but found 'int'.
SetWallpaper.c(30): error #2070: Insufficient number of arguments to 'function'.
Don't forget object pointer:
pAD->lpVtbl->SetWallpaper(pAD,file1,0);
and these pragmas are useful#pragma comment(lib, "ole32.lib")
#pragma comment(lib, "uuid.lib")
Hi Timo,
Adding the pointer solved the problem. As I was focused on the classical C++ syntax without the pointer, it was a bit confusing. Thanks for the info.