// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
// C++
#include <iostream>
using namespace std;

// Windows
#include <windows.h>
#include <initguid.h>
#include <tchar.h>

// our stuff
#import "SNat.tlb" no_namespace named_guids

int main()
{
    CoInitialize(NULL);
    try
    {
        ISPtr spS(__uuidof(CoS));
        long a = 123;
        long b = 456;
        long c = spS->Add(a, b);
        wcout << c << endl;
        BSTR s = SysAllocString(L"ABC");
        BSTR s2 = spS->Dup(s);
        wcout << s2 << endl;
        SysFreeString(s);
        SysFreeString(s2);
        BSTR temp = SysAllocString(L"ABC");
        spS->PutIv(123);
        spS->PutSv(temp);
        SysFreeString(temp);
        spS->M();
        long iv = spS->GetIv();
        BSTR sv = spS->GetSv();
        wcout << iv << " " << sv << endl;
        SysFreeString(sv);
        spS = NULL;
    }
    catch (_com_error er)
    {
        _tprintf("%s\n", er.ErrorMessage());
    }
    //
    CoUninitialize();
    return 0;
}

