Hi, i'm a new learner of the ways of COM and, when trying to recode a code example found in Automating Office by Lori Turner from just a demo of Word interaction into a c++ class (which i will be using in my program) i come across these linker errors:

1>Linking...
1>bridge.obj : error LNK2028: unresolved token (0A00000E) "extern "C" void __stdcall CoUninitialize(void)" (?CoUninitialize@@$$J10YGXXZ) referenced in function "public: __thiscall bridge::~bridge(void)" (??1bridge@@$$FQAE@XZ)
1>bridge.obj : error LNK2028: unresolved token (0A000010) "extern "C" void __stdcall SysFreeString(wchar_t *)" (?SysFreeString@@$$J14YGXPA_W@Z) referenced in function "public: void __thiscall bridge::FindReplace(wchar_t *,wchar_t *)" (?FindReplace@bridge@@$$FQAEXPA_W0@Z)
1>bridge.obj : error LNK2028: unresolved token (0A000011) "extern "C" wchar_t * __stdcall SysAllocString(wchar_t const *)" (?SysAllocString@@$$J14YGPA_WPB_W@Z) referenced in function "public: __thiscall bridge::bridge(void)" (??0bridge@@$$FQAE@XZ)
1>bridge.obj : error LNK2028: unresolved token (0A000018) "extern "C" long __stdcall CoCreateInstance(struct _GUID const &,struct IUnknown *,unsigned long,struct _GUID const &,void * *)" (?CoCreateInstance@@$$J220YGJABU_GUID@@PAUIUnknown@@K0PAPAX@Z) referenced in function "public: __thiscall bridge::bridge(void)" (??0bridge@@$$FQAE@XZ)
1>bridge.obj : error LNK2028: unresolved token (0A000019) "extern "C" long __stdcall CLSIDFromProgID(wchar_t const *,struct _GUID *)" (?CLSIDFromProgID@@$$J18YGJPB_WPAU_GUID@@@Z) referenced in function "public: __thiscall bridge::bridge(void)" (??0bridge@@$$FQAE@XZ)
1>bridge.obj : error LNK2028: unresolved token (0A00001A) "extern "C" long __stdcall CoInitialize(void *)" (?CoInitialize@@$$J14YGJPAX@Z) referenced in function "public: __thiscall bridge::bridge(void)" (??0bridge@@$$FQAE@XZ)
1>bridge.obj : error LNK2019: unresolved external symbol "extern "C" wchar_t * __stdcall SysAllocString(wchar_t const *)" (?SysAllocString@@$$J14YGPA_WPB_W@Z) referenced in function "public: __thiscall bridge::bridge(void)" (??0bridge@@$$FQAE@XZ)
1>bridge.obj : error LNK2019: unresolved external symbol "extern "C" long __stdcall CoCreateInstance(struct _GUID const &,struct IUnknown *,unsigned long,struct _GUID const &,void * *)" (?CoCreateInstance@@$$J220YGJABU_GUID@@PAUIUnknown@@K0PAPAX@Z) referenced in function "public: __thiscall bridge::bridge(void)" (??0bridge@@$$FQAE@XZ)
1>bridge.obj : error LNK2019: unresolved external symbol "extern "C" long __stdcall CLSIDFromProgID(wchar_t const *,struct _GUID *)" (?CLSIDFromProgID@@$$J18YGJPB_WPAU_GUID@@@Z) referenced in function "public: __thiscall bridge::bridge(void)" (??0bridge@@$$FQAE@XZ)
1>bridge.obj : error LNK2019: unresolved external symbol "extern "C" long __stdcall CoInitialize(void *)" (?CoInitialize@@$$J14YGJPAX@Z) referenced in function "public: __thiscall bridge::bridge(void)" (??0bridge@@$$FQAE@XZ)
1>bridge.obj : error LNK2019: unresolved external symbol "extern "C" void __stdcall SysFreeString(wchar_t *)" (?SysFreeString@@$$J14YGXPA_W@Z) referenced in function "public: void __thiscall bridge::FindReplace(wchar_t *,wchar_t *)" (?FindReplace@bridge@@$$FQAEXPA_W0@Z)
1>bridge.obj : error LNK2019: unresolved external symbol "extern "C" void __stdcall CoUninitialize(void)" (?CoUninitialize@@$$J10YGXXZ) referenced in function "public: __thiscall bridge::~bridge(void)" (??1bridge@@$$FQAE@XZ)
1>C:\Users\remuladgryta\Documents\Visual Studio 2008\Projects\testapp\Debug\testapp.exe : fatal error LNK1120: 12 unresolved externals

I'm guessing there's something I've forgot to include, but I have no idea of what. Any help?

Your program needs to link with Ole32.lib. Check the project setting of your compiler to see that it is doing that.

Ok, I'm pretty new to c++ (have been using java untill just recently) and definetly new to visual studio so... how exactly do I do that?

what version of the compiler IDE are you using?

menu Project --> Properties (bottom item of the popup menu) -->expand the Configuration Properties tab --> Linker --> Input. The first line on the right side is "Additional Dependencies". Add the name of the library there.

An alternate way to do it is to add this near the top of one of the *.cpp files in your project #pragma comment(lib, "ole32.lib")

ok... I went to the Additional Dependencies setting, and when klicking on the ...-button one of the libraries listed is ole32.lib. So I tried the comment method, but I still get the same errors

I believe this is it, but if there is any other file you want me to upload, just ask.

you need to include windows.h, not ole32.h. Here are the changes you need to make to stdafx.h. Notice I deleted the line I suggested previously because windows.h forces all the necessary libraries.

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once

// TODO: reference additional headers your program requires here
#include "windows.h"
#include <stdio.h>
#include <iostream>
#include <tchar.h>
#include "bridge.h"
using namespace std;
commented: Nice one :) +12

Tried it. For some reason I still get the same linking errors.

zip up your entire project and attach it to your post. Delete the compiler-generated files, especially those precompiled header files.

I put all the .cpp and .h files into a separate folder, made a new project from existing files. Works like a charm. still don't know what went wrong in the original project though, it's obviously not a c++ code problem. I can't seem to be able to attatch the zipped project for some reason, will try again in a few hours.

Thanks a lot for your time and effort :)

Check the spelling on the Function name and make sure it matches the called Prototype.