[Kde-bindings] playground/bindings/kimono
Richard Dale
rdale at foton.es
Thu Oct 19 20:15:54 UTC 2006
On Thursday 19 October 2006 18:15, Arno Rehn wrote:
> SVN commit 597228 by arnorehn:
>
> * Added support for marshalling C++-QStringLists to C#-ArrayLists
> (not tested yet)
>
> CCMAIL: kde-bindings at kde.org
>
>
>
> M +5 -0 ChangeLog
> M +31 -1 SmokeInvocation.cs
> M +53 -14 handlers.cpp
I tried a test with this code:
ArrayList test = QColor.ColorNames();
foreach (string str in test) {
Console.WriteLine("color: {0}", str);
}
The QStringList was being passed correctly to the marshaller. Then I added
some printfs:
char **
QStringListToStringArray(void* ptr)
{
printf("QStringListToStringArray: ptr: %p\n", ptr);
QStringList * s = (QStringList*) ptr;
char ** result = (char **) calloc(s->count(), sizeof(char *));
for (int i = 0; i < s->count(); i++) {
result[i] = strdup((*s)[i].toLatin1().constData());
printf("QStringListToStringArray: s: %s\n", (*s)[i].toLatin1().constData());
}
return result;
}
and the array was still there ok. However when it returned in
SmokeInvocation.cs, there was a null reference in 'string[] s' and it failed:
static IntPtr QStringListToArrayList(IntPtr ptr) {
Console.WriteLine("ENTER QStringListToArrayList ptr: {0}", ptr);
string[] s = QStringListToStringArray(ptr);
Console.WriteLine("QStringListToArrayList s: {0}", s);
Console.WriteLine("QStringListToArrayList s[0]: {0}", s[0]);
ArrayList al = new ArrayList(s);
return (IntPtr) GCHandle.Alloc(al);
}
Unhandled Exception: System.NullReferenceException: Object reference not set
to an instance of an object
in <0x0023a> System.String:FormatHelper (System.Text.StringBuilder result,
IFormatProvider provider, System.String format, System.Object[] args)
in <0x0002b> System.String:Format (IFormatProvider provider, System.String
format, System.Object[] args)
in <0x0000f> System.String:Format (System.String format, System.Object[] args)
in <0x00012> System.IO.TextWriter:Write (System.String format, System.Object[]
arg)
in <0x00014> System.IO.TextWriter:WriteLine (System.String format,
System.Object[] arg)
in <0x0002e> System.IO.SynchronizedWriter:WriteLine (System.String format,
System.Object[] value)
in <0x00018> System.Console:WriteLine (System.String format, System.Object[]
arg)
in <0x00044> Qyoto.SmokeInvocation:QStringListToArrayList (IntPtr ptr)
How is the 'char **' array terminated - does it expect a null entry at the
end?
I was going to add entries to the array one by one while iterating through the
QStringList and calling a method on C# side for each one, rather than do them
all at once.
-- Richard
More information about the Kde-bindings
mailing list