|
Hello guys,
I've created a struct and defined it as a new data type. However, when I want to declare a variable of this type there are several errors:
SMap: Illegal use of this type as expression
mySMap: undeclared identifier
<br />
#include <stdio.h><br />
#include <stdlib.h><br />
<br />
#ifndef NULL<br />
#define NULL 0<br />
#endif<br />
<br />
typedef struct<br />
{<br />
int width;<br />
int height;<br />
char* data;<br />
} SMap;<br />
<br />
SMap* createMap(int width, int height);<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
int width;<br />
int height;<br />
printf("Enter width: ");<br />
scanf("%i", &width);<br />
printf("Enter height: ");<br />
scanf("%i", &height);<br />
<br />
SMap* mySMap = (SMap*)malloc(sizeof(SMap));
<br />
return 0;<br />
}<br />
<br />
SMap* createMap(int width, int height)<br />
{<br />
SMap* mymap = (SMap*) malloc(sizeof(SMap));<br />
if (mymap == NULL)<br />
{<br />
return NULL;<br />
}<br />
mymap->width = width;<br />
mymap->height = height;<br />
mymap->data = (char*) malloc(width*height);<br />
if (mymap->data = NULL)<br />
{<br />
free(mymap);<br />
return NULL;<br />
}<br />
return mymap;<br />
}<br />
</stdlib.h></stdio.h>
I know that the use of malloc() isn't necessary in C++ but I want to compile the code as C-code.
Does anyone know why this doesn't work, maybe it's a basic thing I forgot about?
Thanks and best wishes.
|
|
|
|
|
Do you get different errors if you change the extension of the from between C and CPP? Then you'll be using the different compilers.
Also, for the initial typedef, try this:
struct _SMap_
{
int width;
int height;
char* data;
} SMap;
then, in main:
main (...)
{
int n;
...
n = sizeof(struct _SMap_);
n = sizeof(SMap);
}
and see if any happiness results.
Iain.
|
|
|
|
|
I told VS to compile the project as C-code until now this was enough.
As expected the results of the sizeof()-operations were the same (12Byte).
However, this didn't change anything. I've no idea what's the problem.
|
|
|
|
|
In C all variables must be defined at the start of the scope they belong to.
Change main() to:
int main(int argc, char* argv[])
{
int width;
int height;
SMap* mySMap;
printf("Enter width: ");
scanf("%i", &width);
printf("Enter height: ");
scanf("%i", &height);
mySMap = (SMap*)malloc(sizeof(SMap));
return 0;
}
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
Thanks, this was my problem. I knew that variables must be defined at the beginning of their scope when programming micro processors, didn't know that this is also important when writing Windows programs.
Thanks a lot.
|
|
|
|
|
It is a C language rule, platform/os doesn't matter.
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
we set focus to a control by sending WM_NEXTDLGCODE to it but in the case
1- the control is a button, check box or radio box
2- the dialog is opened by clicking a menu item by mouse and not keyboard
3- the user has not pressed TAB yat.
if we set focus to a button check box or radio box by code, the focus rectangle around the control text is not displayed and if the control has BS_NOTIFY style, the border is not darkened and user can not see which control has the focus.
is there any other methode to set focus to a control by code? or am I mistaken in some way?
I program with visual studio 9
Thanks
modified on Saturday, November 15, 2008 9:05 AM
|
|
|
|
|
|
No, SetFocus is not the correct answer. According to MSDN, WM_NEXTDLGCODE does things far beyond SetFocus, such as redrawing pushbutton border, and updating button`s push state and focus state.
Thanks for your reply
Abzadeh
|
|
|
|
|
abdolahzadeh wrote: WM_NEXTDLGCODE
WM_NEXTDLGCTL is the message to use.
If it's not working, then you're sending the message from the wrong place
or using the wrong wParam/lParam parameters.
From where and how are you sending the message?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I sent WM_NEXTDLGCTL message properly, and it was proven that this is a bug of win32. I tested this problem on the Sample created by visual studio and added only one button control and one check box, and the problem was there. and I noticed that an exe created by vc9 MFC opened by clicking on exe and not by ENTER had the same problem. I worked arround the problem by sending TAB to dialog artificially when the dialog is created and solved the problem.
Thanks for your notice and interest
Abzadeh
|
|
|
|
|
abdolahzadeh wrote: proven that this is a bug of win32
By who? Have a link?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I found that this may be designed intentionally by microsoft. to prove this, create a simple dialog that contains a push buttom, check box or radio box as the first control and create exe file. no ocde modification is needed. now run exe by clicking mouse and not keyboard, you see that the focus rectangle is not present and by pressing TAB or ALT key it appears. now run exe using keyboard and not mouse. the focus rectangle is present. this makes no problem unless the TAB key is controlled by the application returning DLGC_WANTTAB to WM_GETDLGCODE message(subclassing) or the application sets focus to controls by using WM_NEXTDLGCTL. and if there is a lot of push buttons and the user has openned the dialog by mouse and wants to use keyboard to navigate, he or she wonders which control has the focus. using TAB does not restore focus rectangle beacuse the application processes TAB and only sends WN_NEXTDLGCTL to the dialog.
Is there any way to bypass this behavier of controls?(draw focus rectangle even if the dialog is openned by mouse)
Thanks
Abzadeh
|
|
|
|
|
Here's a solution I've finally found that nails this problem...phewph. It was on MSDN.itags.org at http://visual-c.itags.org/visual-c-c++/49186/[^] and is provided by Jeff Partch [MVP] - thanks so much Jeff!!
On Win2k and up, the focus rect is hidden by default until you do things like: 1) Tabbing with the keyboard, 2) Hit the ALT key, or 3) Invoke the dialog with the keyboard in the first place. The WM_UPDATEUISTATE may explain it better than I do, but if I add a PostMessage of it to your OnInitDialog...
BOOL CTestChekBoxDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_button.Create(_T("Hello"), WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX, CRect(10,10,100,30), this, 10000);
GotoDlgCtrl(&m_button);
PostMessage(WM_UPDATEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEFOCUS));
return FALSE;
}
...it'll circumvent the expected behavior (which may not be a good thing, but that's your call). It
does do for me anyway. To get these 'UISTATE' defines you need to have the latest (or later than
that which ships with VC6) PSDK installed, and 2) You need to have defined (_WIN32_WINNT >= 0x0500)
way early in the build process. Personally, I think this conditional around a Window's message and
its parameter values is an error in judgement. Anyway, both these can be a real pain, so FWIW...
#ifndef WM_UPDATEUISTATE
#define WM_UPDATEUISTATE 0x0128
#endif
#ifndef UISF_HIDEFOCUS
#define UISF_HIDEFOCUS 0x1
#endif
#ifndef UIS_CLEAR
#define UIS_CLEAR 2
#endif
--
Jeff Partch [MVP]
|
|
|
|
|
MFC calls SetRegistryKey in InitInstance ,
and it'll create a key under HKEY_CURRENT_USER .
If different user run the same application, there will be two different entries created.
How to delete the two entries when uninstalling?
|
|
|
|
|
This is a windows issue (not MFC) and I don't think windows provide any solution for this. While you uninstall your application, clean all the CURRENT_USER's datas (which I think you are already doing) and can ignore other users. I remember this was suggested by Microsoft while I had attended a hands on lab at one of their Bangalore facility few years back.
-Suhredayan
|
|
|
|
|
When using VC++ 2008 feature pack, there is a problem for this,
if I change the toolbar, I have to delete the entries in the registry,
or else the change will not take effect.
|
|
|
|
|
Is there any default dialog window (like CFileDialog , CColorDialog ...CDialog derived) to ask the user the desired date and time?
I'd like to use it in this way
CTime Time;
{
CTimeDialog??? dlg;
if(dlg.DoModal()==IDOK){
Time=dlg.m_Time;
}else{
return;
}
}
Needed something similar to the dialog that appears on double click on the win-xp clock (trayicon)
Russell
|
|
|
|
|
|
|
Hello all
i am using VC++ (VS 6.0)
I want to link .lib file to my project ...
How to do it.
But when i put my .lib path in
"Project -> Settings -> Link -> input -> Object\Library modules"..
I didnt get any compilation or linking error .. but when i run the program i get the MessageBox as "Dll Not Found"
Any Sugesstion is really apppreciated..
regards
Aabid
|
|
|
|
|
Did you register your dll file?
|
|
|
|
|
You must be sure the corrensponding .dll (please note, not the .lib ) file, is in the (Windows) dynamic library search path, see [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi
I want to open an existing excel sheet and need to append data.
I m using vc++..giv me suggestions
Thanks
gany
|
|
|
|
|