|
AFAIK, that's not possible, since the # token is reserved for stringifying macro parameters within the macro expansion.
Also, I see that your definition for VALIDATE_ADDR ends in a semicolon. In general, you do not want to end a macro with a semicolon, since this can lead to, in the best case, a compiler error, and in the worst case, a subtle and hard to find bug.
|
|
|
|
|
Macros are purely compile time. If you want runtime checks then use functions. Macros such as the above tend to be more trouble than they are worth.
|
|
|
|
|
What do you mean? I've clearly stated I want compile time execution, not runtime execution of this macro. Are you thinking of the _Static_assert function? It is executed at compile time, I think it's a feature built into the gcc compiler.
|
|
|
|
|
Sorry I misread the question. I have tried a number of variants but cannot get it to work. it would appear that #define statements are not accepted inside a macro definition.
|
|
|
|
|
Btw, I don't need the VALIDATE_ADDR macro for anything, it's perfectly fine to replace it with the _Static_assert directly, if that makes anything easier.
|
|
|
|
|
I have some hard coded strings which I wanted to add to the String Table and load that string from the string table.
From the resource view, i go to the string table and gave ID,value and caption there.
and tries to load by doing this.
CString temp;
temp.LoadString(IDS_STRING1);
But its giving me IDS_STRING1 is undefined. What is the correct way to do this?
Thanks in advance.
|
|
|
|
|
I found what I did wrong. Thanks
|
|
|
|
|
what was wrong ? how did you fix it ?
I'd rather be phishing!
|
|
|
|
|
I gave the value which is already there.. I gave a different number which is not already used and that solve my problem.
|
|
|
|
|
How to implement singleton design pattern for database connection in MFC vc++?.
|
|
|
|
|
|
I have created like this. Am I going in the right direction?
Thanks in advance.
#include <afxdb.h>
#pragma once
class DatabaseSingleton : public CDatabase
{
static DatabaseSingleton* _instance;
DatabaseSingleton();
public:
static DatabaseSingleton* GetInstance();
virtual ~DatabaseSingleton();
private:
CString DSN;
CString UID;
CString PWD;
CString ConnectionString;
};
#include "stdafx.h"
#include "Medication_Administration.h"
#include "DatabaseSingleton.h"
DatabaseSingleton::DatabaseSingleton():DSN(_T("DemoDB")),UID(_T("root")),PWD(_T("root"))
{
ConnectionString.Format(_T("DSN=%s;UID=%s;PWD=%s"), DSN, UID, PWD);
OpenEx(ConnectionString);
}
DatabaseSingleton::~DatabaseSingleton()
{
Close();
}
DatabaseSingleton* DatabaseSingleton::GetInstance()
{
if (_instance == NULL)
{
_instance = new DatabaseSingleton();
}
return _instance;
}
|
|
|
|
|
Yes you do
|
|
|
|
|
Interested to know how you can answer this, not so simple, issue, but struggle with the ones below, which are basic C.
|
|
|
|
|
I have never learn C, just c++ ... and this code where I am working on is written for Linux, and for other compilers than VS. That is why I got tones of errors, one of them I don't know how to handle them without broke the functionality (I cannot try what I modify, so I am working blind).
modified 7-Oct-19 8:30am.
|
|
|
|
|
OT means "Off topic". I am replying to a message but discussing a different subject.
|
|
|
|
|
I have met an error that I cannot rid of:
error C2061: syntax error : identifier 'mode_t'
The fact is that this 'mode_t' is not declared in my sources, and I haven't founded on internet ... how can I get rid of this error ? Thank you for any hint, any suggestion !
|
|
|
|
|
|
Thank you Victor. Might be the late hour, I have seen that page, and I included
<sys/stat.h>
no change ...
|
|
|
|
|
I would guess that in some other platform it is used to refer to the following line of the stat type:
unsigned short st_mode;
Which you could verify by checking the original source.
So you could just add the following above your includes
typedef unsigned short mode_t;
|
|
|
|
|
_Flaviu wrote: how can I get rid of this error ? Use an int .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I've met a weird error:
error C2678: binary '|=' : no operator found which takes a left-hand operand of type 'FILE_ATTR_FLAGS' (or there is no acceptable conversion)
1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\propsys.h(703): could be 'GETPROPERTYSTOREFLAGS &operator |=(GETPROPERTYSTOREFLAGS &,GETPROPERTYSTOREFLAGS)'
1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\propsys.h(1685): or 'PROPDESC_TYPE_FLAGS &operator |=(PROPDESC_TYPE_FLAGS &,PROPDESC_TYPE_FLAGS)'
1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\propsys.h(1704): or 'PROPDESC_VIEW_FLAGS &operator |=(PROPDESC_VIEW_FLAGS &,PROPDESC_VIEW_FLAGS)'
........
........
1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\shobjidl.h(31763): or 'HOMEGROUPSHARINGCHOICES &operator |=(HOMEGROUPSHARINGCHOICES &,HOMEGROUPSHARINGCHOICES)'
1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\shobjidl.h(32037): or 'LIBRARYOPTIONFLAGS &operator |=(LIBRARYOPTIONFLAGS &,LIBRARYOPTIONFLAGS)'
1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\shobjidl.h(32052): or 'LIBRARYSAVEFLAGS &operator |=(LIBRARYSAVEFLAGS &,LIBRARYSAVEFLAGS)'
1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\shobjidl.h(32793): or 'LIBRARYMANAGEDIALOGOPTIONS &operator |=(LIBRARYMANAGEDIALOGOPTIONS &,LIBRARYMANAGEDIALOGOPTIONS)'
1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\thumbcache.h(119): or 'WTS_FLAGS &operator |=(WTS_FLAGS &,WTS_FLAGS)'
1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\thumbcache.h(127): or 'WTS_CACHEFLAGS &operator |=(WTS_CACHEFLAGS &,WTS_CACHEFLAGS)'
1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\shlobj.h(542): or 'SHELL_LINK_DATA_FLAGS &operator |=(SHELL_LINK_DATA_FLAGS &,SHELL_LINK_DATA_FLAGS)'
1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\shlobj.h(1394): or 'KNOWN_FOLDER_FLAG &operator |=(KNOWN_FOLDER_FLAG &,KNOWN_FOLDER_FLAG)'
1> while trying to match the argument list '(FILE_FLAGS, FILE_FLAGS)'
Here is the code that generate the error:
sc->flags |= flag;
where flag is FILE_FLAGS, and sc->flags is
struct scr {
....
....
FILE_FLAGS flags;
....
};
Now, of course that I'ave tried:
scr& operator|=(const scr& rhs)
{
return *this;
}
but this error doesn't disappeared ... have you met this kind of error ? I have to mention that I wrote here the simplified code ...
|
|
|
|
|
Where is FILE_FLAGS defined? IN your code, or in a system header?
|
|
|
|
|
Is defined inside of one of my code header:
typedef enum {
FILE_READONLY = 0x00000001,
FILE_HIDDEN = 0x00000002,
FILE_SYSTEM = 0x00000004,
FILE_DIRECTORY = 0x00000010,
FILE_ARCHIVE = 0x00000020,
FILE_DEVICE = 0x00000040,
FILE_NORMAL = 0x00000080,
FILE_TEMPORARY = 0x00000100,
....
.....
}FILE_FLAGS;
|
|
|
|
|
This works but is not really correct.
sc->flags = FILE_FLAGS(sc->flags | flag);
I suspect the issue is that enums are usually used to signify single values, i.e the flags field is either FILE_READONLY or FILE_SYSTEM, but not both. If you need to combine values then you should really use a set of #define statements.
|
|
|
|