|
thx@ll for the answer
but i did it a little bit different
my problem was for linux, and there is a linux way
but maybe there is a port for windows so i describe how it works with linux:
what i wanted is that i can load a class dynamically during runtime of my "core"
the problem: the only thing i (wanted to) know was the class name (and the function name for instantiating an object)
first you have to create a class, where all your classes are derived from
so i made a server class with a GetInstance method which simply calls
new MyObject();
depending on which class you want
next you can use dlopen to load the library file
and dlsym to get an object using the GetInstance function
void *hndl = dlopen("libnewshapes.so", RTLD_NOW);
if(hndl == NULL){
cerr << dlerror() << endl;
exit(-1);
}
void *mkr = dlsym(hndl, "maker");
shape *my_shape = static_cast<shape *()="">(mkr)();
and there is our shape object
for more information read http://www.linuxjournal.com/article/3687
|
|
|
|
|
Hi All,
I want to create a list view using CListView class. Can any body give me code to create that. I tried to create it in the OnInitialUpdate() of with following code but this is not working.I am not able to see these column names.Please help me.
void CTMSView::OnInitialUpdate()
{
CListView::OnInitialUpdate();
// this code only works for a report-mode list view
ASSERT(GetStyle() & LVS_REPORT);
// Gain a reference to the list control itself
CListCtrl& theCtrl = GetListCtrl();
// Insert a column. This override is the most convenient.
theCtrl.InsertColumn(0, _T("Name"),LVCFMT_LEFT,100);
// The other InsertColumn() override requires an initialized
// LVCOLUMN structure.
LVCOLUMN col;
col.mask = LVCF_FMT | LVCF_TEXT;
col.pszText = _T("Contact Number");
col.fmt = LVCFMT_LEFT;
theCtrl.InsertColumn(1, &col);
// Set reasonable widths for our columns
theCtrl.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER);
theCtrl.SetColumnWidth(1, LVSCW_AUTOSIZE_USEHEADER);
}
|
|
|
|
|
Hi man
is the class CTMSView ur project base class
or is there other classes
and if there is Panes at ur project
MFC programmer
|
|
|
|
|
Make sure that CTMSView is derived from CListView . That's all there is to it.
B.R.Singh wrote:
...but this is not working.
Have you tried removing the second call to InsertColumn() and both calls to SetColumnWidth() ? In other words, if
theCtrl.InsertColumn(0, _T("Name"), LVCFMT_LEFT, 100); does not work, the other code is just getting in the way at this point.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
|
Hi
i have build an application with dialog and buttons. Only i need to have administrator account that can modify smth in the application (not the source). So i decided to create a password verification box.
The problem is what is the best way 2 do it? and how can i store the password outside the source but encrypted in a way so that noone can understand it and for the administrator to be able to change it at runtime?
/\|-||\/|/\|)
|
|
|
|
|
Do it Unix style using 1 way encryption or hashing. There are plenty of sites there that can offer detailed descriptions of how it works but basically it's like this. You take the password and hash it using something like MD5 or SHA-1, then you store that password in plaintext. Then when you want to authenticate your user in the program, you ask for the password, you take that password and hash it and then compare that hash with the stored hash, if they match, then it's probably the right password and you let them in. This should be pretty good, you can add "salting" or a random string to the password if you want to prevent precompiled dictionary attacks...
Take a look at http://www.codeproject.com/cpp/csha1.asp
[^]
|
|
|
|
|
I know the compiler options for a multi-threaded program in VC++. Is there also a preprocessor #define that indicates multi-threading? So that I can do e.g. something like
#ifdef _MULTI_THREAD
# define doSomething(x) doSomethingMulti(x)
#else
# define doSomething(x) doSomethingSingle(x)
#endif
|
|
|
|
|
Since it is your process that actually creates those threads, wouldn't you be the best person to know whether or how many threads are in use?
It seems a bit hard expecting Microsoft to predict your source code.
What am I missing?
|
|
|
|
|
berndg wrote:
Since it is your process that actually creates those threads, wouldn't you be the best person to know whether or how many threads are in use?
It seems a bit hard expecting Microsoft to predict your source code.
I want to compile the whole program (my own code + MS code) either in 'single-threaded' or 'multi-threaded' mode. Depending on the threading-mode I want to call different functions. This should be done with macros (what else).
To make it work I need a #define similar to
#define _POSIX_THREADS
Yes, I can #define my own macro, but that's not the point.
What am I missing?
|
|
|
|
|
|
I know ...
From MSDN: C/C++ Preprocessor Reference : Predefined Macros
See Also Macros | Preprocessor Operators | Preprocessor Directives
The compiler recognizes 10 predefined ANSI C macros, and the Microsoft C++ implementation provides several more. These macros take no arguments and cannot be redefined. Their value, except for __LINE__ and __FILE__, must be constant throughout compilation. Some of the predefined macros listed below are defined with multiple values.
_MT Defined when /MD or /MDd (Multithreaded DLL) or /MT or /MTd (Multithreaded) is specified.
|
|
|
|
|
Blake Miller wrote:
_MT Defined when /MD or /MDd (Multithreaded DLL) or /MT or /MTd (Multithreaded) is specified.
Bingo! Thank you very much!
|
|
|
|
|
If you use this kind of macro magic just to implement your synchronization, this is bad! It is better to define a helper class that implements your lock, and define a macro that creates the lock or does nothing depending on the _MT switch.
Example:
class CSemaphoreLock
{
public:
CSemaphoreLock(HANDLE hSem) : m_hSem(hSem) { ::WaitForSingleObject(hSem, INFINITE); }
~CSemaphoreLock() { ::ReleaseSemaphore(m_hSem, 1, NULL); }
private:
const HANDLE m_hSem;
};
#ifdef _MT
# define SEMAPHORE_LOCK(HSEM) CSemaphoreLock TempLock_(HSEM)
#else
# define SEMAPHORE_LOCK(HSEM)
#endif // _MT
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Yes there is:
/MT Defines _MT so that multithread-specific versions of the run-time routines are selected from the standard header (.h) files. This option also causes the compiler to place the library name LIBCMT.lib into the .obj file so that the linker will use LIBCMT.lib to resolve external symbols. Either /MT or /MD (or their debug equivalents /MTd or /MDd) is required to create multithreaded programs. <br />
/MTd Defines _DEBUG and _MT. Defining _MT causes multithread-specific versions of the run-time routines to be selected from the standard .h files. This option also causes the compiler to place the library name LIBCMTD.lib into the .obj file so that the linker will use LIBCMTD.lib to resolve external symbols. Either /MTd or /MDd (or their non-debug equivalents /MT or MD) is required to create multithreaded programs.
Don't try it, just do it!
|
|
|
|
|
can anybody show me which tool can generate my code from VC to API document spec like javadoc from Sun
|
|
|
|
|
|
doxygen[^] + graphviz[^] is a good solution. It also permits to use java doc style.
Marc Soleda
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|
|
|
how about the other tools like RationalRose or Together, i have tried with Doxygen but it is limited with class diagram showing that only detect inheritance relations, how about other relations like Association,Aggregation, ....
i would like to find a tool that not only support feature to generate API doc spec like Doxygen but also can generate class diagram as RationalRose.
|
|
|
|
|
Would anybody tell me what is virtual destructor?
|
|
|
|
|
Hi
if u have for example multiple inherited classes
and u need to to call the destructor for one of them
so virtual used to call ur specific function u want
and virtual destructor always used at the frmae and application class for document and view
MFC programmer
|
|
|
|
|
the virtual C++ keywowrd tells that a member function is called instead of the base class' one.
for example, let's see this case :
<font color=blue>class</font> CBaseClass {
<font color=blue>public</font>:
<font color=blue>void</font> print() {
printf(<font color=gray>"CBaseClass\n"</font>);
}
};
<font color=blue>class</font> A : <font color=blue>public</font> CBaseClass {
<font color=blue>public</font>:
<font color=blue>void</font> print() {
printf(<font color=gray>"A\n"</font>);
}
};
now, if you make this :
CBaseClass* p = <font color=blue>new</font> A();
p->print();
this will display CBaseClass .
now, imagine you would like to access A::print() through a pointer to the base class, here come virtual .
if we had coded this instead :
<font color=blue>virtual void</font> print() { <font color=green></font> }
this would call the 'correct' print() function (as p is assigned with a A object, p->print() will call A::print() , even if p is a CBaseClass pointer).
understand better now ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
|
Per MSDN:
A destructor implemented by declaring a base class's destructor with the keyword virtual. A virtual destructor ensures that, when delete is applied to a base class pointer or reference, it calls the destructor implemented in the derived class, if an implementation exists.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|