|
I am changing over a communication .dll so that I can load it dynamically. All is going well, except for functions that have a default parameter. Here is an example function that had a default parameter for wID as zero.
I have in my .h file:
<br />
typedef WORD (_EXPORT_API *CM_SETTOOLID )(WORD wID = 0);<br />
extern CM_SETTOOLID CM_SetToolID;<br />
In my .cpp file that I include with my projects to load the .dll:
<br />
CM_SETTOOLID CM_SetToolID;<br />
CM_SetToolID = (CM_SETTOOLID)MyProcAddress( hCommManagerLib, "CM_SetToolID "); <br />
I get a compiler error:
error C2572: 'CM_SetToolID' : redefinition of default parameter : parameter 1
Is there anyway around this?
Thanks,
Eric
|
|
|
|
|
Hi Eric,
Sorry I can't help but you will be pleased to know that the latest compiler (VC++ 8) produces a different error.
Error Message
'symbol' : default-arguments are not allowed on this symbol
The C++ compiler does not allow default arguments on pointers to functions.
This code was accepted by the previous version's compiler but now gives an error. For code that works in all versions of Visual C++, do not assign a default value to a pointer-to-function argument.
For more information, see Summary of Compile-Time Breaking Changes.
The following line generates C2383:
Copy Code
// C2383.cpp
// compile with: /c
void (*pf)(int = 0); // C2383
void (*pf)(int); // OK
Regards,
John
|
|
|
|
|
Thanks for the help John. At least the later compiler gives an more distinct error message. Looks like my default values are out the window!
Eric
|
|
|
|
|
Hi
I have a class named CClipSaver and I want to create an array of this class. I do this as follows:
<code>CClipSaver* Clips[10];
.
int i=0;
Clips[i]=new CClipSaver;
Clips[i]->Save();
.
</code>
But it crashes!
Note:
When I do not use array (i.e.
CClipSaver * Clip;<br />
Clip=new ClipSaver();<br />
Clip->Save();
) everything works fine.
How should I declare and use the array?
|
|
|
|
|
The last time you posted this question, someone (I believe it was PJ Arends) asked what the
value of 'i' is when it crashes. Umm, what is that value?
You have an array of 10 pointers. You only show the first item in the array being used.
Something is happening elsewhere or code you haven't shown.
What line of code does the "crash" occur?
Mark
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
At any value of i (e.g. i=0) it crashes on initialization of the element (before Save() function)
|
|
|
|
|
MohammadAmiry wrote: Clips[i]=new CClipSaver;
Shouldn't this be:
Clips[i] = new CClipSaver(); MohammadAmiry wrote: Clips[i]->Save();.
But it crashes!
Have you stepped into the Step() method to figure out why? If, however, Clips[i] is NULL , you should not be calling the Save() method.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hey DavidCrow,
I noticed that too. What's the difference between those? I always "thought" that without
parenthesis, the default constructor gets called. I always use the parenthesis so I never
bothered to look it up
Thanks!
Mark
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
Mark Salsbery wrote: What's the difference between those?
For non-integral types, there is none. For integral types (e.g., int , char ), it amounts to whether initialization occurs or not.
Mark Salsbery wrote: I always use the parenthesis so I never
bothered to look it up
Same here.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Cool. Thanks for saving me the trouble of looking it up myself
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
Oh yes!
Clips[i] = new CClipSaver();
is correct and it was a missprint (although I have tried both)!
It throws an Access Violation error!
|
|
|
|
|
MohammadAmiry wrote: It throws an Access Violation error!
Where????? Throw us a bone here
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
I think the best advice people can give you is: use your debugger, it will save you hours of hassle.
If you never used it, it's time you start to . Put some breakpoints (by pressing F9) in your program where you want to check relevant information and start the debugger (press F5).
If you handle it well, it will give you much more information than we could give you (because we just have a very short code snippet).
|
|
|
|
|
Cedric Moonen wrote: use your debugger, it will save you hours of hassle.
Because with the following definition of CClipSaver the posted code works just fine
class CClipSaver
{
public:
void Save(){ cout << "Clip.Save" << endl;}
};
led mike
|
|
|
|
|
In fact I use this code inside an MFC dll.
When I put F9 on the line and press F5 to load the file that uses the dll, it disables the breakpoint expressing that the breakpoint is disabled because it is at the beginning of the program!!
I now used it in an MFC exe, surprisingly, NO ERROR occurs!!
|
|
|
|
|
OH I finally figured out!!!
The dll had to be called from a vb6 application (the hell with that!)
In declarations, there was a missing ByVal statement, which caused address value of i to be sent instead of its value.
Thanks all you folks for your attention which helped me figure this out, by checking other possibilities!
|
|
|
|
|
Hello, I have inherited a project that was originally written in VC++ 6.0 and am trying to compile it in vs 2005 but get several static_cast errors in my MESSAGE_MAPS. One example message map is
BEGIN_MESSAGE_MAP(CSlave, CWnd)
//{{AFX_MSG_MAP(CSlave)
ON_WM_CREATE()
ON_WM_NCHITTEST() <===Getting Error Here
ON_WM_NCMOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_WINDOWPOSCHANGING()
ON_WM_PAINT()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_TIFF,OnImage)
END_MESSAGE_MAP()
The exact error is:
cannot convert from 'UINT (__thiscall CSlave::* )(CPoint)' to 'LRESULT (__thiscall CWnd::* )(CPoint)'
The CSlave Class is derived from the CWnd class in an included .h file So I am not certain why this error is occuring. This is happening in several files of the project and any help from the community would be greatly appreciated. Thank you.
Also I will answer any questions as quickly as possible.
|
|
|
|
|
Look carefully at the error message. Some return values changed in message handler methods.
You may need to change your OnNcHitTest() method declaration to return the proper type.
Mark
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
Thank you Mark for the reply. After looking over each one I see that the return types are always different. I'm going to see why they are changed because I know that the project compiles and runs properly in VS 6.0. I'm wondering if it may have happened when the project was converted to 2005.
After examining further I've noticed that the base methods for CWnd always return LRESULT but the methods used in the code i've been given return some data type, void, UINT, BOOL, etc. I will look into this.
|
|
|
|
|
It changed in MFC.
Most are changed for 64-bit support I believe. LRESULT, WPARAM, LPARAM are now all large enough
to hold a pointer on 32 or 64 bit builds (or 65-bit for those that go one higher ).
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
Thank you very much for the help. I've noticed that the code is riddled with int to double and double to long conversions so it seems i'm going to have to go through and clean everything up making it more in line with what the original coder wanted to do.
Blake M. Ward
|
|
|
|
|
bward84 wrote: I've noticed that the code is riddled with int to double and double to long conversions
Bummer. Those would (should!) be unrelated to MFC message handler changes.
Have fun with that
Mark
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
I seemed to be able to remove the errors mentioned by redefining the functions being called by ON_MESSAGE. It seems that when this code was written ON_MESSAGE would return nothing (void) and you could define function handlers which would accept no arguments. I had to redefine them to return LRESULT and to accept WPARAM and LPARAM. However, now I am getting a problem when buttons are clicked. I get a Debug Assertion Failed box saying that the error occured on line 143 of filecore.cpp. I'm not sure if my above actions have caused this or if this is due to something else.
|
|
|
|
|
bward84 wrote: I get a Debug Assertion Failed box saying that the error occured on line 143 of filecore.cpp
What's on that line? In the version I have, it's
ASSERT(shareCompat == 0);
where shareCompat is an enumeration value == 0.
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
Hi. To get answer on your question, look here -> http://forums.microsoft.com/msdn/showpost.aspx?postid=8663&siteid=1
|
|
|
|