How to measure strings???

G

Gianco

Hello

I'm using C# .NET CF and currently developing a graph control. For
speed reasons I prefere to manipulate directly the DCs, bitmaps and so
on.

My question is

how can I obtain the heigth and the width of the strings using the
coredll?

I'm trying to use the function GetTextExtentPoint32 but this causes a
'not supported' exception. Is this function supported?

The function is declare so:
[System.Runtime.InteropServices.DllImport("coredll.dll")]
private static extern int GetTextExtentPoint(IntPtr DC, String Str,
int Len, out SIZE Size);

How can I have the list of functions contained in the coredll? The OS
is CE 4.0

Thanks for the interest

Gianco
 
P

Paul G. Tobey [eMVP]

The best way to get the documentation for the native code API is to install
eMbedded Visual C++ 4.0 and the Pocket PC (or whatever device you are using)
SDK.

The reason for your particular problem is that there actually is no
GetTextExtentPoint exported from the DLL (this has to do with distinguishing
the API functions which take ASCII strings and which take Unicode strings.
So, if you want to call GetTextExtentPoint(), you actually have to call
GetTextExtentPointW(), indicating that you are passing a Unicode-based
string.

I think that correcting this problem will give you working code...

Paul T.
 
G

Gianco

Thanks for your reply Paul

I tried to use the GetTextExtentPointW but I obtain the same error
message

Probably (or better, surely) I made a mistake but I don't understand
which is. I have no problems with the other GDI functions, I can use
also the ExtTextOut

This is the declaration:

[DllImport("coredll.dll")]
private static extern int GetTextExtentPointW(IntPtr DC, string Str,
int Len, out SIZE size);

And where I use the function:

.....
SIZE Size;
String sValue;
.....

.....
sValue = dXScales.ToString();
GetTextExtentPointW(m_MemoryDC, sValue, sValue.Length, out Size);
......

Error message:
An unhandled exception of type 'System.MissingMethodException'
occurred in Test.exe

Which is the my error?

Regards
Gianco

Paul G. Tobey said:
The best way to get the documentation for the native code API is to install
eMbedded Visual C++ 4.0 and the Pocket PC (or whatever device you are using)
SDK.

The reason for your particular problem is that there actually is no
GetTextExtentPoint exported from the DLL (this has to do with distinguishing
the API functions which take ASCII strings and which take Unicode strings.
So, if you want to call GetTextExtentPoint(), you actually have to call
GetTextExtentPointW(), indicating that you are passing a Unicode-based
string.

I think that correcting this problem will give you working code...

Paul T.

Gianco said:
Hello

I'm using C# .NET CF and currently developing a graph control. For
speed reasons I prefere to manipulate directly the DCs, bitmaps and so
on.

My question is

how can I obtain the heigth and the width of the strings using the
coredll?

I'm trying to use the function GetTextExtentPoint32 but this causes a
'not supported' exception. Is this function supported?

The function is declare so:
[System.Runtime.InteropServices.DllImport("coredll.dll")]
private static extern int GetTextExtentPoint(IntPtr DC, String Str,
int Len, out SIZE Size);

How can I have the list of functions contained in the coredll? The OS
is CE 4.0

Thanks for the interest

Gianco
 
D

Dan Elliott [MSFT]

Gianco,

Declare the last parameter (size) as 'ref' rather than 'out'. 'out' means
that the called function should allocate the memory; 'ref' means that the
calling function has already allocated the memory.

BTW, CE 4.2 exports GetTextExtentExPointW.
^^
Here is an article on using dumpbin.exe as an aid when declaring P/Invokes:
http://smartdevices.microsoftdev.com/Learn/Articles/514.aspx

HTH,
Dan

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Gianco

Many thanks Dan, now my problem is solved with GetTextExtentExPointW!

Regards
Gianco
 

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