Pelles C forum

C language => Beginner questions => Topic started by: Vortex on May 05, 2013, 11:32:01 AM

Title: Creating a simple COM example - undeclared identifier
Post by: Vortex on May 05, 2013, 11:32:01 AM
Hello,

I am trying to convert my Poasm code to Pelles C :

Code: [Select]
#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 :

Code: [Select]
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?
Title: Re: Creating a simple COM example - undeclared identifier
Post by: Vortex on May 05, 2013, 12:08:04 PM
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.
Title: Re: Creating a simple COM example - undeclared identifier
Post by: TimoVJL on May 05, 2013, 12:43:26 PM
Correct this line too:
Code: [Select]
pAD->lpVtbl->Release(pAD);
Title: Re: Creating a simple COM example - undeclared identifier
Post by: Vortex on May 05, 2013, 12:49:37 PM
Hi Timo,

Thanks. This time, I have other problems :

Code: [Select]
#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;
}

Code: [Select]
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'.
Title: Re: Creating a simple COM example - undeclared identifier
Post by: TimoVJL on May 05, 2013, 12:53:10 PM
Don't forget object pointer:
Code: [Select]
pAD->lpVtbl->SetWallpaper(pAD,file1,0);and these pragmas are useful
Code: [Select]
#pragma comment(lib, "ole32.lib")
#pragma comment(lib, "uuid.lib")
Title: Re: Creating a simple COM example - undeclared identifier
Post by: Vortex on May 05, 2013, 06:34:52 PM
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.