Creating a simple COM example - undeclared identifier

Started by Vortex, May 05, 2013, 11:32:01 AM

Previous topic - Next topic

Vortex

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?
Code it... That's all...

Vortex

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.
Code it... That's all...

TimoVJL

May the source be with you

Vortex

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'.

Code it... That's all...

TimoVJL

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")
May the source be with you

Vortex

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.
Code it... That's all...