Is there an easy way to marshal to unicode instead of ansi in generated code? #204
-
This header function: Produces this code:
But I'm getting an error code returned when trying to call the function. The documentation states:
So I'm wondering if Marshal.StringToHGlobalAnsi is causing me problems, and if there is a straightforward way to have the generated code use Marshal.StringToHGlobalUni instead? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
It appears either SharpGenTools/SharpGenTools.Sdk/Sdk.targets Lines 85 to 87 in 3f1c00c |
Beta Was this translation helpful? Give feedback.
-
Looks like I mis-remembered. There is a way to do this though with an include prolog.
In your `include` tag for your header, you can add a `pre` element that includes some C++ before the header is included, like so:
```
<include file="Foo.h" attach="true">
<pre>
#define UNICODE 1
</pre>
</include>
```
…________________________________
From: Kevin Gallahan ***@***.***>
Sent: Saturday, June 19, 2021 7:59:46 AM
To: SharpGenTools/SharpGenTools ***@***.***>
Cc: Jeremy Koritzinsky ***@***.***>; Mention ***@***.***>
Subject: Re: [SharpGenTools/SharpGenTools] Is there an easy way to marshal to unicode instead of ansi in generated code? (#204)
@jkoritzinsky<https://github.com/jkoritzinsky> What is the syntax for that? Can't quite figure it out from the docs<https://sharpgentools.readthedocs.io/en/latest/custom-mapping.html>. Keep in mind I'm not a cpp user and am a novice with SharpGenTools.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#204 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAL7UUEG6QIARVDBOUKRL3TTTSWGFANCNFSM466SQP7Q>.
|
Beta Was this translation helpful? Give feedback.
It appears either
_UNICODE
orUNICODE
preprocessor definitions are not set when parsingCrTypes.h
, soCrChar
isCrAChar
(char
). SharpGen does the correct thing by assuming it's ANSI, not Unicode. I'm not sure ifUNICODE
not being defined is SharpGen's fault, but you can try adding that preprocessor definition like this:SharpGenTools/SharpGenTools.Sdk/Sdk.targets
Lines 85 to 87 in 3f1c00c