473,387 Members | 1,897 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Again API call with structures error

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
');

Nov 20 '05 #1
1 1421
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
"NewAlias" <Ne******@NewDomain.com> wrote in message
news:Oi**************@TK2MSFTNGP10.phx.gbl...
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 ');

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

35
by: hasho | last post by:
Why is "call by address" faster than "call by value"?
3
by: melanieab | last post by:
Hi, I'm having trouble when I leave a tabpage to go on to the next. On Focus Leave, I take a snapshot of that tab. It usually turns out ok, but often, part of the next tabpage will appear in...
5
by: eBob.com | last post by:
I am trying to change some Structures to Classes. The Classes now look like this ... Public Class OneAttr Public AttrName As String Public Column As String Public Caption As String End Class...
4
by: zacks | last post by:
A common programming technique I use in VB is making a collection of structures. But if Option Strict is on (which I would prefer), the .Add that adds the structure to the collection is flagged...
1
by: Galen Somerville | last post by:
And yet another VB6 to VB2005 problem. All helpful suggestions appreciated. As you can see in the code below, my structures use fixed length strings and known array sizes. Consequently I can save...
4
by: Steve Richter | last post by:
I have a C++ forms project that I am adding some unmanaged code to. I have a member function of the Form1 class that returns a String^ holding the text of the last win32 error. The code is...
5
by: Envergure | last post by:
I wrote a function to find the point of intersection of a line and a plane in three-space. This function works fine and returns the correct result. However, when I call it using an element from...
2
by: r_ahimsa_m | last post by:
Hello, I am learning PHP5. I need to parse XML file and I found a solution in some book on PHP5 ("PHP5 Programming" by Rasmus Lerdors and others). Unfortunately I have two problems that I don't...
0
by: grndvl1 | last post by:
Here is what I have: I have a Structure, TM_Response that is 3 structures inside of it plus 3 other byte fields. One of the internal structures has a byte array of variable size. I am calling an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.