|
Ok, but, how can I find a filter that have a still capture pin? I dont know how to do it. I have been looking for it in the "msdn" help, but I have not found anything at all
Please help! .
|
|
|
|
|
hiho@ll
first i have to say i need to solve this problem using linux, but i think it's a more c++ related question than linux
what i need:
explanation: i know that templates can generalize the datatype used for a class
so the class can work with an int, string, char, pointers
simply with different data types
my problem is something similar
i need a template for instaniating a class
this means, i want a configuration file, which says which class i need to use for the job i have to do
something like a string to object converter
i thought about make a abstract class and inherit from this and instantiate the needed class using the string
but the point is, i don't know how (or if this is possible) instantiate a object where the only knowledge of which object type to use is my configuration string
i hope it's understandable
greet@ll
|
|
|
|
|
ThinkingPrometheus wrote:
first i have to say i need to solve this problem using linux, but i think it's a more c++ related question than linux
...
the point is, i don't know how (or if this is possible) instantiate a object where the only knowledge of which object type to use is my configuration string
It's not a C++ related question. You need to use C# or Java (Class.forName(..)) to do that.
|
|
|
|
|
The typical C++ approach to this would be like so:
1. Create an abstract base class that defined the interface common to all classes that might be instantiated with this mechanism. Assuming the popular musical example, make this base class an "Instrument" and give it virtual methods like "Play", "Tune", "ThrowAway", etc.
2. Create all classes that need instantiating so, and make sure they all derive from this base class: Flute, Piano, Viola, etc.
3. Read your configuration file, and evaluate it using a simple (or powerful) parser, like so:
<br />
Instrument* parse(const char* word) {<br />
Instrument* result = NULL;<br />
if (!strcmp(word, "Flute")) {<br />
Instrument = new Flute();<br />
} else if (!strcmp(word, "Viola")) {<br />
Instrument = new Viola();<br />
} else ...<br />
...<br />
}<br />
return Instrument;<br />
}<br />
|
|
|
|
|
Hello,
Since you mention templates, I have to say the following. Templates take advantage of the symantics between objects. For example, all the operations they perform on the objects, is the same for every valid type that you can pass in the template specification.
You canno't do something like this at runtime like you can do with templates. You can mimic this behaviour by creating a "typeless" variable type like class CVar{/*...*/}; This type can be any type you want, like the VARIANT type used in scripting.
If the class that you need to create is always the same, but with other variable types, you can do something like the typeless variable above. I think that you need that, since you mentioned templates.
If you need to construct different classes with different behaviour, the inheritance / interface solution, that an other CPian already posted, is the way to go.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Use a class factory pattern - of sorts.
On each class you want to create derive it from base class with a Clone() and Key(), implement the Clone function in each derived class to create a new class and a Key() containing the class name.
Then create a static copy of your class, that you want to be able to create, so that on startup it registers itself dynamically with a Class factory object.
Then use your parser to search the class factory for the key, say in a map<base class> of registered objects - and do a Clone() to create a new one, and do a basic thing.
<br><br><hr color="navy"><small>"<i>Je pense, donc je mange.</i>" - Rene Descartes 1689 - Just before his mother put his tea on the table.<small>
<small>Shameless Plug - <a target="_new" href='http://www.codeproject.com/csharp/ESTransactions.asp'>Distributed Database Transactions in .NET using COM+</a></small>
|
|
|
|
|
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.
|
|
|
|
|