Quantcast

C++ _TCHAR to C# string

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

C++ _TCHAR to C# string

petergabriel
Hi,

I am trying to use SWIG to generate a C# dll from some C++  6 code.

I have managed to get it working where the input/output parameters are int, double or bool, but I'm stuck with how to get it to convert a C++ _TCHAR to a string in C#.

Where the C++ code uses _TCHARs as the parameter types, no matter what I've tried in the SWIG interface file, the C# parameters for any methods which should take a string are coming up as SWIGTYPE_p__TCHAR, which is as far as I can tell is what SWIG produces when it doesn't know what it should use.

I'm sure that this should be a case of using the right typemap in the SWIG interface file, but nothing I've tried so far has worked, any suggestions would be much appreciated!

Cheers,
Peter
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: C++ _TCHAR to C# string

David Piepgrass-2
> I have managed to get it working where the input/output parameters are int,
> double or bool, but I'm stuck with how to get it to convert a C++ _TCHAR to a
> string in C#.
>
> Where the C++ code uses _TCHARs as the parameter types, no matter what
> I've tried in the SWIG interface file, the C# parameters for any methods
> which should take a string are coming up as SWIGTYPE_p__TCHAR, which is
> as far as I can tell is what SWIG produces when it doesn't know what it should
> use.

It's no surprise that SWIG doesn't understand "_TCHAR"--I'm a Windows dev and have never seen TCHAR with an underscore before. In any case the solution is easy, you just tell SWIG what _TCHAR means, near the top of your interface file (before any code that uses it), typically with a typedef:

typedef wchar_t _TCHAR;

Remember that SWIG ignores #include directives.
DISCLAIMER: This email may contain confidential and/or privileged information and any rights to confidentiality and/or privilege have not been waived. Please notify us immediately if you have received this message in error.

------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
_______________________________________________
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++ _TCHAR to C# string

petergabriel
In the end, the maintainer of the C++ code changed his code to use standard chars instead of _TCHARs and I have managed to get this working.

Thank you for your help.
Loading...