+ Reply to Thread
Results 1 to 2 of 2

Thread: Trying to write first app to interface with Group Policy

  1. #1
    kristacrawley is offline Getting Started on GPanswers.com
    Join Date
    Dec 1969
    Posts
    2

    Default

    Hi all:

    I'm trying to write my first "hello world" app to see what I can do with various Group Policy COM interfaces. I see that there is a set of COM interfaces for Group Policy as well as GPMC so I'm starting with the Group Policy IGroupPolicyObject interface with the following very simple code:

    #include <gpmgmt.h>
    #include <gpedit.h>

    #pragma comment(lib, "gpedit.lib")

    IGroupPolicyObject* pIGroupPolicyObject;

    int _tmain(int argc, _TCHAR* argv[])
    {
    HRESULT hr;

    CoInitialize(NULL);

    IGroupPolicyObject* p = NULL;
    hr = CoCreateInstance(CLSID_GroupPolicyObject, NULL, CLSCTX_ALL, IID_IGroupPolicyObject, (LPVOID*)&p);
    if (SUCCEEDED(hr))
    {
    DWORD dwSection = GPO_SECTION_USER;
    HKEY key = NULL;
    p->GetRegistryKey(dwSection, &key);
    p->Release();
    }

    CoUninitialize();

    return 0;
    }

    Unfortunately, I'm getting a linker error on the ID:

    error LNK2001: unresolved external symbol _CLSID_GroupPolicyObject

    The libs are in place, the folder settings point to them, so I'm not sure what is going wrong here.

    Does anyone have any experience or knowledge about how to use the GP COM interfaces?

    Thanks in advance!
    Krista

  2. #2
    kristacrawley is offline Getting Started on GPanswers.com
    Join Date
    Dec 1969
    Posts
    2

    Default

    As usual, you spend 2 days looking for something, finally reach out for help, and solve it 5 minutes later

    The answer is that the gpedit.h file just declares an external reference to the symbol name without initializing it. Hence the linker error. (I was wondering how I could get a linker error on an id!)

    Anyway, the solution to situations where the COM CLSID or IID is declared, but not initialized, is to include "InitGuid.h"

    Krista

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO