Quantcast

C# and the Compact Framework (windows mobile)

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

C# and the Compact Framework (windows mobile)

John Gray-4
I've been using swig to talk to some c libraries from a c# .net app I've
written for Windows Mobile.  Windows Mobile uses the Compact Framework
(CF), a reduced version of the .net framework.

To the best of my knowledge swig doesn't actually support this straight
out of the box.  I wrote a shell script to message the output of swig to
get it to compile for the CF.  I'm happy to share the script, but there
are some caveats.

One the things that script does is disable the SWIGStringHelper.
Otherwise things go boom.  The end result is an inability for the c code
to return strings to c# code.  Which is quite a bummer.  I have strings
going from c# to c (though this requires some wide to ascii conversion,
which make script wedges into the wrapper).

The reason I had to disable the SWIGStringHelper is because it throws an
unsupported exception.  Anybody know how to message the SWIGStringHelper
so it'll work correctly on the CF?

Thanks,
John


------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: C# and the Compact Framework (windows mobile)

David Piepgrass
> I've been using swig to talk to some c libraries from a c# .net app I've

> written for Windows Mobile.  Windows Mobile uses the Compact Framework
> (CF), a reduced version of the .net framework.
>
> To the best of my knowledge swig doesn't actually support this straight
> out of the box.  I wrote a shell script to message the output of swig to
> get it to compile for the CF.  I'm happy to share the script, but there
> are some caveats.
>
> One the things that script does is disable the SWIGStringHelper.
> Otherwise things go boom.  The end result is an inability for the c code
> to return strings to c# code.  Which is quite a bummer.  I have strings
> going from c# to c (though this requires some wide to ascii conversion,
> which make script wedges into the wrapper).
>
> The reason I had to disable the SWIGStringHelper is because it throws an
> unsupported exception.  Anybody know how to message the SWIGStringHelper
> so it'll work correctly on the CF?
I have been working on a Compact Framework-compatible version of SWIG for some time now, though I have been distracted with other things enough that I haven't made a formal patch yet. My version is based on SWIG 1.3.36 or so and it doesn't use string helpers (SWIGStringHelper, SWIGWStringHelper). Note that single-byte character strings cannot be passed on .NET CF.

I'm surprised you didn't mention HandleRef as a problem. The regular SWIG distribution relies on HandleRef, but Compact Framework still doesn't have HandleRef, according to MSDN.

I have attached a file (change its extension to .zip) with which you should be able to use SWIG under Compact Framework.

The following files replace existing files in Lib\csharp in the SWIG distribution:

boost_shared_ptr.i
csharp.swg
csharphead.swg
wchar.i

In addition, the following file contains improved typemaps for single-character C strings, wide C strings, std::string and std::wstring; you need to %include it near the top of your main .i file:

cs_custom_strings.i

Let me know if you have questions/problems.

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user

SwigDotNetCF.zi_ (22K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: C# and the Compact Framework (windows mobile)

David Piepgrass
> I have attached a file (change its extension to .zip) with which you
> should be able to use SWIG under Compact Framework.

I forgot to mention, you need to pass the following command line argument to SWIG in order to get Compact Framework-compatible wrappers:

-DCOMPACT_FRAMEWORK_COMPATIBLE

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: C# and the Compact Framework (windows mobile)

John Gray-4
In reply to this post by David Piepgrass
David Piepgrass wrote:

>> I've been using swig to talk to some c libraries from a c# .net app I've
>> written for Windows Mobile.  Windows Mobile uses the Compact Framework
>> (CF), a reduced version of the .net framework.
>>
>> To the best of my knowledge swig doesn't actually support this straight
>> out of the box.  I wrote a shell script to message the output of swig to
>> get it to compile for the CF.  I'm happy to share the script, but there
>> are some caveats.
>>
>> One the things that script does is disable the SWIGStringHelper.
>> Otherwise things go boom.  The end result is an inability for the c code
>> to return strings to c# code.  Which is quite a bummer.  I have strings
>> going from c# to c (though this requires some wide to ascii conversion,
>> which make script wedges into the wrapper).
>>
>> The reason I had to disable the SWIGStringHelper is because it throws an
>> unsupported exception.  Anybody know how to message the SWIGStringHelper
>> so it'll work correctly on the CF?
>
> I have been working on a Compact Framework-compatible version of SWIG for some time now, though I have been distracted with other things enough that I haven't made a formal patch yet. My version is based on SWIG 1.3.36 or so and it doesn't use string helpers (SWIGStringHelper, SWIGWStringHelper). Note that single-byte character strings cannot be passed on .NET CF.
>
> I'm surprised you didn't mention HandleRef as a problem. The regular SWIG distribution relies on HandleRef, but Compact Framework still doesn't have HandleRef, according to MSDN.
>
> I have attached a file (change its extension to .zip) with which you should be able to use SWIG under Compact Framework.
>
> The following files replace existing files in Lib\csharp in the SWIG distribution:
>
> boost_shared_ptr.i
> csharp.swg
> csharphead.swg
> wchar.i
>
> In addition, the following file contains improved typemaps for single-character C strings, wide C strings, std::string and std::wstring; you need to %include it near the top of your main .i file:
>
> cs_custom_strings.i
>
> Let me know if you have questions/problems.

Thanks David.  This certainly gets me closer.  I dropped your files
1.3.38.  I'm seeing an issue with SysStringLen returning the wrong length.

Yes, I'm aware of lack of HandleRef support the CF.  That was fairly
easily solved.  Its the strings that are killing me.

If there's anything I can do to help it along, please let me know.

It would be really nice to get this integrated into the latest version,
and into the dist.

John

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: C# and the Compact Framework (windows mobile)

David Piepgrass
> Thanks David.  This certainly gets me closer.  I dropped your files
> 1.3.38.  I'm seeing an issue with SysStringLen returning the wrong length.

Can you explain what exactly is happening? I haven't run into problems yet, but I have not tested all the typemaps on .NET CF (I have tested most of them on the desktop.)

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: C# and the Compact Framework (windows mobile)

John Gray-4
Well, I believe the strings coming in from C# aren't truly BSTR's (on
the CF).  I believe they are really wchar_t arrays.  I replaced the call
to SysStringLen with a call to wcslen.  That works just fine.

It appears as though the marshaling in the CF is more limited. By
default on c# strings would be marshalled as a BSTR.  But I don't think
the CF is doing so.  I'm doing some reading between the lines here, but
I'm fairly sure on the CF, we just get an immutable array of wchar_t's.

That's with the latest rev of the 2.0 compact framework on a Windows
Mobile 6.1 device.

John

David Piepgrass wrote:
>> Thanks David.  This certainly gets me closer.  I dropped your files
>> 1.3.38.  I'm seeing an issue with SysStringLen returning the wrong length.
>
> Can you explain what exactly is happening? I haven't run into problems yet, but I have not tested all the typemaps on .NET CF (I have tested most of them on the desktop.)
>

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: C# and the Compact Framework (windows mobile)

abu.noman
This post has NOT been accepted by the mailing list yet.
In reply to this post by John Gray-4
Dear David Piepgrass,

I am trying to build pjsip for windows phone 8.1 using swig. I can build dll for win32 but can't build for compact framework. If I change into csharp.swg as follows:
#if !defined(USE_INTPTR) && !defined(COMPACT_FRAMEWORK_COMPATIBLE)
  #define SWIG_HANDLEREF HandleRef
  #define NEW_HANDLEREF(proxy, ptr) new HandleRef(proxy, ptr)
  #define NULL_HANDLEREF new HandleRef(null, IntPtr.Zero)
#else
  #define SWIG_HANDLEREF IntPtr
  #define NEW_HANDLEREF(proxy, ptr) ptr
  #define NULL_HANDLEREF IntPtr.Zero
#endif

and add cs_custom_strings.i (provided by you) file in swigwin-3.0.2\Lib\csharp and %include this file in my main .i files then it successfully build a dll but main problem is, it generate *.cs files that contains SafeHandle(null, IntPtr.Zero) which is not valid. So, please give me step by step procedure to build the sip stack into dll because I am novice in windows programming.

Thanks,
Abu Noman
Loading...