widl: Handle LPSTR in typelibs

Dan Hipschman dsh at linux.ucla.edu
Mon Aug 27 22:24:37 CDT 2007


Hello.

This patch adds the ability to handle [string] attributes in typelib files.
Without this, widl gets confused:

$ cat foo.idl
typedef [string] char *str_t;
[
  uuid (00000000-0000-0000-0000-000000001111)
]
library LibFoo
{
  [
    uuid (00000000-0000-0000-0000-000000001112)
  ]
  interface IFoo
  {
    void f (str_t s);
  }
}

$ widl -t foo.idl
error: encode_type: VT_USERDEFINED - unhandled type 17

If you just use [string] in the parameter list (without the typedef), widl
doesn't die, but it silently discards the attribute.  MIDL turns this into
LPSTR, which is what this patch does for widl.  In fact, in the small test
case above, MIDL and widl generate the exact same typelib (besides the
timestamp).  This fixes one error that arrises in compiling bits.idl in the
windows SDK.

---
 tools/widl/typelib.c    |   12 ++++++++++--
 tools/widl/write_msft.c |    7 +++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/tools/widl/typelib.c b/tools/widl/typelib.c
index 608a114..0238dc2 100644
--- a/tools/widl/typelib.c
+++ b/tools/widl/typelib.c
@@ -126,8 +126,9 @@ static int kw_cmp_func(const void *s1, const void *s2)
         return strcmp(KWP(s1)->kw, KWP(s2)->kw);
 }
 
-static unsigned short builtin_vt(const char *kw)
+static unsigned short builtin_vt(const type_t *t)
 {
+  const char *kw = t->name;
   struct oatype key, *kwp;
   key.kw = kw;
 #ifdef KW_BSEARCH
@@ -145,6 +146,13 @@ static unsigned short builtin_vt(const char *kw)
   if (kwp) {
     return kwp->vt;
   }
+  if (is_string_type (t->attrs, t))
+    switch (t->ref->type)
+      {
+      case RPC_FC_CHAR: return VT_LPSTR;
+      case RPC_FC_WCHAR: return VT_LPWSTR;
+      default: break;
+      }
   return 0;
 }
 
@@ -160,7 +168,7 @@ unsigned short get_type_vt(type_t *t)
 
   chat("get_type_vt: %p type->name %s\n", t, t->name);
   if (t->name) {
-    vt = builtin_vt(t->name);
+    vt = builtin_vt(t);
     if (vt) return vt;
   }
 
diff --git a/tools/widl/write_msft.c b/tools/widl/write_msft.c
index 920ca2b..dd29c73 100644
--- a/tools/widl/write_msft.c
+++ b/tools/widl/write_msft.c
@@ -852,6 +852,13 @@ static int encode_type(
         *encoded_type = default_type;
         break;
 
+    case VT_LPSTR:
+    case VT_LPWSTR:
+        *encoded_type = 0xfffe0000 | vt;
+        *width = 4;
+        *alignment = 4;
+        break;
+
     case VT_PTR:
       {
         int next_vt;



More information about the wine-patches mailing list