T
Timo
I am trying to pass a pointer to an array of structures to function,
but
I have some problems. I am using MS Visual C++ 6.0, but I think
this is more of a C-problem than Windows programming specific. Here
is the relevant part of my code.
typedef struct
{
int iControlID;
char controlTxt[64];
} CONTROL_TXT;
void SetControlTxts(HWND hDlg, CONTROL_TXT *ctrlTxt[]);
void MyFunc(void)
{
static CONTROL_TXT ctrlTxts[] =
{
{ 1, "text 1" },
{ 2, "text 2" },
{ 3, "text 3" },
{ 0, "" } // marks end of table
};
<clip>
SetControlTxts(hDlg, &ctrlTxts[0]);
}
void SetControlTxts(HWND hDlg, CONTROL_TXT *ctrlTxt[])
{
int i, id;
char txt[64];
for (i = 0; &ctrlTxt->iControlID != 0; i++)
{
id = &ctrlTxt->iControlID;
strcpy(txt, &ctrlTxt->controlTxt);
//strcpy(txt, (char*)ctrlTxt->controlTxt);
//SetDlgItemText(hDlg, ctrlTxt->iControlID,
ctrlTxt->controlTxt);
SetDlgItemText(hDlg, id, txt);
}
return;
}
I get some compiler warnings. Function call "SetControlTxts(hDlg,
&ctrlTxts[0]);
":
warning C4047: 'function' : 'struct CONTROL_TXT ** ' differs in levels
of indirection from 'struct CONTROL_TXT *'
warning C4024: 'SetControlTxts' : different types for formal and
actual parameter 2
"id = &ctrlTxt->iControlID;":
warning C4047: '=' : 'int ' differs in levels of indirection from 'int
*'
"strcpy(txt, &ctrlTxt->controlTxt);":
warning C4047: 'function' : 'const char *' differs in levels of
indirection from 'char (*)[64]'
warning C4024: 'strcpy' : different types for formal and actual
parameter 2
Strcpy also causes access violation in Visual C++. However, I can get
valid value of "id", the debugger shows it correctly.
I also tried casting to char*:
strcpy(txt, (char*)&ctrlTxt->controlTxt);
but it also causes access violation.
Any info what am I doing wrong here?
Timo
but
I have some problems. I am using MS Visual C++ 6.0, but I think
this is more of a C-problem than Windows programming specific. Here
is the relevant part of my code.
typedef struct
{
int iControlID;
char controlTxt[64];
} CONTROL_TXT;
void SetControlTxts(HWND hDlg, CONTROL_TXT *ctrlTxt[]);
void MyFunc(void)
{
static CONTROL_TXT ctrlTxts[] =
{
{ 1, "text 1" },
{ 2, "text 2" },
{ 3, "text 3" },
{ 0, "" } // marks end of table
};
<clip>
SetControlTxts(hDlg, &ctrlTxts[0]);
}
void SetControlTxts(HWND hDlg, CONTROL_TXT *ctrlTxt[])
{
int i, id;
char txt[64];
for (i = 0; &ctrlTxt->iControlID != 0; i++)
{
id = &ctrlTxt->iControlID;
strcpy(txt, &ctrlTxt->controlTxt);
//strcpy(txt, (char*)ctrlTxt->controlTxt);
//SetDlgItemText(hDlg, ctrlTxt->iControlID,
ctrlTxt->controlTxt);
SetDlgItemText(hDlg, id, txt);
}
return;
}
I get some compiler warnings. Function call "SetControlTxts(hDlg,
&ctrlTxts[0]);
":
warning C4047: 'function' : 'struct CONTROL_TXT ** ' differs in levels
of indirection from 'struct CONTROL_TXT *'
warning C4024: 'SetControlTxts' : different types for formal and
actual parameter 2
"id = &ctrlTxt->iControlID;":
warning C4047: '=' : 'int ' differs in levels of indirection from 'int
*'
"strcpy(txt, &ctrlTxt->controlTxt);":
warning C4047: 'function' : 'const char *' differs in levels of
indirection from 'char (*)[64]'
warning C4024: 'strcpy' : different types for formal and actual
parameter 2
Strcpy also causes access violation in Visual C++. However, I can get
valid value of "id", the debugger shows it correctly.
I also tried casting to char*:
strcpy(txt, (char*)&ctrlTxt->controlTxt);
but it also causes access violation.
Any info what am I doing wrong here?
Timo