mirror of https://github.com/mono/CppSharp.git
3 changed files with 78 additions and 29 deletions
@ -1,28 +1,29 @@ |
|||||||
top_srcdir = ../.. |
top_srcdir = ../.. |
||||||
|
|
||||||
INTEROP_DLL = \
|
INTEROP_DLL = \
|
||||||
$(top_srcdir)/src/Mono.VisualC.Interop/bin/Debug/Mono.VisualC.Interop.dll |
$(top_srcdir)/bin/Debug/Mono.Cxxi.dll |
||||||
|
|
||||||
all: hello.exe |
all: hello.exe |
||||||
|
|
||||||
qt-gui.xml: qt-gui.h |
qt-gui.xml: qt-gui.h |
||||||
gccxml -fxml=$@ --gccxml-cxxflags "`pkg-config --cflags QtCore QtGui`" qt-gui.h |
$(GCCXML) -fxml=$@ --gccxml-cxxflags "`pkg-config --cflags QtCore QtGui`" qt-gui.h |
||||||
|
|
||||||
generated: qt-gui.xml |
generated: qt-gui.xml |
||||||
$(RM) -r generated |
$(RM) -r generated |
||||||
mono --debug $(top_srcdir)/src/generator/bin/Debug/generator.exe -o=generated -ns=Qt.Gui -lib=QtGui --filters=qt-gui-filters.txt qt-gui.xml |
$(MONO) --debug $(top_srcdir)/bin/Debug/generator.exe -o=generated -ns=Qt.Gui -lib=QtGui --filters=qt-gui-filters.txt qt-gui.xml |
||||||
|
|
||||||
libQtGui-inline.so: qt-gui.cpp |
#libQtGui-inline.so: qt-gui.cpp
|
||||||
g++ `pkg-config --cflags QtCore QtGui` --shared -fPIC -o $@ -fkeep-inline-functions qt-gui.cpp `pkg-config --libs QtCore QtGui` |
# $(CXX) `pkg-config --cflags QtCore QtGui` --shared -fPIC -o $@ -fkeep-inline-functions qt-gui.cpp `pkg-config --libs QtCore QtGui`
|
||||||
|
|
||||||
Qt.Gui-binding.dll: generated |
Qt.Gui-binding.dll: generated QString.cs |
||||||
$(GMCS) -out:$@ -target:library -unsafe -r:$(INTEROP_DLL) generated/*.cs |
rm generated/QString.cs |
||||||
|
$(GMCS) -out:$@ -target:library -unsafe -r:$(INTEROP_DLL) generated/*.cs QString.cs |
||||||
|
|
||||||
hello.exe: Qt.Gui-binding.dll hello.cs libQtGui-inline.so |
hello.exe: Qt.Gui-binding.dll hello.cs #libQtGui-inline.so
|
||||||
$(GMCS) -out:$@ -target:exe -r:$(INTEROP_DLL) -r:Qt.Gui-binding.dll hello.cs |
$(GMCS) -out:$@ -target:exe -r:$(INTEROP_DLL) -r:Qt.Gui-binding.dll hello.cs |
||||||
|
|
||||||
clean: |
clean: |
||||||
$(RM) -rf generated hello.exe qt-gui.xml Qt.Gui-binding.dll libQtGui-inline.so |
$(RM) -rf generated hello.exe qt-gui.xml Qt.Gui-binding.dll libQtGui-inline.so |
||||||
|
|
||||||
run: hello.exe |
run: hello.exe |
||||||
MONO_PATH=$(top_srcdir)/src/Mono.VisualC.Interop/bin/Debug mono hello.exe |
MONO_PATH=$(top_srcdir)/bin/Debug $(MONO) hello.exe |
||||||
|
@ -0,0 +1,66 @@ |
|||||||
|
using System; |
||||||
|
using System.Text; |
||||||
|
using System.Runtime.InteropServices; |
||||||
|
|
||||||
|
using Mono.Cxxi; |
||||||
|
|
||||||
|
namespace Qt.Gui { |
||||||
|
//TODO: Will this leak?
|
||||||
|
[StructLayout (LayoutKind.Sequential)] |
||||||
|
public unsafe struct QString { |
||||||
|
#region Sync with qstring.h
|
||||||
|
public interface IQString : ICppClass { |
||||||
|
[Constructor] void QString(ref QString @this, [MangleAs ("const QChar*")] IntPtr unicode, int size); |
||||||
|
} |
||||||
|
|
||||||
|
[StructLayout (LayoutKind.Sequential)] |
||||||
|
public struct Data { |
||||||
|
public int @ref; |
||||||
|
public int alloc, size; |
||||||
|
public IntPtr data; |
||||||
|
public ushort clean; |
||||||
|
public ushort simpletext; |
||||||
|
public ushort righttoleft; |
||||||
|
public ushort asciiCache; |
||||||
|
public ushort capacity; |
||||||
|
public ushort reserved; |
||||||
|
public IntPtr array; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public Data* d; |
||||||
|
#endregion
|
||||||
|
|
||||||
|
private static IQString impl = Libs.QtGui.GetClass<IQString> ("QString"); |
||||||
|
|
||||||
|
public QString (string str) : this () |
||||||
|
{ |
||||||
|
var strPtr = Marshal.StringToHGlobalUni (str); |
||||||
|
impl.QString (ref this, strPtr, str.Length); |
||||||
|
Marshal.FreeHGlobal (strPtr); |
||||||
|
|
||||||
|
// TODO: I deref this on construction to let Qt free it when it's done with it.
|
||||||
|
// My assumption is that this struct will only be used to interop with Qt and
|
||||||
|
// no managed class is going to hold on to it.
|
||||||
|
this.DeRef (); |
||||||
|
} |
||||||
|
|
||||||
|
public static implicit operator QString (string str) |
||||||
|
{ |
||||||
|
return new QString (str); |
||||||
|
} |
||||||
|
|
||||||
|
public QString AddRef () |
||||||
|
{ |
||||||
|
d->@ref++; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public QString DeRef () |
||||||
|
{ |
||||||
|
d->@ref--; |
||||||
|
return this; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
Loading…
Reference in new issue