Problem with standard data types

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with standard data types

Jared Mark

I’m fairly new to swig, so I’m sorry if this question is answered in the documentation.  It’s quite a large learning curve.

 

I’m using SWIG to wrap C++ in to C#.  I’m having a problem with numerous functions that take regular data types as arguments.

 

This function, for example:

 

C++

      bool  injectKeyDown(uint key_code);

 

When it’s wrapped, this is the resulting code:

 

  [DllImport("CeguiBindings", EntryPoint="CSharp_GuiSystem_InjectKeyDown")]

  public static extern bool GuiSystem_InjectKeyDown(HandleRef jarg1, HandleRef jarg2);

 

The first argument, as I understand it, is the necessary HandleRef for keeping the GC from cleaning stuff up.  The second argument SHOULD be that UINT, but for some reason it’s using another HandleRef.

 

I don’t have this problem when using custom data types.  Here’s an example of a function that is working:

 

C++

      bool  injectMouseButtonUp(MouseButton button);

 

“MouseButton” is an enum (right, left, etc…)

 

The wrapped code for this one is like this:

 

  [DllImport("CeguiBindings", EntryPoint="CSharp_GuiSystem_InjectMouseButtonUp")]

  public static extern bool GuiSystem_InjectMouseButtonUp(HandleRef jarg1, int jarg2);

 

As you can see, the first argument is a HandleRef… no problem.  The SECOND argument is the value of the enum, and is being passed in as an INT.

 

Why is SWIG not doing this for the first example?  Do I need to write some sort of custom .i code for these functions to cause swig to take that uint value properly?

 

 

Jared Mark

Lead Developer: Vermund ( http://vermund.eeisi.com )

League Administrator: The Ladders Gaming League ( http://www.the-ladders.com/ )

 

 

Reply | Threaded
Open this post in threaded view
|

Re: Problem with standard data types

William S Fulton
Jared Mark wrote:

> I’m fairly new to swig, so I’m sorry if this question is answered in the
> documentation.  It’s quite a large learning curve.
>
>  
>
> I’m using SWIG to wrap C++ in to C#.  I’m having a problem with numerous
> functions that take regular data types as arguments.
>
>  
>
> This function, for example:
>
>  
>
> C++
>
>       bool  injectKeyDown(uint key_code);
>
>  
>
> When it’s wrapped, this is the resulting code:
>
>  
>
>   [DllImport("CeguiBindings", EntryPoint="CSharp_GuiSystem_InjectKeyDown")]
>
>   public static extern bool GuiSystem_InjectKeyDown(HandleRef jarg1,
> HandleRef jarg2);
>
>  
>
> The first argument, as I understand it, is the necessary HandleRef for
> keeping the GC from cleaning stuff up.  The second argument SHOULD be
> that UINT, but for some reason it’s using another HandleRef.
>
>  
>
> I don’t have this problem when using custom data types.  Here’s an
> example of a function that is working:
>
>  
>
> C++
>
>       bool  injectMouseButtonUp(MouseButton button);
>
>  
>
> “MouseButton” is an enum (right, left, etc…)
>
>  
>
> The wrapped code for this one is like this:
>
>  
>
>   [DllImport("CeguiBindings",
> EntryPoint="CSharp_GuiSystem_InjectMouseButtonUp")]
>
>   public static extern bool GuiSystem_InjectMouseButtonUp(HandleRef
> jarg1, int jarg2);
>
>  
>
> As you can see, the first argument is a HandleRef… no problem.  The
> SECOND argument is the value of the enum, and is being passed in as an INT.
>
>  
>
> Why is SWIG not doing this for the first example?  Do I need to write
> some sort of custom .i code for these functions to cause swig to take
> that uint value properly?
>
>  
>

You havn't given SWIG all the type information. SWIG has no idea what a
uint is unless you tell it, just like a C compiler. However, unlike a C
compiler which absolutely requires full type information for every type,
SWIG will wrap any unknown type as a pointer. That will explain the
wrapping you see. Just get SWIG to parse the typedef for uint and you'll
get what you want. There is a lot to read, but it is all documented.

William


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user