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?

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?

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.

Attachments
#include "stdafx.h"

bridge::bridge(){    
		// ****************** Initialize Variables *********************
		dpNoArgs.rgvarg = NULL;
		dpNoArgs.rgdispidNamedArgs = NULL;
		dpNoArgs.cArgs = 0;
		dpNoArgs.cNamedArgs = 0;
		
		vOpt.vt = VT_ERROR;
		vOpt.scode = DISP_E_PARAMNOTFOUND;

		// ******************** Start Automation ***********************;
		//Initialize the COM libraries
		::CoInitialize(NULL);

		// Create an instance of the Word application and obtain the 
		// pointer to the application's IDispatch interface.
		
		CLSIDFromProgID(L"Word.Application", &clsid);  
		HRESULT hr = ::CoCreateInstance( clsid, NULL, CLSCTX_SERVER,
		                                 IID_IUnknown, (void**) &pUnk);
		
		hr = pUnk->QueryInterface(IID_IDispatch, (void**)&pDispApp);

		// Get IDispatch* for the Documents collection object
		szFunction = OLESTR("Documents");
		hr = pDispApp->GetIDsOfNames (IID_NULL, &szFunction, 1, 
			                          LOCALE_USER_DEFAULT, &dispid_Docs);
		hr = pDispApp->Invoke (dispid_Docs, IID_NULL, 
			                    LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, 
			                &dpNoArgs, &vResult, NULL, NULL);
		pDispDocs = vResult.pdispVal;
		// Invoke the Add method on the Documents collection object
		// to create a new document in Word
		// Note that the Add method can take up to 3 arguments, all of 
		// which are optional. You are not passing it any so you are 
		// using an empty DISPPARAMS structure
		szFunction = OLESTR("Add");
		hr = pDispDocs->GetIDsOfNames(IID_NULL, &szFunction, 1, 
		                              LOCALE_USER_DEFAULT, 
		                              &dispid_DocsAdd);
		hr = pDispDocs->Invoke(dispid_DocsAdd, IID_NULL, 
		                       LOCALE_USER_DEFAULT, DISPATCH_METHOD, 
		                       &dpNoArgs, &vResult, NULL, NULL);
	
	    // Get IDispatch* for the Selection object
	    szFunction = OLESTR("Selection");
	    hr = pDispApp->GetIDsOfNames (IID_NULL, &szFunction, 1, 
	                                  LOCALE_USER_DEFAULT, &dispid_Sel);
	    hr = pDispApp->Invoke (dispid_Sel, IID_NULL, LOCALE_USER_DEFAULT,
	                           DISPATCH_PROPERTYGET, &dpNoArgs, &vResult, 
	                           NULL, NULL);
	    pDispSel = vResult.pdispVal;
	
	
	    // Get the DISPIDs of the TypeText and TypeParagraph methods of 
	    // the Selection object.  You'll use these DISPIDs multiple
	    // times.
	    szFunction = OLESTR("TypeText");
	    hr = pDispSel->GetIDsOfNames(IID_NULL, &szFunction, 1, 
	                                  LOCALE_USER_DEFAULT, 
	                                  &dispid_TypeText);
	
	    szFunction = OLESTR("TypeParagraph");
	    hr = pDispSel->GetIDsOfNames(IID_NULL, &szFunction, 1, 
	                                  LOCALE_USER_DEFAULT, 
	                                  &dispid_TypePara);
	
		
		// Get IDispatch* for the Find interface
		EXCEPINFO excep;
		szFunction = OLESTR("Find");
	    hr = pDispSel->GetIDsOfNames (IID_NULL, &szFunction, 1, 
	                                  LOCALE_USER_DEFAULT, &dispid_Find);
	    hr = pDispSel->Invoke (dispid_Find, IID_NULL, LOCALE_USER_DEFAULT,
	                           DISPATCH_PROPERTYGET, &dpNoArgs, &vResult, 
	                           &excep, NULL);
		pDispFind = vResult.pdispVal;
		
		//Get the DISPID of the Execute method of the Find object
		szFunction = OLESTR("Execute");
		hr = pDispFind->GetIDsOfNames(IID_NULL, &szFunction, 1, 
	                                  LOCALE_USER_DEFAULT, 
	                                  &dispid_Execute);

		// The TypeText method has and requires only one argument, a 
	    // string, so set up the DISPPARAMS accordingly
	    VARIANT vArgsTypeText[1];
	    DISPPARAMS dpTypeText;
	
	    bstrTemp = ::SysAllocString(OLESTR("One"));
	    vArgsTypeText [0].vt = VT_BSTR;
	    vArgsTypeText [0].bstrVal = bstrTemp;
	    dpTypeText.cArgs = 1;
	    dpTypeText.cNamedArgs = 0;
	    dpTypeText.rgvarg = vArgsTypeText;
	}


	void bridge::FindReplace(wchar_t * Fstr, wchar_t * Rstr){

		//Find the text contained in Fstr
		//setup DISPPARAMS for the Execute method, requires only 1 of the 15 arguments but we set the wrap option too
		VARIANT vArgsFind[8];
		DISPPARAMS dpFind;
	
		bstrTemp = ::SysAllocString(Fstr);
		vArgsFind[7].vt = VT_BSTR;         //text to be found
		vArgsFind[7].bstrVal = bstrTemp;
		vArgsFind[6] = vOpt;			   //omitted
		vArgsFind[5] = vOpt;			   //omitted
		vArgsFind[4] = vOpt;			   //omitted
		vArgsFind[3] = vOpt;			   //omitted
		vArgsFind[2] = vOpt;			   //omitted
		vArgsFind[1] = vOpt;			   //omitted
		vArgsFind[0].vt = VT_BOOL;		   //wrap
		vArgsFind[0].boolVal = TRUE;
		dpFind.cArgs = 8;
		dpFind.cNamedArgs = 0;
		dpFind.rgvarg = vArgsFind;
	
		hr = pDispFind->Invoke(dispid_Execute, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dpFind, NULL, NULL, NULL);
		
			::SysFreeString(bstrTemp);
		bstrTemp = ::SysAllocString(Rstr);
		hr = pDispSel->Invoke (dispid_TypeText, IID_NULL, 
                           LOCALE_USER_DEFAULT, DISPATCH_METHOD, 
                           &dpTypeText, NULL, NULL, NULL);
		::SysFreeString(bstrTemp);
	}
	bridge::~bridge(){
	    ::SysFreeString(bstrTemp);
		pDispActiveDoc->Release();
		pDispSel->Release();
		pDispDocs->Release();
		pDispApp->Release();
		pUnk->Release();
		
		::CoUninitialize();
	}
	void bridge::done(wchar_t* path){
		// Get IDispatch* for the ActiveDocument object
		szFunction = OLESTR("ActiveDocument");
		hr = pDispApp->GetIDsOfNames (IID_NULL, &szFunction, 1, 
		                              LOCALE_USER_DEFAULT, 
		                              &dispid_ActiveDoc);
		hr = pDispApp->Invoke (dispid_ActiveDoc, IID_NULL, 
		                       LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, 
		                       &dpNoArgs, &vResult, NULL, NULL);
		pDispActiveDoc = vResult.pdispVal;
	
	    //Set up the DISPPARAMS for the SaveAs method (11 arguments)
	    VARIANT vArgsSaveAs[11];
	    DISPPARAMS dpSaveAs;
	    dpSaveAs.cArgs = 11;
	    dpSaveAs.cNamedArgs = 0;
	    dpSaveAs.rgvarg = vArgsSaveAs;
	
	    BSTR bstrEmptyString;
	    bstrEmptyString = ::SysAllocString(OLESTR(""));
	
	    VARIANT vFalse;
	    vFalse.vt = VT_BOOL;
	    vFalse.boolVal = FALSE;
	
	    bstrTemp = ::SysAllocString(path);
	    vArgsSaveAs[10].vt = VT_BSTR;         
	    vArgsSaveAs[10].bstrVal = bstrTemp;        //Filename
	    vArgsSaveAs[9].vt = VT_I4;            
	    vArgsSaveAs[9].lVal = 0;                   //FileFormat
	    vArgsSaveAs[8] = vFalse;                   //LockComments
	    vArgsSaveAs[7].vt = VT_BSTR;
	    vArgsSaveAs[7].bstrVal = bstrEmptyString;  //Password
	    vArgsSaveAs[6].vt = VT_BOOL;      
	    vArgsSaveAs[6].boolVal = TRUE;             //AddToRecentFiles
	    vArgsSaveAs[5].vt = VT_BSTR;
	    vArgsSaveAs[5].bstrVal = bstrEmptyString;  //WritePassword
	    vArgsSaveAs[4] = vFalse;                   //ReadOnlyRecommended
	    vArgsSaveAs[3] = vFalse;                   //EmbedTrueTypeFonts
	    vArgsSaveAs[2] = vFalse;                //SaveNativePictureFormat
	    vArgsSaveAs[1] = vFalse;                   //SaveFormsData
	    vArgsSaveAs[0] = vFalse;                   //SaveAsOCELetter
	
	
	    //Invoke the SaveAs method
	    szFunction = OLESTR("SaveAs");
	    hr = pDispActiveDoc->GetIDsOfNames(IID_NULL, &szFunction, 1, 
	                                  LOCALE_USER_DEFAULT, 
	                                  &dispid_SaveAs);
	    hr = pDispActiveDoc->Invoke(dispid_SaveAs, IID_NULL, 
	                                LOCALE_USER_DEFAULT, DISPATCH_METHOD, 
	                                &dpSaveAs, NULL, NULL, NULL);
	    ::SysFreeString(bstrEmptyString);
		
	
	
	    //Make Word Visible
		DISPID dispid_Visible;
		szFunction = OLESTR("Visible");
		hr = pDispApp->GetIDsOfNames(IID_NULL, &szFunction, 1, 
		                             LOCALE_USER_DEFAULT, &dispid_Visible);
		VARIANT pArgs2[1];
		DISPPARAMS dpVisible;
		pArgs2[0].vt= VT_BOOL;
		pArgs2[0].boolVal = TRUE;
		dpVisible.cArgs = 1;
		dpVisible.cNamedArgs = 1;
		dpVisible.rgvarg = pArgs2;
		DISPID dispidNamed = DISPID_PROPERTYPUT;
		dpVisible.rgdispidNamedArgs = &dispidNamed;
		
		hr = pDispApp->Invoke (dispid_Visible, IID_NULL, LOCALE_USER_DEFAULT,
		                       DISPATCH_PROPERTYPUT, &dpVisible, NULL, NULL, 
		                       NULL);
	
		}
	/*
	
	void bridge::ErrHandler(HRESULT hr, EXCEPINFO excep){
		if(hr==DISP_E_EXCEPTION)
		{
		    char errDesc[512];
		    char errMsg[512];
		    wcstombs(errDesc, excep.bstrDescription, 512);
		    sprintf(errMsg, "Run-time error %d:\n\n %s", 
		            excep.scode & 0x0000FFFF,  //Lower 16-bits of SCODE
		            errDesc);                  //Text error description
		    ::MessageBox(NULL, errMsg, "Server Error", MB_SETFOREGROUND | 
		              MB_OK);
		}
		else
		{
		    LPVOID lpMsgBuf; 
		    ::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 
		                    FORMAT_MESSAGE_FROM_SYSTEM | 
		                    FORMAT_MESSAGE_IGNORE_INSERTS, NULL, hr,
		                    MAKELANGID(LANG_NEUTRAL, 
		                    SUBLANG_DEFAULT),(LPTSTR) &lpMsgBuf,
		                    0, NULL);
		    ::MessageBox(NULL, (LPCTSTR)lpMsgBuf, "COM Error", 
		                 MB_OK | MB_SETFOREGROUND);
		    ::LocalFree( lpMsgBuf );
		}
		
	}*/
class bridge{
	// *************** Declare Some Variables ********************

    // Variables that will be used and re-used in our calls
    DISPPARAMS dpNoArgs;
    VARIANT vResult;
	VARIANT vOpt;			   //optional parameter

    OLECHAR FAR* szFunction;
    BSTR bstrTemp;

	VARIANT vArgsTypeText[1];
    DISPPARAMS dpTypeText;

	HRESULT hr;

	IUnknown* pUnk;
	CLSID clsid;

    // IDispatch pointers for Word's objects
    IDispatch* pDispDocs;      //Documents collection
    IDispatch* pDispSel;       //Selection object
    IDispatch* pDispActiveDoc; //ActiveDocument object
	IDispatch* pDispFind;      //Find interface
	IDispatch* pDispApp;       //Application object

    // DISPIDs
    DISPID dispid_Docs;        //Documents property of Application 
                               //object

    DISPID dispid_DocsAdd;     //Add method of Documents collection 
                               //object
    DISPID dispid_Sel;         //Selection property of Application 
                               //object
    DISPID dispid_TypeText;    //TypeText method of Selection object
    DISPID dispid_TypePara;    //TypeParagraph method of Selection 
                               //object
    DISPID dispid_ActiveDoc;   //ActiveDocument property of 
                               //Application object
    DISPID dispid_SaveAs;      //SaveAs method of the Document object
	DISPID dispid_Find;        //Find property of Application object
	DISPID dispid_Execute;     //Execute method of Find interface

	void ErrHandler(HRESULT, EXCEPINFO);
public:
	void done(wchar_t*);
	void FindReplace(wchar_t*, wchar_t*);
	bridge();
	~bridge();
};

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;
Comments
Nice one :)

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.

This question has already been answered. Start a new discussion instead.