Please replace all "~" into " " (i.e. space), since my blog sucks when pasting code.
usage: save the code as showver.py, thn "showver.py assembly_filename"
#!/usr/bin/env~ipy
from System.Reflection import *
import sys
def~main(argv=None):
~~~~if~argv~is~None:
~~~~~~~~argv~=~sys.argv
~~~~assemblyFile~=~argv[1];
~~~~print~'Version~of~"%s":'~%~assemblyFile
~~~~ass~=~Assembly.LoadFile(assemblyFile)
~~~~print~ass.GetName().Version
if~__name__~==~"__main__":
~~~~main()
| Data Type | ILP32 | ILP64 | LP64 | LLP64 |
| char | 8 | 8 | 8 | 8 |
| short | 16 | 16 | 16 | 16 |
| int | 32 | 64 | 32 | 32 |
| long | 32 | 64 | 64 | 32 |
| long long | 64 | 64 | 64 | 64 |
| pointer | 32 | 64 | 64 | 64 |
Most 64bit Unix/Linux systems use LP64, 64bit Windows Systems use LLP64.
So be careful with the size of "int" and "long" in the C/C++ source code.
E.g. When doing dllimport in .Net, we shall use Int32 for "int" and IntPtr for "long" on Linux; we shall use Int32 for both "int" and "long" on Windows.
Now do some physical exercise 六月 8th, 2009
╔囧╗╔囧╝╚囧╝╚囧╗╔囧╗╔囧╝╚囧╝╚囧╗╔囧╗╔囧╝╚囧╝╚囧╗╔囧╗╔囧╝╚囧╝╚囧╗╔囧╗╔囧╝╚囧╝╚囧╗╔囧╗╔囧╝╚囧╝╚囧╗╔囧╗╔囧╝╚囧╝╚囧╗
dbus2net is released 六月 3rd, 2009
What's dbus2net
Dbus2Net is a tool to enable you import and invoke DBus services in a simple manner. i.e. you can select a dbus service from a dialog, then the tool will auto-generate a .Net dll to access the dbus service for you. You can use dbus2net as a standalone GUI application or a monodevelop addin.
How to find the demo, documentation and source code?
Search "dbus2net" in your favorite search engine.
Blog Applications on Google appengine 六月 3rd, 2009
Copied from this post
Plog http://code.google.com/p/pyweblog/ sample: http://plog.appspot.com
n23 http://code.google.com/p/n23/ sample: http://n23.appspot.com/blog
xian-min http://code.google.com/p/xian-min/ sample: http://xian-min.appspot.com
tublog http://code.google.com/p/tublog/ sample: http://ether.appspot.com
NiuBi http://code.google.com/p/niubi/ sample: http://niubi.appspot.com
onlypy http://code.google.com/p/onlypy/ sample: http://onlypython.appspot.com
Potlatch Blog http://github.com/araddon/potlatchblog/tree/master sample: http://aaronspotlatch.appspot.com/
Bloog http://github.com/DocSavage/bloog/tree/master sample: http://bloog.appspot.com/
My twitter 四月 3rd, 2009
One tip for MonoDevelop non-english users 三月 24th, 2009
I believe every visual studio user loves to use the "show auto completion window" (the short-cut is Ctrl + J) function when editing code.
MonoDevelop provided the same function, however by default cannot be short-cut-key-inovked by non-english users (i.e. those use more than one input methods), since its short-cut is Ctrl + Space (IIRC it follows Eclipse?), which is normally also used to switch input methods.
You can change the key-bindings at preference settings, to enable this useful editing function.
Any application shall never use the "Ctrl + Space" key-binding on Windows/Linux.
The funniest Web UI I've ever seen 三月 19th, 2009
Today I googled an open source music player for Last.fm., whose web site is:
http://folks.o-hand.com/iain/last-exit/
I just can not stop laughing when being navigated to this site...
very cute.
E.g. In WPF UIA, textbox exposed 3 patterns,
However in silverlight, there is only one.
And similar bugs can be easily found...
Marshal linked list from c to c# 二月 26th, 2009
Today I wrote a managed wrapper for Alex's universal encoding detector (ued) lib. One function exposed by this lib is defined as below:
LinkedList * detect (char * stream, int size)
Where the LinkedList is defined as below:
typedef struct {
LinkedList *next;
LinkedList *prev;
} LinkedList;
And actually the detect function returns a result of EncodingEntry list type, therefore we have an EncodingEntry struct which contains the LinkedList struct at the head:
typedef struct {
LinkedList link;
int score;
char* encoding;
} EncodingEntry;
Linux kernal and many other open source projects usually use similar code to return a non-fixed-size array, this kind of struct defination is common, however in C# it's difficult for you to manipulate pointors without using unsafe code. And hereby I want to share how I wrap the LinkedList without introducing unsafe code.
Let me firstly show the wrapping result, then discuss how it's implemented.
1. The result is now C# users can call libued by through this wrapper method:
public static IEumerable<EncodingEntry> detect (byte[] contentToDetect);
//sample usage:
foreach (EncodingEntry entry in detect(textBytes))
{
Console.WriteLine("Encoding: {0}, {1}", entry.score, entry.encoding);
}
2. How to implement this wrapper. Firstly we define LinkedList and EncodingEntry structs in C#, notice that there is no LinkedList head in the EncodingEntry structs, since I don't want to confuse the C# user (also you may want store the LinkedList head in the EncodingEntry as private fields, that shall be no problem either):
[StructLayout(LayoutKind.Sequential)]
struct LinkedList
{
public System.IntPtr next;
public System.IntPtr prev;
}
[StructLayout(LayoutKind.Sequential)]
struct EncodingEntry
{
public int score;
public string encoding;
}
Then we import the detect function from the dynamic library file, and map the result to IntPtr directly:
[DllImport ("libuniversal_encoding_detector.so")]
private static extern IntPtr detect (byte[] text, int size);
Then finally we write the wrapper function:
public static IEnumerable<EncodingEntry> detect (byte[] text)
{
if (text == null)
text = new byte[0];
IntPtr entryPtr = detect(text, text.Length);
while (entryPtr != IntPtr.Zero)
{
LinkedList listItem = (LinkedList)Marshal.PtrToStructure(entryPtr, typeof(LinkedList));
int entryPtrVal = entryPtr.ToInt32();
entryPtrVal += 2 * Marshal.SizeOf(typeof(IntPtr)); //sizeof prev and next ptr.
entryPtr = new IntPtr(entryPtrVal);
EncodingEntry entry = (EncodingEntry)Marshal.PtrToStructure(entryPtr, typeof(EncodingEntry));
yield return entry;
entryPtr = listItem.next;
}
}
In the wrapper method
1. I use Marshal class to memcpy the struct content out from an IntPtr, and avoid unsafe code at the same time.
2. We need to increase the pointor so that we can skip the LinedList header and jump to the EncoingEntry part. I don't what's the offical way to do this, since IntPtr dosen't provide such kind of method. My way is to firstly use
int entryPtrVal = entryPtr.ToInt32();
to convert a IntPtr to int, then increase/decrease the int value, and then use
entryPtr = new IntPtr(entryPtrVal);
to convert the pointor back.
When walk the pointor value, we use "Marshal.SizeOf" to make sure 64bit pointor is also supported, since you cannot simply get the size of pointor used in current OS by using sizeof(IntPtr).
//walk pointor sample:
entryPtrVal += 2 * Marshal.SizeOf(typeof(IntPtr));
BTW, now I find a code snippet formatter is quite necessary, and I plan to search and integrate one into the blog engine next week.
3. I used "yield return" to retrieve the IEnumerable. It's intersting for me to find out that statements after the "yield return" (i.e. "entryPtr = listItem.next;") will also be executed.