Again API call with structures error

N

NewAlias

I still can't make APIs with structures to work at first time in VB .NET
This is a required function to be called prior to use ScriptStringOut to
display unicode complex scripts

The famigerate message shows for the signaled line:
:: An unhandled exception of type 'System.NullReferenceException'
occurred in MyTest.exe
:: Additional information: Object reference not set to an instance of an
object.

With so many parameters I have no clue about which one is wrong

Thank for any help

' ****** THE FUNCTION DECLARATION ******
' the C proptotype is at the end of this message in SECTION 3
' ****** SECTION 1
Private Declare Unicode Function ScriptStringAnalyse Lib "usp10"
Alias "ScriptStringAnalyse" ( _
ByVal hdc As IntPtr, _
ByVal pString As String, _
ByVal cStringLen As Integer, _
ByVal cGlyphs As Integer, _
ByVal iCharset As Integer, _
ByVal dwFlags As tagSSA, _
ByVal iReqWidth As Integer, _
ByRef psControl As Integer, _
ByRef psState As Short, _
ByRef piDx() As Integer, _
ByVal pTabdef As SCRIPT_TABDEF, _
ByRef pbInClass As Byte, _
ByVal pssa As IntPtr) _
As Integer

' ******* PROGRAM FRAGMENT that works fine for TextOut(Hdc, 0, i *
lf.Height, Lines(i), Len(Lines(i)))
' ******* the line with error is signaled
' ******* see SECTION 2 for vb structure declaration and C bit structures
Dim ssa As IntPtr, R As RECT : R.Bottom = 2000 : R.Right = 2000
For i As Integer = 0 To UBound(Lines) ' lines is an array of
strings
Dim piDx(Len(Lines(i)) - 1) As Integer
Dim cGlyphs As Integer = Len(Lines(i)) * 1.5 + 16
Dim flags As tagSSA = tagSSA.BREAK Or tagSSA.FALLBACK Or
tagSSA.GLYPHS Or tagSSA.LINK
Dim pscontrol As Integer ' this should be equivalent to a 32
bit structure
Dim psstate As Short ' this should be equivalent to a 16 bit
structure
Dim tabdef As New SCRIPT_TABDEF ' see bellow
Dim pbInClass As Byte ' Pointer to a BYTE
Dim Txt As String = Lines(i)
---> ScriptStringAnalyse(Hdc, Txt, Len(Lines(i)), cGlyphs, -1,
flags, 2000, pscontrol, psstate, piDx, tabdef, pbInClass, ssa)
ScriptStringOut(ssa, 0, i * lf.Height, 0, R, 2, 0, False)
ScriptStringFree(ssa)
Next



' ******* SECTION 2

Private Structure SCRIPT_TABDEF
Dim cTabStops As Integer
Dim iScale As Integer
Dim pTabStops() As Integer
Dim iTabOrigin As Integer
End Structure

'typedef struct tag_SCRIPT_CONTROL { // psControl
' 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;

' typedef struct tag_SCRIPT_STATE { // psState
' 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;


' ******* SECTION 3

'HRESULT WINAPI ScriptStringAnalyse(
' HDC hdc,
' const void *pString,
' int cString,
' int cGlyphs,
' int iCharset,
' DWORD dwFlags,
' int iReqWidth,
' SCRIPT_CONTROL *psControl,
' SCRIPT_STATE *psState,
' const int *piDx,
' SCRIPT_TABDEF *pTabdef,
' const BYTE *pbInClass,
' SCRIPT_STRING_ANALYSIS *pssa // this is a pointer to an unknow structure
');
 
Y

yEaH rIgHt

Try replacing the ByVal With ByRef in your declaration for SCRIPT_TABDEF

ByRef pTabdef As SCRIPT_TABDEF


Declare Function ScriptStringAnalyse Lib "usp10.dll" _
(ByVal hdc As IntPtr, pString As Strin, ByVal cString As Integer, ByVal
cGlyphs As Integer, _
ByVal iCharset As Integer, ByVal dwFlags As Integer, ByVal iReqWidth As
Integer, _
ByRef psControl As SCRIPT_CONTROL, ByRef psState As SCRIPT_STATE, _
ByRef piDx As Integer, ByRef pTabdef As SCRIPT_TABDEF, ByVal pbInClass As
String, _
ByRef pssa As SCRIPT_STRING_ANALYSIS ) _
As Integer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top