2015-04-23 41 views
-1

我不是C#的人。不用說,我沒有這方面的經驗。如何使用C#調用API?

我買了一個軟件,並將它安裝在我的電腦上。現在我想在我的軟件上使用它的一些功能(我在C#中進行規劃)。所以我給那些賣給我軟件的人發了消息,他給我發了一個兩頁的pdf文件來解釋要做什麼。

它指出:

This software features a COM interface. 

    And it goes saying it's API contains a function "stackAPI". 

    and the parameters used are apiname type string, apipass type string. 

    Return values type long. 0 for sucess and 1 for error. 

這一切都指出,我累了谷歌搜索,它不能幫助我的人。那麼我該如何開始?當我在c#上編寫下面的代碼時,它給我錯誤。

string[] apiname; 
string[] apipass; 
stackAPI(apiname, apipass); 

我知道,如果我使用的DLL我會導入爲

[DllImport("example.dll"] 

但是沒有提供DLL。 我是否需要將路徑添加到安裝軟件的文件夾以調用API?

+1

如果您使用的Visual Studio看看https://msdn.microsoft.com/en-us/library/hsy826az%28v=vs.140%29.aspx –

+0

你有沒有寫過一個簡單的C#程序? – Alex

+1

在Visual Studio項目中 - >引用 - > COM並查看它是否列出(否則瀏覽到DLL) - >右鍵單擊新引用 - >在obj瀏覽器中查看 –

回答

0

如果有人想知道我是怎麼做的。經過一週的搜索,我今天能夠找到解決方案。我想調用函數stackAPI(apiname, apipass);

stackAPI(apiname, apipass)是的stack.callapi 成員所以我寫了:

dynamic lifestohack = Activator.CreateInstance(Type.GetTypeFromProgID("stack.callapi")); 

不僅僅是你可以這樣調用該函數。

int rv; 
string[] apiname; 
string[] apipass; 
rv=lifestoahck.stackAPI(apiname, apipass); 

希望它可以幫助別人。

0

要開始:

using example.dll; 

然後在你的主類:

example.CustomService api = new example.CustomService(); 
var response = api.Dostuff(); 
Console.WriteLine(response); 
+0

沒有DLL提供。我唯一擁有的是安裝在我的電腦上的軟件以及說明問題中所寫內容的api文檔。 – Lifestohack

+0

好吧,對不起,沒有讀過最後一行。 –