Dear All,
I have a two questions about interoperating with unmanaged code. I'm trying
to call a function from a DLL file called usp.dll which contains Uniscribe
functions from C#. I'm calling a function called ScriptItemize which is
defined with its structures as follows:
HRESULT WINAPI ScriptItemize(
const WCHAR *pwcInChars,
int cInChars,
int cMaxItems,
const SCRIPT_CONTROL *psControl,
const SCRIPT_STATE *psState,
SCRIPT_ITEM *pItems,
int *pcItems
);
typedef struct tag_SCRIPT_STATE {
WORD uBidiLevel :5;
WORD fOverrideDirection :1;
WORD fInhibitSymSwap :1;
WORD fCharShape :1;
WORD fDigitSubstitute :1;
WORD fInhibitLigate :1;
WORD fDisplayZWG :1;
WORD fArabicNumContext :1;
WORD fGcpClusters :1;
WORD fReserved :1;
WORD fEngineReserved :2;
} SCRIPT_STATE;
typedef struct tag_SCRIPT_ANALYSIS {
WORD eScript :10;
WORD fRTL :1;
WORD fLayoutRTL :1;
WORD fLinkBefore :1;
WORD fLinkAfter :1;
WORD fLogicalOrder :1;
WORD fNoGlyphIndex :1;
SCRIPT_STATE s ;
} SCRIPT_ANALYSIS;
typedef struct tag_SCRIPT_ITEM {
int iCharPos;
SCRIPT_ANALYSIS a;
} SCRIPT_ITEM;
typedef struct tag_SCRIPT_CONTROL {
DWORD uDefaultLanguage :16;
DWORD fContextDigits :1;
DWORD fInvertPreBoundDir :1;
DWORD fInvertPostBoundDir :1;
DWORD fLinkStringBefore :1;
DWORD fLinkStringAfter :1;
DWORD fNeutralOverride :1;
DWORD fNumericOverride :1;
DWORD fLegacyBidiClass :1;
DWORD fReserved :8;
} SCRIPT_CONTROL;
I defined it is C# as follows
[DllImport("usp10.dll", EntryPoint = "ScriptItemize", CharSet =
CharSet.Unicode,
ExactSpelling = true)]
public static extern int ScriptItemize(
string pwcInChars,
int cInChars,
int cMaxItems,
ref SCRIPT_CONTROL psControls,
ref SCRIPT_STATE psState,
ref SCRIPT_ITEM pItems,
out int pcItems
);
public struct SCRIPT_STATE
{
public short uBidiLevel;
public short fOverrideDirection;
public short fInhibitSymSwap;
public short fCharShape;
public short fDigitSubstitute;
public short fInhibitLigate;
public short fDisplayZWG;
public short fArabicNumContext;
public short fGcpClusters;
public short fReserved;
public short fEngineReserved;
}
public struct SCRIPT_ANALYSIS
{
public short eScript;
public short fRTL;
public short fLayoutRTL;
public short fLinkBefore;
public short fLinkAfter;
public short fLogicalOrder;
public short fNoGlyphIndex;
public SCRIPT_STATE s;
}
public struct SCRIPT_ITEM
{
public int iCharPos;
public SCRIPT_ANALYSIS a;
}
public struct SCRIPT_CONTROL
{
public int uDefaultLanguage;
public int fContextDigits;
public int fInvertPreBoundDir;
public int fInvertPostBoundDir;
public int fLinkStringBefore;
public int fLinkStringAfter;
public int fNeutralOverride;
public int fNumericOverride;
public int fLegacyBidiClass;
public int fReserved;
}
Now I have two problems:
1- The function may accept a null values in the parameters psControls and
psState. I don't know how to pass null value in the function call??
2- The function should fill the pItems array with values but when I call it,
it fills only the first item in the array and leaves the other items with
their default values. I'm using the following code to call the function. Am
I missing something in my code ??
string DisplayText = "Some text here";
char[] DisplayCharacters = DisplayText.ToCharArray();
Uniscribe.SCRIPT_CONTROL defaultControl = new Uniscribe.SCRIPT_CONTROL();
Uniscribe.SCRIPT_STATE defaultState = new Uniscribe.SCRIPT_STATE();
Uniscribe.SCRIPT_ITEM[] resultItems = new Uniscribe.SCRIPT_ITEM[10];
int resultItemNumbers;
int FunctionReturnValue;
FunctionReturnValue = ScriptItemize(DisplayText, DisplayText.Length,
resultItems.Length, ref defaultControl, ref defaultState, ref
resultItems[0], out resultItemNumbers);
the resultItemNumbers should return the number of array items in resultItems
but whatever this number is, only the first item is filled with values. What
is missing or wrong in my code?
Sorry if I have so long question.
Please, help.
Ehab Zaky - 27 Nov 2004 13:21 GMT
Dear All,
I'm sorry if I couldn't express my questions well.
This is my questions simplified:
1- How to pass structures that contains another structures from C# to C++
functions where C++ function should fill this structure ??
2- How to use functions that can accepts values and nulls as one of its
parameters.
Thanks
Yours,
Ehab Zaky
> Dear All,
>
[quoted text clipped - 147 lines]
> Sorry if I have so long question.
> Please, help.
kurnikov - 04 Jul 2007 12:56 GMT
I try to solve this problems
can you contact me via msn: it.proster@hotmail.com
or via e-mail: igor.kurnikov@gmail.com
?
>Dear All,
>
[quoted text clipped - 18 lines]
>> Sorry if I have so long question.
>> Please, help.