Reputation: 713
I'm using DrawText
to draw some text to a bunch of rectangles I made in a plug-in.
Now i'm receiving a char pointer from embedded python:
char *a=PyString_AsString(value);
which, when I print to textfile gives: 1\n2\n3\n4\n5\n6\n7\n8\n9\n
(this is just a sample character, the one I'm going to use is much more complex)
I want to use DrawText
to print specific characters in a loop:
for(int count=0;count<content.size();count++){
dc->DrawText(a[count*2],&rect[count],DT_CENTER); //*2 to print only the numbers
but i can't because it says that argument is not of type char?? I can pass a
, &a[count]
but not a[count]
. Why is this?
Also, when i print &a[2]
to textfile it gives: 2\n3\n4\n5\n6\n7\n8\n9\n
. Shouldn't it be only 2
?
Note: DrawText function receives:
int DrawText(
_In_ HDC hDC,
_Inout_ LPCTSTR lpchText,
_In_ int nCount,
_Inout_ LPRECT lpRect,
_In_ UINT uFormat
);
Upvotes: 0
Views: 207
Reputation: 612993
The first parameter of your DrawText
method is a char*
pointer. You are passing a single char
instead, which is the type mismatch that the compiler is complaining about.
You can obtain a pointer to a specific character like this:
&a[count*2]
or like this:
a + count*2
The problem is that your three parameter OOP wrapper of DrawText
has removed the nCount
parameter of the Win32 DrawText
function. Instead your wrapper is passing -1
which means that the character pointer is interpreted as a null-terminated string. The function will print all the characters until it reaches the null-terminator.
If you want to print a single character then you would need to pass 1
through the nCount
parameter. There's no way for you to do that with your wrapper. You'd have to do this:
char temp[2];
temp[1] = 0;
temp[0] = a[count*2];
dc->DrawText(temp, ...);
In order to avoid this temporary buffer you would need to expose the nCount
parameter of the raw Win32 API function.
Upvotes: 3