|
I need a example for CopyFile() in MFC..
Anyone please....
|
|
|
|
|
in MSDN Samples, there s a sample pro named fibers, which copies a file frm a src dir, to a destn dir
the source filename, qualified with path and the destination path can be input as command line parameters..
hav a nice time copyin files
thanks,
-- ano
|
|
|
|
|
Hi all -
Here is the problem.
I need to create five worker threads in my win 32 dll and keep them alive throughout the host process life time. I need to call certain routines in these threads as per the host process's calls. I want to know what are the possible loopholes in this code. Is it correct or totally wrong? Your expert and experienced comments will be greatly appreciated..
The code looks like
HANDLE m_hThreadF1 = 0; //global thread handles
HANDLE m_hThreadF2 = 0;
HANDLE m_hThreadF3 = 0;
DLL::Function1() //this routine gets called by the host process
{
if (m_hThreadF1!=0)
ResumeThread(m_hThreadF1)
else
m_hThreadF1 = CreateThread(,,ThreadFuncF1,0); //not in
suspended mode
//Wait on the above thread to finish, then return, probably via an event
}
ThreadFuncF1() //thread handler
{
//do the intended processing
SuspendThread(m_hThreadF1)
}
|
|
|
|
|
Why do you call suspendthread? If you suspend the thread it will not exit and thus if you wait on the thread handle it will not ever be signaled. It's only signaled when the thread exits and unless you have another thread calling "ResumeTHread" that thread will just sit around.
Also, I know you didn't do this up there but never suspend a thread from another thread; it could be holding a lock and thus deadlock the process since you don't know what it's doing when you suspend it.
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|
See here for an interesting article about why you shouldn't (in general) call SuspendThread . If you want one thead to wait until another is finished try code like this:
WaitForSingleObject(m_hThreadF1, INFINITE);
A thread handle is a waitable object - It becomes signalled when the thread exist.
Steve
|
|
|
|
|
some tips, uh?
the method, WaitforSingleObject(threadhandle, waittime)
will return a value equal to WAIT_TIMEOUT if the thread is still alive (not in signalled state). instead of if(m_hThreadF1 != 0) try using this method with waittime as zero, as below:
if(WaitForSingleObject(m_hThread, 0)==WAIT_TIMEOUT)
// The thread s alive
else
// The thread s signalled, spawn new
make sure that the pThread's m_autodelete s set to false.
u mentioned, the thread s supposed to be alive till da end.
in this case, it seems, ur thread func has to make a slight modification. ResumeThread(handle), will resume a thread from the point it has been suspended, so, in ur case, when the ThreadFuncF1 resumes, it jst exits!!!
ThreadFuncF1()
{
do{
// do the intended processing
// Finished Processing, Notify parent
SuspendThread(m_hThreadF1)
}while(TRUE); // do processing again
}
hope thes'll help.
thanks,
-- 'whiz'
|
|
|
|
|
how can i change the background color of selected listctrl item i have set show selection allways property , it show only gray color but i want to change this color.
Bankey Khandelwal
Software Engineer
Solversa TechnologiesPvt.Ltd.
15,Yeshwant Nagar
Range Hill Road
Ganeshkhind,Pune-03
bankey.khandelwal@solversa.com
Mobile: +91-9850432990
Office : +91-20-25521888
|
|
|
|
|
There are probably lots of ways to do this - but one that springs to (my) mind is "Custom Draw". See here. Doing a search for "Custom Draw" on the The Code Project and Google will no doubt give many hits.
Steve
|
|
|
|
|
Hi all,
Yesterday I bought Robert Lafore's Object Oriented Programming in C++ book but there is a problem I really can't solve.
When I want to write the example codes in the book, I click File menu > New > File and then select Visual C++ > C++ File (.cpp). And I get a new window to code things. But the problem is whenever I press Build from the Build menu, I get this error:
C:\OOP\NewX\NewX.cpp(9): fatal error C1010: unexpected end of file while looking for precompiled header directive
Is Build what I should use to see the result of the code?
What I have written was this:
#include <iostream>
using namespace std;
int main()
{
cout << “Every age has a language of its own\n”;
return 0;
}
and then this:
cout << “Every age has a language of its own\n”
Please help me to solve this problem as this is the key thing to learn C++.
Btw I have Visual C++ 2005 Express Edition.
Thanks in advance,
Joshua
|
|
|
|
|
if its just for a (excuse me, not meaning to demean you in any way) 'trivial' program you're playing around with, then in MSVC 6 I would have gone
Project -> Settings
Selected the source .cpp file
Gone 'to the right' pane and selected 'C++', Category 'Precompiled Headers', and ticked 'Not using precompiled headers'
In real world programs, this can mean that stdafx.h isnt being used correctly, but if you're working on small example, I'd ignore MSVC technicalities in favour of getting something to build and run (else it gets way boring) ...
'Precompiled Headers' can also be set at a project level, but I'm not au-fait with the .NET Editor/Environment, so I'll have to leave that with you - 'either one' should do the trick
'g'
-- modified at 22:08 Friday 20th January, 2006
|
|
|
|
|
Thanks alot Garth. Actually I am trying to learn c++, so this is really important but this kind of behaviour really confused me. I have now turned off precompiled headers and got these errors:
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2065: '“Every' : undeclared identifier
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2146: syntax error : missing ';' before identifier 'age'
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2065: 'age' : undeclared identifier
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2146: syntax error : missing ';' before identifier 'has'
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2065: 'has' : undeclared identifier
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2146: syntax error : missing ';' before identifier 'a'
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2065: 'a' : undeclared identifier
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2146: syntax error : missing ';' before identifier 'language'
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2065: 'language' : undeclared identifier
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2146: syntax error : missing ';' before identifier 'of'
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2065: 'of' : undeclared identifier
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2146: syntax error : missing ';' before identifier 'its'
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2017: illegal escape sequence
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2065: 'its' : undeclared identifier
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2146: syntax error : missing ';' before identifier 'own'
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2065: 'own' : undeclared identifier
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2146: syntax error : missing ';' before identifier 'n”'
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2065: 'n”' : undeclared identifier
|
|
|
|
|
ok, its a list of errors - it looks like you've stuffed the definition of a character string of some sort .. [deleted] .. sorry, I thought you hadnt posted the code .. looking back you did
I'll try to look at it in a mo
'g'
-- modified at 5:35 Saturday 21st January, 2006
|
|
|
|
|
still not exactely sure how your project is set up (did you use a wizard ?), but if I have
#include "stdafx.h"
#include <iostream>
int main(int argc, char* argv[])
{
std::cout << "now is the time\n" ;
return 0;
}
I dont have any issues ..
If you're not generating your project using a wizard, it can get very hard getting all the settings right, so start by creating your projects with the 'wizard'...
so try this
shut down VS .NET, then start it up to get a clean slate
select file, new, projects, Win32 Console Application
set a location, give the project a name eg test1
instruct the wizard to create a "Simple Application"
Then select the fileview tab, source file, test1.cpp
edit test1.cpp to look like mine, build it (F7), it should compile cleanly, then CTRL+F5 to run it ..
I often think its hard on win32 to learn this, because you have a complicated IDE to master as well - I learnt on Unix and to some extend, it was easier
see how you go with that ..
note the std:: in front of the cout - its because within iostream library, its exporting the 'cout' into what's known as a 'namespace' - so to reference it, you need the std:: (there is another way around this, lets walk before we can run)
'g'
|
|
|
|
|
Hey Garth,
You simply rock! It works now. I can't believe I saw it working man.
If you don't mind can I ask why I have to build and then use execute? In the language I know, I only use evaulate all and then it compiles and works.
Is there a reason for this?
Thanks again!!!
|
|
|
|
|
'build' in your IDE is a compile of the source code into an object module, and then link the required object modules into an executable program (program in this case as opposed to dll etc) .. this executable program can be run directly by the host platform ie Win32 (thats a big simplification)
'execute' actually calls/runs the .exe and shows its output (if you look, in likely to be a 'debug' folder under where you created the test1 project, you'll have test1.exe, plus some other objects) .. you could run a cmd prompt, change to the directory where the .exe is (or copy it somewhere useful) and simply run it from the command line
Joshua N wrote: In the language I know
ok .. its probably a 'bytecode'/interpreted language, like java perhaps ? .. in this case, the source code is compiled into an intermediate representation, 'bytecode', that is then interpreted code by code/instruction by instruction by an engine - a 'java virtual machine "jvm"' - ie, the JVM calls the underlying os functions etc and performs the functionality (again, simplistic for this response)
ok, so, you're started .. at some stage, I suggest you experiment with doing the 'build' stage, then instead of running a program using CTRL+F5, use 'debug' options (there's a menu for them, showing some of the keys I'll mention below) .. for example, pressing F10 after a 'clean' build will run the program one statement at a time (so you'll have to press it more than once), and you can see the contents of your variables etc in a window on the screen. You can 'step into' functions, using F11, you can put the cursor on a line of code and say 'run to here', you can set a stop called a breakpoint on a line and push F5 to run to that breakpoint (put cursor on line, select 'hand symbol' and a red dot should appear next to the line), and of course you can have more than one breakpoint ... knowing how to use these options will save you many hours of grief when it comes to debugging something more complex .. it will take some time to learn it and find the various windows etc, but dont most things worthwhile take some effort to learn ?
'g'
-- modified at 18:19 Saturday 21st January, 2006
|
|
|
|
|
First of all, you placed your last cout out of main() and you forgot the ; at the end of the statement.
|
|
|
|
|
Sorry Radio,
I did this to show that I even can't run a sinle line. Do I need to use; after every line btw?
Thanks!
|
|
|
|
|
Hi Joshua,
There are some instances where we don't need to use ";" like in macros and comments.
Before you start c++, make sure to orient yourself with the basics of the subject first (the syntax, how to use the IDE, the capabilities of C++) for you to at least have an idea what's in store for you ahead. There are lots of C++ tutorials online, just to guide you along the way.
=waxie=
|
|
|
|
|
I think you are missing a #include file name, and possibly you're using those strange slanty quotes. You need to do something like this:
#include <iostream>
using namespace std;
int main()
{
cout << "Every age has a language of its own\n";
return 0;
}
|
|
|
|
|
Hello,
Is there a way to make a connection to an access database using the .NET framework? So I'm looking for functionality like what is in System.Data.SqlClient, but I'd like to connect to an access database.
Also, when you pass a "connection string" to a SqlConnection object, you need to include a database name.. Does that name refer to an ODBC connection or just to the name of the database in SQL server?
Thank you,
-Jordan
|
|
|
|
|
Check out this article.[^]
ed
~"Watch your thoughts; they become your words. Watch your words they become your actions.
Watch your actions; they become your habits. Watch your habits; they become your character.
Watch your character; it becomes your destiny."
-Frank Outlaw.
|
|
|
|
|
Thanks Ed. It looks like I need to use an OleDbConnection.
--Jordan
|
|
|
|
|
Hey all, I have the Visual Studio Express Beta 2 with Team System in there including the code coverage and testing stuff. Does anyone know of a tutorial I can check out on how to use the code coverage?
When I did try to use the "New Test" menu item, it auto generated a bunch of code that looked like C#. I tried to add in my own C++ stuff but the compile failed terribly with over 8000 (yes that's right 8 thousand) errors (and it was still going when I canceled it). Perhaps you can only use the code coverage for C# code and not C++?
Thanks
azbok
|
|
|
|
|
Hi folks,
I'm creating a simple Visual C++ program which is supposed to display an animation: A timer event
calls a panel_Paint() which writes the graphics on screen.
My problem is that I cannot store data anywhere that will tell the panel_Paint() function
at which frame of the animation it is so it knows which file to display -
if I initialize a variable inside the function, it will be re-initialized next time it is
called, and if I try to initialize a variable outside the function, I am told that I can only initialize static variables there.
I'm new to Visual C++ and this kind of event-driven programming, maybe somebody can tell me
where I can store data for my functions to use. Thanks in advance.
-- modified at 20:59 Friday 20th January, 2006
|
|
|
|
|
I need more information about the structure of your program to answer this question - But normally the data would be stored in a member variable of the class that contains the callback function.
Steve
|
|
|
|
|