|
I am sure I have had to use it in threads in MFC apps. Its been a while and of course it use could be required in many situations.
|
|
|
|
|
ForNow wrote: m_pMainWnd->MessageBox((LPCTSTR)"SockClientThreadFail",NULL,MB_ICONERROR);
Look at the underlined section. What are you hoping to achieve by the cast? If you're compiling for non-Unicode it does nothing and if it's a Unicode build it tells the compiler not to issue an error but to shut up and assume the ANSI string is a Unicode one, which it's clearly not. Best case scenario is a garbled string in the message box, worst case an access violation because of no double NULL terminator. This is the typical fate of the cast-happy: turning a compile-time error into a runtime one. Don't cast if you don't know what's going on or fumble around casting to suppress a compiler error.
You don't need any casts:
m_pMainWnd->MessageBox(_T("SockClientThreadFail"), NULL, MB_ICONERROR);
Steve
|
|
|
|
|
On which thread do you encounter the access violation? Can you post the piece of code that causes the crash? It would be nice to see the whole code of your worker thread and the codepieces from he main thread that are used in the communication with the worker (like thread creation, receiving messages from the worker).
As "UI thread" I usually name the thread that drives a gui framework, by default in MFC this is the main thread. In my opinion its better to use just one thread to handle the GUI (the main thread with MFC) because that is perfectly enough on every platform with any GUI framework despite the fact that on windows any threads are allowed to create their own set of windows but this is not a good practice. As I see your thread handles networking, how do you send/receive data? In case of multithreading a very nice strategy is minimizing the amount of shared data as much as possible usually by using message posting. Sometimes the amount of shared data can be reduced to zero along with the bugs. Post some code if possible and then we can give advices.
EDIT: Forgot to mention that in MFC there are two different kind of threads: UI threads that support message pumping for the UI and simple worker threads. There are two AfxBeginThread() functions and one of them creates a UI thread while the other creates a worker. You can simply go by creating a worker thread with a lightweight wrapper class around this worker AfxBeginThread() call. Deriving from CWinThread and using its CreateThread method is useful only if you want to reuse the same thread object to execute and exit many threads on it but reusing the same thread object twice is a bad design anyway because it introduces a lot of bugs. Its better to recreate thread objects. If you want to preserve state between thread executions then put the preservable state into a separate object and pass the same state object to every time you recreate the thread after the destruction of the previous thread. Often its better simply keep the thread running than terminating it and then starting another (but in my frameworks I always use pools and precreated threads, the frameworks hides the creation/destruction of threads and that is cool).
modified 17-Aug-13 11:06am.
|
|
|
|
|
I need a template function that takes a stream_type and a data type as template parameters in a function. The purpose for this template function is to either read or write data to a file (binary or text format). I define an stream_traits and its io traits specializations as following:
template <typename T>
struct iostream_traits
{
typedef T stream_type;
};
template<>
struct iostream_traits <std::ofstream>
{
typedef std::ofstream stream_type;
static const bool _bSaving = true;
static const bool _bLoading = false;
};
template<>
struct iostream_traits <std::ifstream>
{
typedef std::ifstream stream_type;
static const bool _bSaving = false;
static const bool _bLoading = true;
};
My template function for read or write is defined as:
template<typename STREAM_T, typename T>
void SerializeElement_IO(STREAM_T &ios, T &t, bool bBinary, char cDelimiter)
{
if (iostream_traits<STREAM_T>::_bSaving)
{
if (bBinary) ios.write(reinterpret_cast<char *>(&t), sizeof(t)); else
{
if (cDelimiter == ' ') ios << t << " "; else if (cDelimiter == '\n') ios << t << std::endl;
else ios << t;
}
}
else
{
if (bBinary) ios.read(reinterpret_cast<char *>(&t), sizeof(t));
else ios >> t;
}
}
However, if I make a call to this template function in a program:
int a = 10;
std::ofstream ofs("DataFile");
SerializeElement_IO(ofs, a, true, ' ');
I got compile errors as
error C2039: 'read' : is not a member of 'std::basic_ofstream<_Elem,_Traits>'
error C3767: '>>': candidate function(s) not accessible
I am sure I have included necessary headers for the program.
I just couldn't understand why the errors are related to read or << operator while an std::ofstream object is passed to the template function.
Is there any way to implement this using traits technique?
modified 3-Aug-13 18:09pm.
|
|
|
|
|
basic_ofstream is inherited from basic_ostream and is used for output.
read is for getting input and so is not implemented in basic_ostream .
On the other hand basic_ifstream which is inherited from basic_istream implements read and not write .
In your case, since the function template uses both read and write , you could use basic_fstream which inherits from basic_iostream which in turn inherits from both basic_istream and basic_ostream .
Or you would need to write 2 separate function templates, one for read and one for write.
|
|
|
|
|
How to find the shortest path between two nodes in a undigraph,but the constraints of this path isthat it should via several given intermediate nodes. This uidigraph is a sparse graph and may not a connected graph.
The weight of every edge in the graph is the same. The number of nodes in the graph is about several thousand.
Do you have some ideas about it? Looking forward to your reply!
|
|
|
|
|
Please do not post the same question in multiple forums.
Use the best guess
|
|
|
|
|
Alcohol is the answer.
When ever you are well pissed it is incredible how quickly you can find your way from the pub to your house wjile passing trough several important nodes such as 1, kebab shop, 2 all nigt shop, 3, bus shelter to relieve yourself.
|
|
|
|
|
Hi,
I have created an application in visualstudio 2008 and i used MFC Featurepack CRibbonBar for designing menu bar. Its working fine in my PC.
When i invoke that application in some other PC which doesnot have Visual studio, its not opening.
I pasted mfc90d.dll ,mfc90ud.dll,mfcm90d.dll,mfcm90ud.dll,Microsoft.VC90.MFC.manifest in that application path. When i open the application,its opening but i cannot find the Ribbon menubar.
Just the view window get enlarged and filled the screen.
I think im missing some Dlls related to MFC Feature Pack.
Please help me how to resolve this problem. I want to run this application in my Client PC.
Anu
|
|
|
|
|
|
I installed that redistributable package. But no use. its not working.
Application is running but Ribbonbar is not coming.
Anu
|
|
|
|
|
Anu_Bala wrote: But no use. its not working. Then you will need to do some debugging to find out what is happening; it's impossible for us to guess.
Use the best guess
|
|
|
|
|
In my PC where visual studio 2008 installed , working fine.i can get ribbon bar also.
But not in other pCs. So i installed Microsoft Visual C++ 2008 SP1 Redistributable Package (x86)
and Microsoft Visual C++ 2008 Feature Pack Redistributable Package (x86)
in that PCs. But its not working.
IS there any particular DLL required for showing that ribbon bar?
Anu
|
|
|
|
|
|
You can find the missing dlls using Dependency Walker.
This small tool proved itself to be really helpful.
Microsoft ... the only place where VARIANT_TRUE != true
|
|
|
|
|
Looks like you're trying to deploy the debug version of you application.
The d in the names of the DLLs suggest this.
The redistributable package you installed does not contain the debug DLLs.
So you must try and deploy a release build.
|
|
|
|
|
Dear Friends,
We have an application which is developed using VC++ 2008. This application will refer the database with in the intranet network. Now I want to access this database from different network(via internet). For example, similar to "Form" getting user details and store it in the server and retrieve data back.
Kindly anyone suggest or guide me.
Thanks and Regards,
S.Shanmuga Raja
|
|
|
|
|
Assuming the server holding your database is accessible across the internet it would be just the same.
Use the best guess
|
|
|
|
|
I want to access database from different network.. like web application.
|
|
|
|
|
Repeating the same vague question is not helping your cause. What exact technical problem are you facing? Connecting from one system to another through a network, whether intra or inter is exactly the same. All you need to ensure is that each system can connect to the other through subnets and firewalls.
Use the best guess
|
|
|
|
|
My Database in India n my user access database from some other country. Plz tell me, for this scenario what connective needed to access the database.
|
|
|
|
|
I already told you. And since you have given no information, other than a vague "I want to" it is impossible to offer any further suggestion.
Use the best guess
|
|
|
|
|
Right now Application connected with database using OLEDB(connective). User are using this application within the same network(same building). Now they want to access the database from different place(not in the same network and different country). My question is same connective(OLEDB) procedure helpful for this scenario?
|
|
|
|
|
|
Sad but true.
Use the best guess
|
|
|
|