2012-07-12 64 views
2

我在Monotouch中包裝Objective-c庫。問題是,在使用btouch生成DLL之後,以及當我嘗試在示例應用程序中使用DLL中的某些類時,大多數類的類都會返回0x0。我調試了這個問題,並且我發現class_ptr(由Messaging類使用)也返回0x0。包裝Monotouch類的ClassHandle返回null

我檢查了構建輸出(在MonoDevelop中構建項目之後),它看起來鏈接了我的本機庫,但仍然出現相同的錯誤。構建輸出包含在下面。問題是,我有定義爲一個協議GDiOSDelegate如下

@protocol GDiOSDelegate 
@required 

- (void)handleEvent:(GDAppEvent*)anEvent; 
@end 

此協議通過GDiOS類使用(即我也包括在內),但它也需要作爲handleEvent方法需要與從一些物體進行通信與UIApplicationDelegate交互UIApplicationDelegate(在Objective-C中使用庫的等效示例代碼有一個類A:NSObject)。

我這是在GDiOSDelegate結合我設置的typeof屬性UIApplicationDelegate而不是NSObject的

[BaseType(typeof(UIApplicationDelegate))] 

所以,回來我是有錯誤後,我使用了一些方法的方式Monotouch綁定DLL,它拋出一個異常說AppDelegate沒有實現UIApplicationDelegate。

[Register ("AppDelegate")] 
public partial class AppDelegate : GDiOSDelegate 
{...} 

即使我將UIApplicationDelegate而不是GDiOSDelegate作爲基類,也會發生這種情況。

生成的輸出:

Building: GDBinding (Debug) 

Build started 7/16/2012 9:03:46 AM. 
__________________________________________________ 
Project "/Users/thabetkacem/Projects/GDBinding/GDBinding/GDBinding.csproj" (Build target(s)): 

Target CreateGeneratedSourcesDir: 
    Created directory "obj/Debug/ios/" 

Target PrepareForBuild: 
    Configuration: Debug Platform: AnyCPU 

Target CopyFilesMarkedCopyLocal: 
    Copying file from '/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll' to '/Users/thabetkacem/Projects/GDBinding/GDBinding/bin/Debug/GDBinding.dll' 

Target GenerateSatelliteAssemblies: 
No input files were specified for target GenerateSatelliteAssemblies, skipping. 

Target GenerateBindings: 
    Tool /Developer/MonoTouch/usr/bin/btouch execution started with arguments: /d:DEBUG GDBinding.cs /s:StructsAndEnums.cs /tmpdir:obj/Debug/ios/ /sourceonly:obj/Debug/ios//sources.list 
GDBinding.cs(642,22): warning CS0465: Introducing `Finalize' method can interfere with destructor invocation. Did you intend to declare a destructor? 

Target CoreCompile: 
    Tool /Developer/MonoTouch/usr/bin/smcs execution started with arguments: /noconfig /debug:full /debug+ /optimize- /out:obj/Debug/GDBinding.dll /resource:libGD.a libGD.linkwith.cs Extra.cs AssemblyInfo.cs StructsAndEnums.cs obj/Debug/ios/ObjCRuntime/Messaging.g.cs obj/Debug/ios/GDBinding/GDCReadStream.g.cs obj/Debug/ios/GDBinding/GDCWriteStream.g.cs obj/Debug/ios/GDBinding/GDPersistentStoreCoordinator.g.cs obj/Debug/ios/GDBinding/GDFileSystem.g.cs obj/Debug/ios/GDBinding/GDDirectByteBuffer.g.cs obj/Debug/ios/GDBinding/GDSocketDelegate.g.cs obj/Debug/ios/GDBinding/GDSocket.g.cs obj/Debug/ios/GDBinding/GDHttpRequestDelegate.g.cs obj/Debug/ios/GDBinding/GDHttpRequest.g.cs obj/Debug/ios/GDBinding/NSURLCache.g.cs obj/Debug/ios/GDBinding/GDURLLoadingSystem.g.cs obj/Debug/ios/GDBinding/GDCacheController.g.cs obj/Debug/ios/GDBinding/GDPushConnectionDelegate.g.cs obj/Debug/ios/GDBinding/GDPushConnection.g.cs obj/Debug/ios/GDBinding/GDPushChannelDelegate.g.cs obj/Debug/ios/GDBinding/GDPushChannel.g.cs obj/Debug/ios/GDBinding/GDSecureDocs.g.cs obj/Debug/ios/GDBinding/GDAppEvent.g.cs obj/Debug/ios/GDBinding/GDiOSDelegate.g.cs obj/Debug/ios/GDBinding/GDiOS.g.cs obj/Debug/ios/GDBinding/NSMutableURLRequest.g.cs /target:library /unsafe+ /define:DEBUG /reference:/Developer/MonoTouch/usr/lib/mono/2.1/System.dll /reference:/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll /reference:../../../Desktop/GDExtended/GDBinding.dll /reference:/Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll /reference:/Developer/MonoTouch/usr/lib/mono/2.1/mscorlib.dll /warn:4 
obj/Debug/ios/GDBinding/GDSocket.g.cs(273,53): warning CS0436: The type `GDBinding.GDSocketDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition 
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning) 
obj/Debug/ios/GDBinding/GDHttpRequest.g.cs(541,58): warning CS0436: The type `GDBinding.GDHttpRequestDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition 
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning) 
obj/Debug/ios/GDBinding/GDPushConnection.g.cs(180,61): warning CS0436: The type `GDBinding.GDPushConnectionDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition 
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning) 
obj/Debug/ios/GDBinding/GDPushChannel.g.cs(175,58): warning CS0436: The type `GDBinding.GDPushChannelDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition 
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning) 
obj/Debug/ios/GDBinding/GDiOS.g.cs(393,50): warning CS0436: The type `GDBinding.GDiOSDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition 
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning) 
obj/Debug/ios/ObjCRuntime/Messaging.g.cs(53,134): warning CS0436: The type `GDBinding.GDFileStat' conflicts with the imported type of same name'. Ignoring the imported type definition 
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning) 
obj/Debug/ios/GDBinding/GDFileSystem.g.cs(159,31): warning CS0436: The type `GDBinding.GDCReadStream' conflicts with the imported type of same name'. Ignoring the imported type definition 
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning) 
obj/Debug/ios/GDBinding/GDFileSystem.g.cs(181,31): warning CS0436: The type `GDBinding.GDCWriteStream' conflicts with the imported type of same name'. Ignoring the imported type definition 
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning) 
obj/Debug/ios/GDBinding/GDDirectByteBuffer.g.cs(139,46): warning CS0108: `GDBinding.GDDirectByteBuffer.Init' hides inherited member `MonoTouch.Foundation.NSObject.Init()'. Use the new keyword if hiding was intended 
/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll (Location of the symbol related to previous warning) 
obj/Debug/ios/GDBinding/GDSocket.g.cs(177,32): warning CS0436: The type `GDBinding.GDDirectByteBuffer' conflicts with the imported type of same name'. Ignoring the imported type definition 
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning) 
obj/Debug/ios/GDBinding/GDHttpRequest.g.cs(377,46): warning CS0108: `GDBinding.GDHttpRequest.Init' hides inherited member `MonoTouch.Foundation.NSObject.Init()'. Use the new keyword if hiding was intended 
/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll (Location of the symbol related to previous warning) 
obj/Debug/ios/GDBinding/GDHttpRequest.g.cs(449,32): warning CS0436: The type `GDBinding.GDHttpRequest_state_t' conflicts with the imported type of same name'. Ignoring the imported type definition 
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning) 
obj/Debug/ios/GDBinding/NSURLCache.g.cs(79,57): warning CS0436: The type `GDBinding.NSURLCache' conflicts with the imported type of same name'. Ignoring the imported type definition 
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning) 
obj/Debug/ios/GDBinding/GDPushConnection.g.cs(84,31): warning CS0436: The type `GDBinding.GDPushConnection' conflicts with the imported type of same name'. Ignoring the imported type definition 
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning) 
obj/Debug/ios/GDBinding/GDPushChannel.g.cs(148,46): warning CS0108: `GDBinding.GDPushChannel.Init' hides inherited member `MonoTouch.Foundation.NSObject.Init()'. Use the new keyword if hiding was intended 
/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll (Location of the symbol related to previous warning) 
obj/Debug/ios/GDBinding/GDSecureDocs.g.cs(101,85): warning CS0436: The type `GDBinding.SendFileSuccessBlock' conflicts with the imported type of same name'. Ignoring the imported type definition 
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning) 
obj/Debug/ios/GDBinding/GDAppEvent.g.cs(82,32): warning CS0436: The type `GDBinding.GDAppResultCode' conflicts with the imported type of same name'. Ignoring the imported type definition 
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning) 
obj/Debug/ios/GDBinding/GDAppEvent.g.cs(102,32): warning CS0436: The type `GDBinding.GDAppEventType' conflicts with the imported type of same name'. Ignoring the imported type definition 
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning) 
obj/Debug/ios/GDBinding/GDiOSDelegate.g.cs(76,51): warning CS0436: The type `GDBinding.GDAppEvent' conflicts with the imported type of same name'. Ignoring the imported type definition 
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning) 
obj/Debug/ios/GDBinding/GDiOS.g.cs(139,36): warning CS0465: Introducing `Finalize' method can interfere with destructor invocation. Did you intend to declare a destructor? 
obj/Debug/ios/GDBinding/GDiOS.g.cs(163,31): warning CS0436: The type `GDBinding.GDiOS' conflicts with the imported type of same name'. Ignoring the imported type definition 
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning) 
obj/Debug/ios/GDBinding/GDiOS.g.cs(281,94): warning CS0436: The type `GDBinding.GDUIColorTheme' conflicts with the imported type of same name'. Ignoring the imported type definition 
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning) 
obj/Debug/ios/GDBinding/NSMutableURLRequest.g.cs(83,67): warning CS0436: The type `GDBinding.NSMutableURLRequest' conflicts with the imported type of same name'. Ignoring the imported type definition 
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning) 
obj/Debug/ios/ObjCRuntime/Messaging.g.cs(44,84): warning CS0436: The type `GDBinding.Messaging' conflicts with the imported type of same name'. Ignoring the imported type definition 
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning) 

Target DeployOutputFiles: 
    Copying file from '/Users/thabetkacem/Projects/GDBinding/GDBinding/obj/Debug/GDBinding.dll.mdb' to '/Users/thabetkacem/Projects/GDBinding/GDBinding/bin/Debug/GDBinding.dll.mdb' 
    Copying file from '/Users/thabetkacem/Projects/GDBinding/GDBinding/obj/Debug/GDBinding.dll' to '/Users/thabetkacem/Projects/GDBinding/GDBinding/bin/Debug/GDBinding.dll' 
Done building project "/Users/thabetkacem/Projects/GDBinding/GDBinding/GDBinding.csproj". 

Build succeeded. 

Warnings: 

/Users/thabetkacem/Projects/GDBinding/GDBinding/GDBinding.csproj (Build) -> /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Xamarin.ObjcBinding.CSharp.targets 
(GenerateBindings target) -> 

GDBinding.cs(642,22): warning CS0465: Introducing `Finalize' method can interfere with destructor invocation. Did you intend to declare a destructor? 

/Users/thabetkacem/Projects/GDBinding/GDBinding/GDBinding.csproj (Build) -> 
/Library/Frameworks/Mono.framework/Versions/2.10.9/lib/mono/4.0/Microsoft.CSharp.Targets (CoreCompile target) -> 

obj/Debug/ios/GDBinding/GDSocket.g.cs(273,53): warning CS0436: The type `GDBinding.GDSocketDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition 
obj/Debug/ios/GDBinding/GDHttpRequest.g.cs(541,58): warning CS0436: The type `GDBinding.GDHttpRequestDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition 
obj/Debug/ios/GDBinding/GDPushConnection.g.cs(180,61): warning CS0436: The type `GDBinding.GDPushConnectionDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition 
obj/Debug/ios/GDBinding/GDPushChannel.g.cs(175,58): warning CS0436: The type `GDBinding.GDPushChannelDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition 
obj/Debug/ios/GDBinding/GDiOS.g.cs(393,50): warning CS0436: The type `GDBinding.GDiOSDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition 
obj/Debug/ios/ObjCRuntime/Messaging.g.cs(53,134): warning CS0436: The type `GDBinding.GDFileStat' conflicts with the imported type of same name'. Ignoring the imported type definition 
obj/Debug/ios/GDBinding/GDFileSystem.g.cs(159,31): warning CS0436: The type `GDBinding.GDCReadStream' conflicts with the imported type of same name'. Ignoring the imported type definition 
obj/Debug/ios/GDBinding/GDFileSystem.g.cs(181,31): warning CS0436: The type `GDBinding.GDCWriteStream' conflicts with the imported type of same name'. Ignoring the imported type definition 
obj/Debug/ios/GDBinding/GDDirectByteBuffer.g.cs(139,46): warning CS0108: `GDBinding.GDDirectByteBuffer.Init' hides inherited member `MonoTouch.Foundation.NSObject.Init()'. Use the new keyword if hiding was intended 
obj/Debug/ios/GDBinding/GDSocket.g.cs(177,32): warning CS0436: The type `GDBinding.GDDirectByteBuffer' conflicts with the imported type of same name'. Ignoring the imported type definition 
obj/Debug/ios/GDBinding/GDHttpRequest.g.cs(377,46): warning CS0108: `GDBinding.GDHttpRequest.Init' hides inherited member `MonoTouch.Foundation.NSObject.Init()'. Use the new keyword if hiding was intended 
obj/Debug/ios/GDBinding/GDHttpRequest.g.cs(449,32): warning CS0436: The type `GDBinding.GDHttpRequest_state_t' conflicts with the imported type of same name'. Ignoring the imported type definition 
obj/Debug/ios/GDBinding/NSURLCache.g.cs(79,57): warning CS0436: The type `GDBinding.NSURLCache' conflicts with the imported type of same name'. Ignoring the imported type definition 
obj/Debug/ios/GDBinding/GDPushConnection.g.cs(84,31): warning CS0436: The type `GDBinding.GDPushConnection' conflicts with the imported type of same name'. Ignoring the imported type definition 
obj/Debug/ios/GDBinding/GDPushChannel.g.cs(148,46): warning CS0108: `GDBinding.GDPushChannel.Init' hides inherited member `MonoTouch.Foundation.NSObject.Init()'. Use the new keyword if hiding was intended 
obj/Debug/ios/GDBinding/GDSecureDocs.g.cs(101,85): warning CS0436: The type `GDBinding.SendFileSuccessBlock' conflicts with the imported type of same name'. Ignoring the imported type definition 
obj/Debug/ios/GDBinding/GDAppEvent.g.cs(82,32): warning CS0436: The type `GDBinding.GDAppResultCode' conflicts with the imported type of same name'. Ignoring the imported type definition 
obj/Debug/ios/GDBinding/GDAppEvent.g.cs(102,32): warning CS0436: The type `GDBinding.GDAppEventType' conflicts with the imported type of same name'. Ignoring the imported type definition 
obj/Debug/ios/GDBinding/GDiOSDelegate.g.cs(76,51): warning CS0436: The type `GDBinding.GDAppEvent' conflicts with the imported type of same name'. Ignoring the imported type definition 
obj/Debug/ios/GDBinding/GDiOS.g.cs(139,36): warning CS0465: Introducing `Finalize' method can interfere with destructor invocation. Did you intend to declare a destructor? 
obj/Debug/ios/GDBinding/GDiOS.g.cs(163,31): warning CS0436: The type `GDBinding.GDiOS' conflicts with the imported type of same name'. Ignoring the imported type definition 
obj/Debug/ios/GDBinding/GDiOS.g.cs(281,94): warning CS0436: The type `GDBinding.GDUIColorTheme' conflicts with the imported type of same name'. Ignoring the imported type definition 
obj/Debug/ios/GDBinding/NSMutableURLRequest.g.cs(83,67): warning CS0436: The type `GDBinding.NSMutableURLRequest' conflicts with the imported type of same name'. Ignoring the imported type definition 
obj/Debug/ios/ObjCRuntime/Messaging.g.cs(44,84): warning CS0436: The type `GDBinding.Messaging' conflicts with the imported type of same name'. Ignoring the imported type definition 

25 Warning(s) 
0 Error(s) 

Time Elapsed 00:00:05.0845450 

---------------------- Done ---------------------- 

Build: 0 errors, 25 warnings 


Any help would be greatly appreciated. 
+0

您需要張貼一些代碼。包括你試圖綁定的Objective-C以及你爲C#綁定所做的貢獻。 – jonathanpeppers 2012-07-13 12:33:59

回答

0

如果你不鏈接可能出現這種情況,手動或(更好)與[LinkWith]屬性,本地庫(即您綁定)與您的應用程序。

在這種情況下,選擇的消息將不會到達本地代碼,並將返回null(它會顯示手柄(實例或類)是0x0

爲了證實這一點看看你構建輸出(內MonoDevelop的),看看你的libX.a被鏈接到你的應用程序。

也可以嘗試這種在模擬器(I386)和設備(ARMv6及/或ARMv7的),因爲它可能是你的本地庫架構不可用(在你的.a)。

+0

我使用$ btouch binding.cs生成綁定-s:enum.cs -x:extra.cs --link-with = libGD.a,libGD.a我在這裏丟失了什麼?當我嘗試使用MonoDevelop構建庫(AssemmblyInfo.cs包含[LinkWith]屬性)時,在使用dll中類的某些方法時出現錯誤)。謝謝 – Thabet 2012-07-15 23:55:50

+0

@Thabet如果你不嘗試(並回報)我的建議,我不能幫你;-)你也不會提供你在嘗試從MD構建庫時遇到的錯誤(所以我不能幫助再次)。請使用附加數據編輯您的原始問題,以便我(或其他人)能夠使用這些信息來幫助您。 – poupou 2012-07-16 12:01:14

+0

我試過了你的建議,但我仍然遇到這次我描述的同樣的問題。 Merci bcp :) – Thabet 2012-07-16 13:56:24