tagSOMETHING and API calls.

Hello Experts.
I need you again :)

A begginer in C++
As I told before... talking about Visual C++.

Well, I'm working on a personal project, the goal of this is to learn
to program in this language. Thats why I'm working without MFC at this
time.
I just created a "Typical Hello World" aplication... And I'm adding
things on it.

I try to call some Api funtions that receive struct parameters.
For example. CreateBrushIndirect(CONST LOGBRUSH *lplb).

LOGBRUSH is defined like this:
typedef struct tagLOGBRUSH { // lb
   UINT     lbStyle;
   COLORREF lbColor;
   LONG     lbHatch;
} LOGBRUSH;

Well... Here is the problem.
I try this code.

LOGBRUSH mBrush; (Tried also LOGBRUSH *Brush = new LOGBRUSH;)

First
Into the class, When I write "Brush." (I There was a member they should be shown at this moment
but they don't appear).

Well The point is this.
When I call the Api Funtion:

CreateBrushIndirect(Brush);
The compiler rejects the code telling:
error C2664: 'CreateBrushIndirect' : cannot convert parameter 1 from 'struct tagLOGBRUSH' to 'const struct tagLOGBRUSH *'

Would you tell me what do I have to do?... Is not the first Api That receive "tagSOMETHING" as
parameter, Ind I have the same problem with them.
Thanks

I'm sorry for not being more generous, but I really need to do more questions.
Thanks again.
LVL 1
MarscAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ZoppoConnect With a Mentor Commented:
Hi Marsc,

function is defined like this:

CreateBrushIndirect(
  CONST LOGBRUSH *lplb   // brush information
);

the parameter is a constant pointer to a struct LOGBRUSH instance, so you have to pass a pointer, i.e.:

------------------------------------------------
LOGBRUSH mBrush;
....
CreateBrushIndirect( &mBrush );
------------------------------------------------
or
------------------------------------------------
LOGBRUSH *pBrush;
....
CreateBrushIndirect( pBrush );
------------------------------------------------

hope that helps,

ZOPPO
0
 
MarscAuthor Commented:
I Forgor to tell...
I included the file <wingdi.h>
0
 
ZoppoCommented:
ehh, forgot to mention that in the second example you'll have to release the allocated memory for the LOGBRUSH object after creating the brush, i.e.:

------------------------------------------------
LOGBRUSH *pBrush;
.....
CreateBrushIndirect( pBrush );
delete pBrush; // free memory
------------------------------------------------

ZOPPO
0
 
MarscAuthor Commented:

0
 
MarscAuthor Commented:

0
All Courses

From novice to tech pro — start learning today.