|
Sir, What if I do if I run the executable on another computer.I have only "C:\\ and D:\\" drives if I run the executable on another computer which has "C:\\ D:\\ E:\\ " drives my code ultimately fails .How can I get the list of all files on the computer on which my executable runs.I sincerely thank you for giving me the excellent link for speed up my searching.
|
|
|
|
|
You really need to learn how to do some more research for yourself. How do you get a list of all the drives? Type "Windows list drives C++" into Google and start reading.
|
|
|
|
|
Yes, this ("Windows list drives C++") didn't strike to my mind.
Thank you sir for your kind help.
|
|
|
|
|
Are you referring to GetLogicalDrives() or GetLogicalDriveStrings()?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
modified 13-Dec-15 15:28pm.
|
|
|
|
|
Thank you Sir for your kind help. Can you please suggest me some links related to this?
I am searching in google for something related to this(like getting the strings form an executable) but I cannot find one.
|
|
|
|
|
Why do you keep asking this? I have explained what you need to do to find strings in a file, it's now time to go and try it.
|
|
|
|
|
Sir, I have tried a lot and finally figured out something. It is by searching for a specific file with MD5 hashes. Since, I want to search for a specific file through the whole drive.
Here is my try
inline std::string narrow(std::wstring const& text)
{
std::locale const loc("");
wchar_t const* from = text.c_str();
std::size_t const len = text.size();
std::vector<char> buffer(len + 1);
std::use_facet<std::ctype<wchar_t> >(loc).narrow(from, from + len, '_', &buffer[0]);
return std::string(&buffer[0], &buffer[len]);
}
void _tmain(int argc, TCHAR *argv[])
{
HANDLE hFind;
WIN32_FIND_DATA data;
std::string path = "C:\\";
std::string fileName = "";
wchar_t* file = L"C:\\*";
hFind = FindFirstFile(file, &data);
if (hFind != INVALID_HANDLE_VALUE) {
do {
fileName = narrow(data.cFileName);
if (fileName.compare(".") == 0)
continue;
if (fileName.compare("..") == 0)
continue;
cout << "FileName: " << fileName << " MD5 hash: ";
std::string finalFile = path + fileName;
char *cstr = new char[finalFile.length() + 1];
strcpy(cstr, finalFile.c_str());
char **temp = CALL_MD5_Function(cstr);
cout << temp;
cout <<endl << endl;
} while (FindNextFile(hFind, &data));
FindClose(hFind);
}
}
I don't know how to iterate if I found a directory, in here
if (fileName.compare(".") == 0)
continue;
if (fileName.compare("..") == 0)
continue;
I used continue statement to break the skip the operation since I am unsure. Could you please suggest me some ways to do it?
Thank you sir for your kind help
|
|
|
|
|
You should move your find processing to a separate function and call that with the root path you wish to search. You can then call that recursively each time you find a directory, something like:
void ProcessFiles(string root, string directory)
{
string searchPath = }
int main()
{
ProcessFiles("C:\\", NULL);
}
|
|
|
|
|
Thank you sir for your kind help and I am really sorry for the late reply
|
|
|
|
|
Hello, everyone! I am a Chinese programmer. Here is a question I want to specify this:
When I create an application based on Dialog, and then I open the toolbox and put the controls into my application.
I find this:
Button(which is the first control )
and MFC button control
Are they the same or different?
I will appreciate if anyone can provide an example to demonstrate it!
|
|
|
|
|
The Button is a standard Windows control that can be used in a Win32 or MFC application. The MFC Button Control[^] is an MFC class that 'wraps' the standard Button, but can only be used in MFC applications.
|
|
|
|
|
After including
#include <atlbase.h>
. Please suggest
2>C:\Program Files\Microsoft SDKs\Windows\v6.0A\\include\rpcndr.h(154) : warning C4114: same type qualifier used more than once
2>C:\Program Files\Microsoft SDKs\Windows\v6.0A\\include\rpcndr.h(154) : error C2632: 'char' followed by 'char' is illegal
2>C:\Program Files\Microsoft SDKs\Windows\v6.0A\\include\rpcndr.h(154) : warning C4091: 'typedef ' : ignored on left of 'unsigned char' when no variable is declared
|
|
|
|
|
Such things may happen when including header files in the wrong order, required header files has not been loaded, or are skipped due to exclusions. Because we don't know the other headers file that might be involved, it can't be answered for now.
A common problem is the inclusion of winsock2.h. This must be included before windows.h. I mention it here beacuse RPC is network related.
If this does not help you should try to find out the correct order by inspecting the header file inclusion tree. You can generate an include file tree by editing your project settings (Configuration Properties - C/C++ - Advanced - Show Includes).
Inspect the line of error (154 in rpcnhdr.h) to know which definitions trigger the error. Then try to find these definitions in header files included before that.
|
|
|
|
|
Thanks you for response. Basically I was trying to use ATL in non-ATL application.. Please advise
the line 154 in rpcnhdr.h is
typedef unsigned char byte;
|
|
|
|
|
When you use ATL, then your application is not a non-ATL one.
The first error message is "same type qualifier used more than once". So byte has been already defined.
The next one "'char' followed by 'char' is illegal" indicates that byte has been probably defined using a #define statement so that the compiler sees
typedef unsigned char char;
The third error is just based on the previous one.
So the goal is to find the previous definition of byte and check if the definition can be suppressed or the header file containing it might be included later. That might be some work because atlbase.h includes a lot of other files. I did a quick search but did not found it. But you should better perform this search with your files because they may change with the Visual Studi and the SDK versions.
|
|
|
|
|
Thanks for response. Actual I had a non ATL C++ application, to which I need to add Text to speech(https://msdn.microsoft.com/en-us/library/jj127898.aspx[^]), and hence I was trying to add
#include <atlbase.h>
extern CComModule _Module;
#include <atlcom.h>
And there by started with this issue.
|
|
|
|
|
Sir, I need to create "string" as an output using my formatted data.
To achieve this I did make use of "sprintf" function.But when building a solution using visual studio I get "C4996" error.
Here is the error message which I get:
Quote: Severity Code Description Project File Line
Error C4996 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 155
to disable all depreciation I've used this preprocessors as per my compiler's suggestion
#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_WARNINGS
but still the error persists.I have also decreased the warning level.
Kindly help me.
|
|
|
|
|
_CRT_SECURE_NO_WARNINGS must be defined before the header files that use the macro are included. So put it on top of your source file before including any header files.
To set it for all files of a project, add it on top of stdafx.h (when using that) or add it to the preprocessor definitions of your project settings (Configuration Properties - C++ - Preprocessor - Preprocessor Definitions).
Decreasing the warning level does not help here because the warning is treated as an error. To treat them as warnings, set SDL Checks to No in your project settings (Configuration Properties - C++ - General).
Another option is disabling the warning by using a pragma statement:
#pragma warning(disable : 4996)
This is useful when using those deprecated functions only a few times because they can be disabled on function level:
#pragma warning(disable : 4996)
void SomeFunc()
{
}
#pragma warning(enable : 4996)
|
|
|
|
|
Thank you Sir for your kind help.It works after defining "_CRT_SECURE_NO_WARNINGS " before the header files.
|
|
|
|
|
A better solution would be to do what the message says and use the sprintf_s function to create formatted strings. Or even to use the STL libraries if this is C++.
|
|
|
|
|
Thank you Sir for your kind help.
|
|
|
|
|
Hi
I am a bit confused about the double pointer.
I would like to pass it to a function and change the pointer value:
static int GetValue(int** hello)
{
*hello = &Something;
}
int* pointer = NULL;
GetValue(&pointer);
int** pointer = NULL;
GetValue(pointer);
To me they seem like the same thing.
|
|
|
|
|
elelont2 wrote: To me they seem like the same thing. No, they are totally different.
Case 1:
You create a pointer that will point to an integer variable, and pass its address to the function. The function then stores the address of a variable inside the pointer. On return the pointer now points to the variable, and the variable contains a value.
Case 2:
You create a pointer that will point to a pointer but is currently NULL. So when you pass it to the function the function gets a NULL value.
Simply put, in case 1, hello points to the address of pointer, in case 2, hello contains NULL. If you step through the code with your debugger it should become clear.
|
|
|
|
|
Hi all,
I have an MDI application under MFC. When I click on a menu I have a dialog based view (CDialog) which contains a button. What I need is when I click the button I want to resize my Dialog and set it to a new position.
I tried the MoveWindow, SetWindowPos but nothing changed. I think that those functions don't work with MDI or I missed sthing.
So people: How can I resize and move my Dialog to a new location point.
Thank you in advance.
"The Only Limit Is Only Your Imagination."
|
|
|
|
|
Moving the dialog by code should work like moving it by mouse. This does not depend on the application type.
Resizing is disabled for CDialog derived classes. To be resizable the window must have a different style (you may search for resizable dialogs). But it usually requires a lot of code to implement resizing with dialogs. It may be simpler to create your own window class that is not CDialog based (especially when it should be non-modal).
[EDIT]
You may have a look at these CP articles: CResizableDialog[^] and ResizableLib[^].
modified 8-Dec-15 5:40am.
|
|
|
|