用于TFS API的C++包装器

C++ Wrapper for TFS API

本文关键字:包装 C++ TFS API 用于      更新时间:2023-10-16

我在VS 2012中有两个项目试图为Team Foundation Server API构建C++包装器。

#pragma once    
using namespace System;
using namespace System::Reflection;    
using namespace System::Collections::ObjectModel;
using namespace Microsoft::TeamFoundation::Client;
using namespace Microsoft::TeamFoundation::Framework::Common;
using namespace Microsoft::TeamFoundation::Framework::Client;
namespace ManagedDll {
    public ref class  TFSAUth
    {
    public:
         TFSAUth();
        ~ TFSAUth();
        void AuthUser() 
        { 
            System::String ^x = gcnew String( "http://myhost:8080/tfs");
            System::String ^u = gcnew String( "user");
            System::String ^p = gcnew String( "Pass");
            System::Net::NetworkCredential ^c = gcnew System::Net::NetworkCredential(u, p);
            TeamFoundationServer ^something = gcnew TeamFoundationServer(x, c);
            something->Authenticate();
            System::String ^col = gcnew String (something->TfsTeamProjectCollection->Name);
            Console::WriteLine(col);        
        }
    private:
    };
     TFSAUth:: TFSAUth()
    {
    }
     TFSAUth::~ TFSAUth()
    {
    }
}
__declspec(dllexport) void Auth()
{
    ManagedDll::TFSAUth work;
    work.AuthUser();
}

这是库项目,我有一个使用此库的测试应用程序。

#include "stdafx.h"
#include "conio.h"
#include <iostream>
#include <windows.h>
#include "ManagedDll.h"
_declspec(dllexport) void Auth();
int _tmain()
{
    Auth();
    system("pause");
    return 0;
}

我工作了一段时间,打开这个项目,看看我是否能做得更远。今天它编译失败,给了我链接器错误。

TestApp.obj:错误LNK2019:未解析的外部符号"void __cdeclAuth(void)"(?Auth@@YAXXZ)在函数_wmain 中引用

我不知道为什么,因为一切都没有改变。但除此之外,我想知道在为TFS API创建C++包装器时,我是否做了正确的事情。

任何帮助/示例/建议都将不胜感激,因为这是我第一次尝试使用包装器。

在本机C++项目(测试应用程序)中,必须包含托管C++项目(ManagedDll)的lib文件。

管理C++DLL中导出的DLL函数与本机C++DLL中的函数相同,您可以按照以下步骤操作:将Lib文件作为链接器输入以使其工作。

此外,您应该删除

_declspec(dllexport) void Auth();

在测试应用程序中。