|
I have added "myfile.exe" to the my project's resource. The ID for the file in the project is "IDR_FILE2". After that,I created a newly open file with CFile with the following code:
CFile newfile("c:\\test\\quest.exe",CFile::modeCreate|CFile::modeWrite);
Which ofcourse will create a blank "quest.exe" in the directory. But I want to copy "myfile.exe" in the project's resource in to the newly create file "quest.exe" Could you please tell me the exact code that do what i want?
Thanks in advance for your help
noilivap
|
|
|
|
|
I guess you'd need to step over the file that is a resource, and write it's contents to the files. I could tell you how to do that with proper C++, but not with Microsoft's imitation classes.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
Could you please tell me the exact code(proper C++)?
Thank you very much for your help.
|
|
|
|
|
Does the file contain text only, or is it binary data, like an image ?
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
The file is a binary executable (.exe) and i want the newly created file be able to execute as well. And could you show me the code for text file too please.
Thank you so much for your help.
|
|
|
|
|
The part I'm not sure about is stepping through the original file object. I'll have a look tonight and LYK. Otherwise, a text object is easy.
std::string sObject; // Has been set to the text of the file
std::ofstream aa("c:\\myfile.txt");
aa << sObject;
aa.close();
You need to #include <iostream> and <fstream> and then that would be fine. The file can be opened with ios::bin as a parameter to be in binary mode, but unless you have a method of stepping through the file object, that does not help much. I'll do some research.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
I have compiled the boost library (specifically the regex++ portion), and have successfully used it in a test app in VC6. The problem is, that im getting no Intellisense (and I am using VisualAssist), and it is quite annoying. Its a small issue, but I am wondering what directories need to be included in VC and where I need to add those directories (I tried Tools:Options). Any suggestions?
|
|
|
|
|
I am trying to enumerate through all the process on running on my computer
so I can run through them and get a handle to the process using OpenProcess()
const DWORD dProcessCountGuesstimate = 200;
DWORD ardProcessIds[dProcessCountGuesstimate];
DWORD dNumberOfProccessFound = 0;
BOOL bReturn;
bReturn = EnumProcesses(ardProcessIds,
dProcessCountGuesstimate * sizeof(DWORD),
&dNumberOfProccessFound);
My question: Is there a better way other then guessing the number of process running on my computer. It kinda seems retarded to do it this way. Could someone please help.
Thanks.
|
|
|
|
|
The problem is that the process set is very volatile. Processes get started and stopped very regularly, without user intervention. Even if you could determine immediately prior to calling EnumProcesses how many there were, there's no reason to believe the count will be the same by the time EnumProcesses executes. So, just make a wild-ass overestimate of the count, and hope for the best. I'm sure that with statistical analysis, you could determine a value that has a 99.99% probability of being sufficient. But memory is cheap, right? Make your best guess at how many there will be -- and double that. Even if you allow for 1000 processes, that's just 4000 bytes.
Scot Brennecke
Software Developer
VC++ MVP
|
|
|
|
|
I have a strange problem that I am not sure where it is coming from. I have a program (GUI) that runs fine. I added another Form to my program and put label etcs on. All my labels I have made a label class to customize the behavior. As such I subclass all labels and such on all forms I make. And I have a lot of forms in my project.
OK. Today, after I added ONE single extra label, the system runs fine but when I exit, it gives me an access violation error.
What I want to know, is there a limitation how many controls there are in a project? Is there a limitation how many BRUSHes etc that I can create? The reason is that I have CBrush variable to hold brushes of all sorts in these so that they can change the bkgnd etc at will in the Ctlcolor function.
I hope someone can help. This is just driving me nuts.
Thanks in advance.
|
|
|
|
|
Yes, there is a limit, but it is quite large.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
hi all,
i am trying to write a client to connect to a non-mfc application thro' network. i am just at the beginning, i found that CSocket approach only support connecting to mfc application as the CArchive used. is it true?
would you recommend using winsock api or start from CSocket to connect to a non-mfc server? i don't have too much idea about these. pls try to give me some idea!
thanks,
jim
|
|
|
|
|
I'm actually going through a similar situation. And I can tell you that CSocket will not connect to a standard socket connection. If you use CSocket, you have to use CSocket throughout. If you can't use CSocket on all ends, use basic sockets. There's quite a bit of info out there.
Programming in binary is as easy as 01 10 11.
|
|
|
|
|
Hello, the codegurus around the world.;)
As the previous poster pointed out, CSocket or CAsyncSocket class
is closely related to GUI by MFC.
So, if you don't need to use MFC, you don't need these classes at all.
(In fact, WSAAsyncSelect function is inserted some messages like FD_WRITE
to Window message process at CSocket and CAsynSocket)
As a result, WinSock API is best choice for you.
Please, don't send me your email about your questions directly.
Have a nice day!
Sonork - 100.10571:vcdeveloper
-Masaaki Onishi-
|
|
|
|
|
hi,
i want to know whether i can use CSocket class to connect to non-mfc application. or, CSocket designed to be able for only connecting to MFC application.
in my application, i used MFC GUI. but, what i mean is connecting to Non-MFC application but my application is a MFC application.
i don't sure CSocket can connect to standard socket application such as a web server...
currently, i am using a winsock API. but, i feel it is a bit trouble on receiving data using recv() function.
thanks,
jim
|
|
|
|
|
In most source code, when initializing structures to zero, you mostly find something like this:
MYSTRUCT mystruct;
ZeroMemory(&mystruct,sizeof(mystruct));
I was wondering... what's wrong with a simple
MYSTRUCT mystruct = {0};
Cheers, Marc Click to see my *real* signature
|
|
|
|
|
Nothing what you are doing is just fine. It's all about what way you were taught. Peace
|
|
|
|
|
It's all about making readable code for yourself and others, weeks after you write it.
= {0} works. But it's not as obvious that the entire structure will be zeroed.
ZeroMemory usually gets compiled as memset with 0, but ZeroMemory is much clearer to read.
Back in the days when drive space and memory was expensive, it paid to write very small source code. We learned to be VERY thrifty with every byte, at the expense of readability. But the cost of maintenance should not be underestimated. If you can save another programmer just 2 minutes by making the code easier to read and understand, you've justified the use of a few extra bytes of source code.
Scot Brennecke
Software Developer
VC++ MVP
|
|
|
|
|
I got a bit curious, and fetched the decompiler...
= {0} is translated to 20 bytes of inline machine code in my test program whereas
the ZeroMemory approach is worth 16 bytes of inline machine code which includes a call to a more complex function with several jump instructions.
Scot Brennecke wrote:
but ZeroMemory is much clearer to read
Not in assembly
Cheers, Marc Click to see my *real* signature
|
|
|
|
|
OK, since you want to "fight" about it...
= {0} is not strictly equivalent to the ZeroMemory approach. Most significantly, if your struct is declared on the stack, you do not get what you want:
"If initializer-list has fewer values than an aggregate type, the remaining members or elements of the aggregate type are initialized to 0 for external and static variables. The initial value of an automatic identifier not explicitly initialized is undefined."
Scot Brennecke
Software Developer
VC++ MVP
|
|
|
|
|
damn.. well ok, you win, you got the docs on your side
MSDN wrote:
The initial value of an automatic identifier not explicitly initialized is undefined
..if this is true I think my code needs a little rewrite, but I'm quite sure this isn't true (at least for MS Visual C++).
Cheers, Marc Click to see my *real* signature
|
|
|
|
|
MySQL Has the following core functions:
connect(), query(), store_result(), fetch_[row, feild]() num_rows(), num fields(),
escape_string(), and close()
There are others, but those are the most used.
Data returned is all characters, and and you get to the data by:
row=fetch_row(query_result);
and row[N] = field N, it's that simple!
Is there anything that simple for ADO or ODBC? I'm trying to port a MySQL app to SQL Server, and having a hard time finding anything that simple. My real concern is handling user-defined queries. In MySQL it was as easy as:
con=connect();
select_database(con, "my database");
query(con, user_sql);
result=store_restult(con);
fields=num_fields(result);
while (row=fetch_row(result)){
for (f=0; f< fields; f++){
printf("%s", row[f]);
}
}
adding field names to the output is just as easy too! (a for loopw/fetch_feild() )
I have yet to see anything that easy for Windows/SQL server. My MFC book says it's too hard to do queries like that, so it doesn't cover it.
Anyone have any suggestions on wrappers?
|
|
|
|
|
Windows provides lots of way to get to data in databases but as you point out many of them are complex at least in the form provided by the system. I have used the CDatabase/CRecordset/CDaoDatabase, CDaoRecordset stuff from MFC, the ODBC api in straight C, ADO via smart pointers, ADO via straight COM, etc.
All of these do what you want but none with quite so few lines of code. I think they are designed to be more generic and powerful, but unfortunantely for many tasks they are just a pain in the butt.
I would take a look at the ADO library by Carlos Antollini (http://www.codeproject.com/database/caaadoclass1.asp). I have not used them myself but they appear to be quite simple and powerful.
If that doesn't work for you I have a set of class wrappers for ADO I developed a couple years ago which can do what you ask in fewer lines of code than you listed. I have not posted it here because it is not UNICODE compliant. Let me know if you would like the library and I will sent it to you with source code. It does not require MFC and this is basically how you would do what you asked:
CFPSADODatabase db("db", "uid", "pwd");
CFPSADORecordset rs(strSQL, db);
while (!rs.IsEOF())
{
for (iField = 0; iField < rs.GetFieldCount(); iField++)
printf(rs.GetFieldValueText(iField));
rs.MoveNext();
}
|
|
|
|
|
Is there a really good book on Windows Sockets that covers basics so low someone who hasn't programmed winsock before could understand but good enough to be the only resource I would need on the subject even for advanced topics?
|
|
|
|
|