NO

Author Topic: Creating a simple COM example - undeclared identifier  (Read 4783 times)

Offline Vortex

  • Member
  • *
  • Posts: 867
    • http://www.vortex.masmcode.com
Creating a simple COM example - undeclared identifier
« 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?
Code it... That's all...

Offline Vortex

  • Member
  • *
  • Posts: 867
    • http://www.vortex.masmcode.com
Re: Creating a simple COM example - undeclared identifier
« Reply #1 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.
Code it... That's all...

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Creating a simple COM example - undeclared identifier
« Reply #2 on: May 05, 2013, 12:43:26 PM »
Correct this line too:
Code: [Select]
pAD->lpVtbl->Release(pAD);
May the source be with you

Offline Vortex

  • Member
  • *
  • Posts: 867
    • http://www.vortex.masmcode.com
Re: Creating a simple COM example - undeclared identifier
« Reply #3 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'.
Code it... That's all...

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Creating a simple COM example - undeclared identifier
« Reply #4 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")
« Last Edit: May 05, 2013, 12:58:59 PM by timovjl »
May the source be with you

Offline Vortex

  • Member
  • *
  • Posts: 867
    • http://www.vortex.masmcode.com
Re: Creating a simple COM example - undeclared identifier
« Reply #5 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.
Code it... That's all...