Add examples/msvc client
authorSam Thursfield <samthursfield@codethink.co.uk>
Tue, 19 Jul 2011 10:29:35 +0000 (11:29 +0100)
committerSam Thursfield <samthursfield@codethink.co.uk>
Tue, 19 Jul 2011 10:29:35 +0000 (11:29 +0100)
examples/msvc/Makefile [new file with mode: 0644]
examples/msvc/README [new file with mode: 0644]
examples/msvc/msvc-example.c [new file with mode: 0644]

diff --git a/examples/msvc/Makefile b/examples/msvc/Makefile
new file mode 100644 (file)
index 0000000..b5635fa
--- /dev/null
@@ -0,0 +1,18 @@
+# Makefile for use with NMAKE
+
+# Base path of MSVC installation
+VC_PATH=c:\Program Files\Microsoft SDKs\Windows\v6.0\VC
+
+# Base path of Windows SDK installation
+SDK_PATH=c:\Program Files\Microsoft SDKs\Windows\v6.0
+
+CL=$(VC_PATH)\bin\cl.exe
+LINK=$(VC_PATH)\bin\link.exe
+
+all: msvc-example.exe
+
+msvc-example.obj: msvc-example.c
+       "$(CL)" msvc-example.c -c -I..\..\libmoonshot -I"$(VC_PATH)\INCLUDE" -F$@
+
+msvc-example.exe: msvc-example.obj
+       "$(LINK)" msvc-example.obj ..\..\libmoonshot\libmoonshot.lib -LIBPATH:"$(VC_PATH)\LIB" -LIBPATH:"$(SDK_PATH)\LIB" -OUT:$@
diff --git a/examples/msvc/README b/examples/msvc/README
new file mode 100644 (file)
index 0000000..93a807f
--- /dev/null
@@ -0,0 +1,17 @@
+msvc-example: demonstrates using libmoonshot-0.dll from Visual C
+
+You must edit the Makefile to set up the correct paths before this
+example will build.
+
+To run it, you must set the correct PATH for the required DLL's:
+libmoonshot-0.dll (which is in ../../libmoonshot/.libs/) and msrpc-mingw.dll
+(which is in [msrpc-mingw tree]/build/). You will need to execute something
+like the following:
+
+    (in sh.exe:)
+
+PATH=../../libmoonshot/.libs:/c/build/src/msrpc-mingw/build/:$PATH msvc-example
+
+    (or in cmd.exe:)
+
+PATH=..\..\libmoonshot\.libs;c:\build\src\msrpc-mingw\build\;%PATH% msvc-example
diff --git a/examples/msvc/msvc-example.c b/examples/msvc/msvc-example.c
new file mode 100644 (file)
index 0000000..12a62b8
--- /dev/null
@@ -0,0 +1,40 @@
+#include "libmoonshot.h"
+
+#include <stdio.h>
+
+int main (int argc, char *argv[])
+{
+    MoonshotError *error = NULL;
+    int            success;
+
+    char *nai,
+         *password,
+         *server_certificate_hash,
+         *ca_certificate,
+         *subject_name_constraint,
+         *subject_alt_name_constraint;
+
+    success = moonshot_get_default_identity (&nai,
+                                             &password,
+                                             &server_certificate_hash,
+                                             &ca_certificate,
+                                             &subject_name_constraint,
+                                             &subject_alt_name_constraint,
+                                             &error);
+
+    if (success) {
+        printf ("Got identity: %s %s\n", nai, password);
+
+        moonshot_free (nai);
+        moonshot_free (password);
+        moonshot_free (server_certificate_hash);
+        moonshot_free (ca_certificate);
+        moonshot_free (subject_name_constraint);
+        moonshot_free (subject_alt_name_constraint);
+
+        return 0;
+    }
+
+    printf ("FAIL: %s\n", error->message);
+    return 1;
+}