Score:0

C# wrapper for Debian apt library libapt-pkg

cn flag

I need to retrieve package information in my C# application running on Linux. I've tried to use Python.NET which wrap python-apt which wrap libapt-pkg.so, and it works but I would prefer to go more direct by pinvoke libapt-pkg.

But I need help on my DLLImport statement.

When using python-apt I first initialize the apt module, then instantiate the Cache() class and then call the Cache.keys() function which retrieve all package-names as a string array.

If I can get this to work using pinvoke I believe I have a good chance getting the rest working too (retrieve the more advanced stuff)

Just to show some code which doesn't work, but just to get started:

[DllImport("libapt-pkg")]
public static extern dynamic GetPkgCache(Boolean BuildCaches);

dynamic AptCache = GetPkgCache(false);

I've been looking in the header file cachefile.h of the apt project. Maybe these lines are useable for my DllImport statement?

..
inline operator pkgCache &() const {return *Cache;};
inline operator pkgCache *() const {return Cache;};
..
inline pkgCache* GetPkgCache() { BuildCaches(NULL, false); return Cache; };
..

But I'm new to C/C++ so it doesn't make much sense for me at present.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.