2016-12-29 26 views
1

COM對象是我的全新領域,我搜索了很多,沒有運氣。我打電話給第三方COM對象,我可以讓它做它應該做的事情,但它總是返回null,我需要下一步的值。它的示例是在Python中,並按預期返回。我的代碼在下面,我怎麼設置這個,所以我可以得到返回值?C#返回值調用第三方COM對象

Type t = Type.GetTypeFromProgID("3rdParty.Name"); 

object publisher = Activator.CreateInstance(t); 

object[] args = new object[6]; 

//fill in the args 

//It works and does what it is supposed to behind the scenes, 
//but need the int return value. 
//Right now it is always null 
int? handle = (int?)t.InvokeMember("DoYourThing", 
            BindingFlags.InvokeMethod, 
            null, 
            publisher, 
            args); 
+3

爲什麼你不只是[使用COM互操作包裝(http://stackoverflow.com/questions/635839/best-way-to-access-com-objects-from-c-尖銳)?它會把整個事情變成一項微不足道的任務。 –

+0

我不知道存在,因爲我說這對我來說都是新的。奇蹟般有效! –

回答