Alright, I have a working version in C# .NET, but not all my clients will have the .NET runtime installed, so instead we've decided we need to port it to C++.

Objectives of the Application:
The application will have a list of URLs to add to IE's "Trusted" zone. After adding the zones it will display a message box with any successes/failures.

Current Code:
Code:
#include "windows.h"
#include "stdafx.h"
#include "urlmon.h"
#using <mscorlib.dll>
#include <atldef.h>
#include <atlconv.h>
using namespace System;
using namespace System::Runtime::InteropServices;
#define MAX_LOADSTRING 100

int _tmain(int argc, _TCHAR* argv[])
{
HRESULT hr;
	IInternetSecurityManager *pSecurityMgr;
	IInternetZoneManager *pZoneMgr;
	LPCWSTR site1 = SysAllocString(L"http://www.mydomain.com");


	hr = CoCreateInstance(CLSID_InternetSecurityManager, NULL, CLSCTX_INPROC_SERVER, IID_IInternetSecurityManager, (void**)&pSecurityMgr);
	pSecurityMgr->SetZoneMapping((DWORD)2, site1, (DWORD)0); // 2 = Trusted Site, site1 is the URL to add, and 0 is to create the entry.
}
That is just a snippet, but it gives you everything I'm trying to do.

The problem is that when I call CoCreateInstance(), I get a return value of -2147221008. When that happens pSecurityMgr is pointing to null and the SetZoneMapping() results in a null pointer exception.

My question is why is CoCreateInstance failing?

Any help would be appreciated, especially since I am following word for word what is happening here:
http://education.dewsoftoverseas.com...rview.htm]here

(Note: Scroll all the way to the bottom for their code example.)

Just incase you want to compile it, here is the WHOLE source code:

Code:
// test6.cpp : Defines the entry point for the console application.
//

#include "windows.h"
#include "stdafx.h"
#include "urlmon.h"
#using <mscorlib.dll>
#include <atldef.h>
#include <atlconv.h>
using namespace System;
using namespace System::Runtime::InteropServices;
#define MAX_LOADSTRING 100

int _tmain(int argc, _TCHAR* argv[])
{
	// constants from urlmon.h
	const int URLZONE_LOCAL_MACHINE = 0;
	const int URLZONE_INTRANET = URLZONE_LOCAL_MACHINE + 1;
	const int URLZONE_TRUSTED = URLZONE_INTRANET + 1;
	const int URLZONE_INTERNET = URLZONE_TRUSTED + 1;
	const int URLZONE_UNTRUSTED = URLZONE_INTERNET + 1;
	const int URLZONE_ESC_FLAG = 0x100;
	const int SZM_CREATE  = 0;
	const int SZM_DELETE  = 0x1;

	HRESULT hr;
	IInternetSecurityManager *pSecurityMgr;
	IInternetZoneManager *pZoneMgr;
	LPCWSTR site1 = SysAllocString(L"http://www.mydomain.com");

	hr = CoCreateInstance(CLSID_InternetSecurityManager, NULL, CLSCTX_INPROC_SERVER, IID_IInternetSecurityManager, (void**)&pSecurityMgr);

	pSecurityMgr->SetZoneMapping((DWORD)2, site1, (DWORD)0); // 2 = Trusted Site, site1 is the URL to add, and 0 is to create the entry.

	pSecurityMgr->Release();
	pZoneMgr->Release();

	return 0;
}