|
Sry, I don't understand your issue.
Don't try it, just do it!
|
|
|
|
|
You need a single 'Event' object. See CreateEvent.
Whne the OnDraw is called or 2 seconds have passed, call SetEvent.
Write your thread to wait on the event handle returned from CreateEvent.
So, then, your thread will 'run' when the event is signalled.
|
|
|
|
|
This is my first experience with maps and I am having some troubles.
I have developed a Logger that can do private logs depending on the client who calls the COM object. Based on the client's information, it needs to find the specific file to log to.
Here is my code:
//(header declarations)
std::map<BSTR, ofstream*> m_FileList;
std::map<BSTR, ofstream*>::iterator mFileListIterator;
//(code)
bool ClientHasCalledBefore;
_bstr_t FileName; //name of the file coming in.
//Look for FileName in map to see if it was called before.
ClientHasCalledBefore = (!(m_FileList.find(FileName) == m_FileList.end()));
// If it has called before, it logs to a clear file.
// If not, it creates the file, then appends the logs.
if (!ClientHasCalledBefore)
{
ofstream *ofstr = new ofstream(FileName, ios::out);
m_FileList[FileName] = ofstr;
*m_FileList[FileName] << "EntryToBeLogged";
m_FileList[FileName]->close();
}
else
{
m_FileList[FileName]->open(FileName, ios::app);
*m_FileList[FileName] << "EntryToBeLogged";
m_FileList[FileName]->close();
}
Okay. This code leads me to my first question. When I enter a new file into the map, sometimes it does not enter properly and the next time the conditional is checked, the FileName is not found. It does this sometimes the first one to three times it runs through. After the first couple of times, everything works fine. Because I am opening the file clean, this overwrites the first couple of entries. Any suggestions so that my conditional finds the entry in the map the first time?
//**************
In my destructor, I have this code to add a footer to every file:
for (m_FileListIterator = m_FileList.begin(); m_FileListIterator != m_FileList.end(); ++m_FileListIterator)
{
(m_FileListIterator->second)->open(FileListIterator->first, ios::app);
*(m_FileListIterator->second) << "FooterToBeAdded";
(m_FileListIterator->second)->close();
}
I think something is totally flawed with this. Sometimes it will append to a file I would have never created in my code, making a new file. Other times it will log the footer into the same file multiple times. It is almost as if it is not iterating.
Again, this is my first experience with any of this. Any help is much appreciated. Thank you.
|
|
|
|
|
Hello ChemmieBro, next time you post here please make sure you check on the "Do not treat <'s as HTML tags" checkbox below the input window: otherwise your < 's and > 's won't show up properly. For the benefit of other readers, I'm reproducing here the definition of m_FileList with the bracket thing right:
std::map<BSTR, ofstream*> m_FileList; The problem you're having is most likely the following: when you look up an item in std::map , the key you pass is compared against those of the elements stored in the map. So far so good, but in your case it is BSTR s that are used as keys, and these are pointers: so, instead of comparing the contents pointed to by the BSTR , it is the pointer addresses that std::map is taking into account, certainly not what you want. The most straightforward solution is to use as keys another type of objects with the right comparison semantics, like for instance MFC CString or some other wrapper around raw BSTR s.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
Thanks for your help. I'm brand new to using BSTRs also.
I do not have access to MFC here, so the CString is out. I will look into using some kind of wrapper around the BSTRs.
|
|
|
|
|
Check Michael Dunn and Nishant Sivakumar's Complete Guide to C++ Strings, Part II [^], you might find what you need there.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
Thank you so much. It was a pretty simple fix using the _bstr_t class instead of the BSTR. My inexperience with BSTR and _bstr_t got the best of me. I don't know why I chose BSTR in my map instead of _bstr_t. But everything is working fine now!
|
|
|
|
|
The following code works gives the b::B no appropriate default constructor err
while it works out fine without the virtual code words.
Can someone explain it/ how to make it pass compilation?
class B
{
public:
B(int a) {printf("BBB%d\n",a);}
};
class D : public virtual B
{
public:
D(int a):B(a) {printf ("DDD%d\n",a);};
};
class DD : public virtual D
{
DD(int a) (a) {printf ("DDD2%d\n",a);};
};
int _tmain(int argc, _TCHAR* argv[])
{
D d(3);
return 0;
}
Keep it simple
|
|
|
|
|
Change the definition of DD as follows:
class DD : public virtual D
{
DD(int a): <font color="#ff0000">B(a),</font> D(a) {printf ("DDD2%d\n",a);};
}; You may ask, why does one need to explicitly construct B , when D already does it? This is a fundamental characteristic of virtual inheritance. To illustrate the issue, consider the following class hierarchy:
struct Top
{
Top(int x){...}
};
struct Middle1: virtual public Top
{
Middle1(int x):Top(x){...}
};
struct Middle2: virtual public Top
{
Middle2(int x):Top(x){...}
};
struct Bottom: public Middle1, public Middle2
{
Bottom():Middle1(1), Middle2(2){}
}; As you know virtual inheritance makes Base objects contain only one instance of Top , like depicted in the diagram:
Top
/\
/ \
/ \
Middle1 Middle2
\ /
\ /
\/
Bottom Now take a look at Bottom 's constructor and ask yourself the following: How is the Top suboject of Bottom initialized? According to Middle1 , it is constructed with x==1 , but Middle2 calls Top 's constructor with x==2 ...
The fundamental problem is that, when virtually inheriting from Top , one cannot assume exclusive rights to the derived-from class, as it is likely to be shared among other unrelated classes. Recognizing this problem, C++ dictates the following: a virtually derived-from class Top must be explicitly constructed from the most derived class constructor, and all other calls to constructors of Top are ignored. Hence your problem.
This issue does not arise to the surface when the Top class has a default constructor, which could be the reason why you haven't met the problem before. Hope this helps.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
even the pixels is not contiguous,how to copy and paste through appications?
|
|
|
|
|
|
if i make a program that should handle a certain file type (for example, i want to make another notepad that should handle files of extension .txt), what do i have to do to associate that file type (in my case .txt) with my own program (in my case, let's say GNotepad.exe) so that by double-clicking a .txt file in the explorer it should open my notepad instead of the classic one ? oh, and i would reaaaaaaly apreciate if you have an example of source code. thanX a lot ...
|
|
|
|
|
|
Hi
Is it possible for 2 machines on comletely different networks communicate with each other using Winsock2?
Regards
dp_76
|
|
|
|
|
daniel vittori wrote:
Is it possible for 2 machines on comletely different networks communicate with each other using Winsock2?
Possible,if First Machine IP is Visible from Second Machine Network!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
I have a folder which contains an exe, and other files it needs (it was created from a python script using py2exe). Anyway, at the moment the user has to open the folder and click on the exe to run it. I would like to have it where i have a simple installer program which moves the folder to the program fiels directory, and creates a short cut for the exe in the desktop.
How do i do this?
Thankyou.
|
|
|
|
|
Free Setup Utilities
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
|
|
|
|
|
Hello!!
They are a new customer of the forum is I would want to make a question regarding DAO and ADO. I am work to a plan written in C++ 6,0 using DAO, now I have the necessity to use in same plan ADO. I have unloaded from Internet class ADO2 of Carlos Antollini and inserted in the plan but the two Classes they do not seem to cohabit... Someone to some idea on like using ADO and DAO in the same plan?
Thanks in advance payment.
|
|
|
|
|
When you say they "do not seem to cohabit..", are you getting compilation conflicts?
If that is the case then try this:
<code>
#pragma warning(push)
#pragma warning(disable:4146)
#import "C:\Program Files\Common Files\System\ado\msado15.dll" rename ("EOF","ADOEOF")
using namespace ADODB;
#pragma warning(pop)
#include <afxdao.h>
</code>
I Dream of Absolute Zero
|
|
|
|
|
My stdafx.h is:
#ifndef _AFX_NO_DB_SUPPORT
#include <afxdb.h> // MFC ODBC database classes
#endif // _AFX_NO_DB_SUPPORT
#ifndef _AFX_NO_DAO_SUPPORT
#include <afxdao.h> // MFC DAO database classes
#endif // _AFX_NO_DAO_SUPPORT
#pragma warning(disable:4146)
#import <msado15.dll> rename_namespace("ADODB") rename( "EOF", "EndOfFile" )
#pragma warning (default: 4146)
this work correctly.
My problem rises when it includes the class "Ado2.h" in some .cpp
msjro.tlh(48) : error C2011: 'ReplicaTypeEnum' : 'enum' type redefinition
cl.exe terminated at user request.
This why ADO and DAO use the same enum.....
|
|
|
|
|
MK78 wrote:
msjro.tlh(48) : error C2011: 'ReplicaTypeEnum' : 'enum' type redefinition
Ahh yes, JRO!
There are a host of conflicts between the JRO, ADO and DAO that you will get when you host all of them at once. To solve this, you will need to tinker with their namespaces definition a bit.
Below is the method that I use to resovle this conflict. The code below was used in the stdafx.h file, but your problem is located in the ado2.h file. you may want to modify the file directly, or relocate the importation routine to your stdafx.h file.
<code>]
#pragma warning(push)
#pragma warning(disable:4146)
<font color=green>
#import "C:\Program Files\Common Files\system\ado\msadox.dll"
#import "C:\Program Files\Common Files\System\ado\msado15.dll" rename ("EOF","ADOEOF")
#import "C:\Program Files\Common Files\system\ado\msjro.dll" rename_namespace("JRODB")
#import "C:\Program Files\Common Files\System\Ole DB\oledb32.dll" rename_namespace("oledb")
using namespace ADODB;
#pragma warning(pop)
#include <afxdao.h>
</code>
I Dream of Absolute Zero
|
|
|
|
|
Ok works!
Thanks!
Too many plans make the health badly...
|
|
|
|
|
Hi!
I'm trying to import a dll in Visual C++ 6. Can anybody help me?
When I link to that dll from another project it doesn't work. I'm sure I'm missing something, but I don't know what...
Here's how the dll is written (no errors, no warnings):
**************
* whatever.h *
**************
#ifdef __cplusplus
extern "C"{
#endif
class __declspec(dllexport) MyClass{
private:
char myString[100];
int myInteger;
public:
MyClass();
void getMyString(char * str);
int getMyInteger(void);
void setMyString(char * str);
void setMyInteger(int);
};
__declspec(dllexport) int function(MyClass * mc);
****************
* whatever.cpp *
****************
Just implementation here...
What can I do to import the class and the function from that dll (preferably not using a .def file)??? Please, help me, I'm going mad...
Thank you!!!
|
|
|
|
|
when importing you need to declare __declspec(dllimport)
An often used method when writing dll^s is following:
in the header write a statement like
#ifdef __MY_DLL_PROJECT__
#define _DECSPEC_ __declspec(dllexport)
#else
#define _DECSPEC_ __declspec(dllimport)
#endif
all you need to do is define the symbol _MY_DLL_PROJECT_ in your dll project, and
define your class in the header as:
class _DECSPEC_ MyClass
{
...
};
Greetings,
Davy
|
|
|
|
|
Yeah, thanks...
I had already done that. I nearly kill myself when I realized that I wasn't setting the dependence between both projects. That was all I needed.
Thank you very much for your reply!!!
JaVinci
|
|
|
|