|
Hey Snakefoot,
I use it as a convenient location to keep operating files without bothering with the registry. Let me give an assurance that I am not in the business of writing viruses or Malware. They may have the best of intentions, but people like this cause alot more harm than they do good.
Danny
|
|
|
|
|
When you mean operating file, then I guess you mean data files that belongs to your application. Such files should not be placed in the Windows-directory.
What if another application suddenly decides to also use this location, and by mistakes uses your filename-format ?
You should read this guide from Microsoft Data and Settings Management[^] (Though written for Win2k, then it also holds for Vista/Win7)
TCHAR szAppData[MAX_PATH];
...
hr = SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, szAppData);
PathAppend(szAppData, "Company\Product\File.txt")
- CSIDL_APPDATA - Per user, roaming [user profile]\Application data
- CSIDL_LOCAL_APPDATA - Per user, non-roaming [user profile]\Local Settings\Application data
- CSIDL_COMMON_APPDATA - Hidden folder for normal users. Per machine (non-user specific & non- roaming) All Users\Application data
- CSIDL_COMMON_DOCUMENTS - Visible folder for normal users. Default files in this folder is readonly for other users than the creator, the application must change the security permissions on its application-folder to change this behavior. Per machine (non-user specific & non- roaming) All Users\Documents
modified on Monday, December 14, 2009 10:39 AM
|
|
|
|
|
Hi all,
I am using '_UNICODE' rather '_MBCS' in my MFC single document app.
My problem code-
CString openFilePath;
CFileDialog fileOpen(true, NULL, NULL, NULL, L"Text file(.txt)||*.txt", NULL);
openFilePath = fileOpen.GetPathName(); //it returns CString
'GetPathName()' returns just a single charecter. When i use '_MBCS' it returns full file path.
I want unicode standard with full file path when i open a file using "CFileDialog".
Thanks
|
|
|
|
|
Shaheen.India wrote: 'GetPathName()' returns just a single charecter. When i use '_MBCS' it returns full file path.
How are you verifying this?
Shaheen.India wrote: I want unicode standard with full file path when i open a file using "CFileDialog".
CFileDialog does not open files. It merely allows you to select them.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Verifying in Debug mode. It sends a single character as a string. When i open a file, if it belongs like "e:\MyData\aa.txt", it returns just "e" as string
|
|
|
|
|
Which does not answer my question. If you are using the Watch window, then you'll need to use the ,su symbol to see Unicode strings. Otherwise, you're just going to see a single character.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Using object of CFileDialogIt sends a single character as a string. When i open a file, if it belongs like "e:\MyData\aa.txt", it returns just "e" as string.
OK. How can i get open file path?
modified on Wednesday, November 11, 2009 10:41 AM
|
|
|
|
|
Shaheen.India wrote: When i open a file, if it belongs like "e:\MyData\aa.txt", it returns just "e" as string
This makes no sense. You've shown no code that opens a file, only code that selects a file. What's the "it" that you are referring to?
You would receive more reliable help if you'd post the actual code that you are commenting on or asking a question about.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
OK. Can i get full file when i open a file using 'CFileDialog's constructor?
|
|
|
|
|
This is my simple code:
CString openFilePath;
CFileDialog fileOpen(true, NULL, NULL, NULL, L"Text file(.txt)||*.txt", NULL);
if(fileOpen.DoModal() == IDOK)
{
openFilePath = fileOpen.GetPathName();//Here is a break point. at this stage //value of openFilePath display like {"e"} only.
..
..
}
|
|
|
|
|
Shaheen.India wrote: openFilePath = fileOpen.GetPathName();//Here is a break point. at this stage //value of openFilePath display like {"e"} only.
See here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Hello guys,
Im new to this forum and this is my first post!!!
I am a beginner at this and need some help with my first project.
Basically i am looking to create a expert car system..which works as follows:
a user will be able to input natural english text into the system...for example 'i want a blue honda with a 1.6 engine'
the system should read the text and cleverly extract the key words such as 'blue' 'honda' '1.6'
as soon as the words are matched, c++ will add these values in my database in mysql
if there are any missing values then the system should ask the user.. so:
tables:
colour table - blue
car table - honda
model table - ?
engine table - 1.6
so becuase the model table is missing maybe the system can ask the user..'how about the model?'
and evetually one the tables are filed the sql wil run and find matching cars and the output will be shown in c++.
okay so this is my plan..what do you guys think??
stupid plan?
i just need help trying to design this program.
any ideas or suggestions will help. like how do i go about creating sets of colours in c++ so when the user types in the text i can match the colour from his text to my set and send it up to the sql database?
Thanks guys
|
|
|
|
|
akshay1741 wrote: any ideas or suggestions will help. like how do i go about creating sets of colours in c++ so when the user types in the text i can match the colour from his text to my set and send it up to the sql database?
You will need a list, array or table of some form with all the valid colours held as strings. Then when the user enters the deatails you need to parse the input and look for a word that matches any of your colours, not forgetting to allow for upper, lower or mixed case.
From your opening statement I would suggest you get comfortable with the basics of C++ before trying to create the project you describe above.
|
|
|
|
|
akshay1741 wrote: cleverly extract the key words
ok, that is not simple; but people have been doing this for a while, but it's not easy.
Parsing, even simple, natural language is difficult.
If you want to simple extract strings from any input and match them to table that's easy, but that's no expert system.
for example "bla bla 1.6 blue fox jumps over the honda but his engine is sick"...
you will need to tokenize (keyword here) the input string and take each token and do a search into a table.
Good luck.
This signature was proudly tested on animals.
|
|
|
|
|
In the vein of my CreateProcess() question in a parallel thread today I'm facing the problem
of letting the called subprocess doing some tidying up work before really following the termination signal.
Would that be possible? Or would it be better to send the process a different signal
(in UNIX that would have been a USR signal) and wait a time period for receiving the termination event and if that does not occur in time, then terminating it brute force?
Is the TerminateProcess an unconditional signal that cannot be intercepted by the process
under termination itself? Hope I expressed myself clearly enough
--
Christoph
|
|
|
|
|
Have you control about the subprocess?
If so why not use named events?
HANDLE hEvent = CreateEvent(NULL, true, false, "some_silly_name_you_can_refer_to_in_your_processes");
You can use this in your service and your subprocess.
If an event with this name does not exists in the system it will be created, if
it exists, you get the same handle as the first application who called CreateEvent with this
name. Now you can interact with your subprocesses.
Greetings
Covean
|
|
|
|
|
Covean wrote: Have you control about the subprocess?
If so why not use named events?
HANDLE hEvent = CreateEvent(NULL, true, false, "some_silly_name_you_can_refer_to_in_your_processes");
Thanks. Yes, I have control of the process' source code. Will try something in that vein.
--
Christoph
|
|
|
|
|
In general I do not post my own code but doing some IPC-stuff is not such a secret.
Here is a dll I wrote to communicate between 2 apps.
The one site calls
GetFaceDetectionStatusChangedEventHandle(),
CreateFaceDetectionStatusMapFile(),
and GetCurrentFaceDetectionStatus() and closes it if it doesnt need it anymore.
the other site calls SetFaceDetectionStatus() instead of GetCurrentFaceDetectionStatus().
This code shows how to wait in one app for another and how to transfer
data from one app to the other by using shared memory.
Note: I left the german comments in for you.
------------------------------------------------------------------------------------------
fdinterop.h
#pragma once
#define WINVER 0x0501
#define _WIN32_WINNT 0x0501
#define _WIN32_WINDOWS 0x0410
#define _WIN32_IE 0x0600
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
TCHAR szEventName[]=TEXT("FDInteropDllFaceDetectionStatusChanged");
TCHAR szMapFileName[]=TEXT("FDInterOpDLLFaceDetectionMapFile");
typedef struct _fdsObject
{
DWORD dwTimeStamp;
BOOL bFaceDetected;
INT nX1;
INT nY1;
INT nX2;
INT nY2;
} FDS_OBJECT, *PFDS_OBJECT, NEAR *NPFDS_OBJECT, FAR *LPFDS_OBJECT;
HANDLE _declspec(dllexport) __stdcall GetFaceDetectionStatusChangedEventHandle();
void _declspec(dllexport) __stdcall CloseFaceDetectionStatusChangedEventHandle(HANDLE hFaceDetectionStatusChangedEventHandle);
HANDLE _declspec(dllexport) __stdcall CreateFaceDetectionStatusMapFile();
void _declspec(dllexport) __stdcall CloseFaceDetectionStatusMapFile(HANDLE hFaceDetectionStatusMapFile);
BOOL _declspec(dllexport) __stdcall GetCurrentFaceDetectionStatus(HANDLE hFaceDetectionStatusMapFile, LPFDS_OBJECT pFDSObject);
void _declspec(dllexport) __stdcall SetFaceDetectionStatus(INT bFaceDetected, INT nX1, INT nY1, INT nX2, INT nY2);
------------------------------------------------------------------------------------------
fdinterop.c
#include "fdinterop.h"
BOOL __stdcall DllMain(HANDLE hModule, DWORD dwReasonForCall, LPVOID lpReserved)
{
switch(dwReasonForCall)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
HANDLE __stdcall GetFaceDetectionStatusChangedEventHandle()
{
return CreateEvent(NULL, TRUE, FALSE, szEventName);
}
void __stdcall CloseFaceDetectionStatusChangedEventHandle(HANDLE hFaceDetectionStatusChangedEventHandle)
{
CloseHandle(hFaceDetectionStatusChangedEventHandle);
}
HANDLE __stdcall CreateFaceDetectionStatusMapFile()
{
return CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(FDS_OBJECT), szMapFileName);
}
void __stdcall CloseFaceDetectionStatusMapFile(HANDLE hFaceDetectionStatusMapFile)
{
CloseHandle(hFaceDetectionStatusMapFile);
}
BOOL __stdcall GetCurrentFaceDetectionStatus(HANDLE hFaceDetectionStatusMapFile, LPFDS_OBJECT pFDSObject)
{
LPFDS_OBJECT pFDSBuffer = NULL;
if((hFaceDetectionStatusMapFile == NULL) || (pFDSObject == NULL))
return FALSE;
pFDSBuffer = (LPFDS_OBJECT)MapViewOfFile(hFaceDetectionStatusMapFile, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(FDS_OBJECT));
if(pFDSBuffer == NULL)
return FALSE;
memcpy(pFDSObject, pFDSBuffer, sizeof(FDS_OBJECT));
UnmapViewOfFile(pFDSBuffer);
return TRUE;
}
void __stdcall SetFaceDetectionStatus(INT bFaceDetected, INT nX1, INT nY1, INT nX2, INT nY2)
{
FDS_OBJECT fdsObject;
LPFDS_OBJECT pFDSObject;
HANDLE hFaceDetectionStatusMapFile = NULL;
HANDLE hFaceDetectionStatusChangedEvent = NULL;
fdsObject.dwTimeStamp = GetTickCount();
fdsObject.bFaceDetected = (bFaceDetected==0) ? FALSE : TRUE;
fdsObject.nX1 = nX1;
fdsObject.nY1 = nY1;
fdsObject.nX2 = nX2;
fdsObject.nY2 = nY2;
hFaceDetectionStatusMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, szMapFileName);
if (hFaceDetectionStatusMapFile != NULL)
{
pFDSObject = MapViewOfFile(hFaceDetectionStatusMapFile, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(FDS_OBJECT));
if(pFDSObject != NULL)
{
memcpy(pFDSObject, &fdsObject, sizeof(FDS_OBJECT));
UnmapViewOfFile(pFDSObject);
CloseHandle(hFaceDetectionStatusMapFile);
}
}
hFaceDetectionStatusChangedEvent = GetFaceDetectionStatusChangedEventHandle();
SetEvent(hFaceDetectionStatusChangedEvent);
CloseFaceDetectionStatusChangedEventHandle(hFaceDetectionStatusChangedEvent);
} ;
I hope this gives you a clue how to do this.
But be aware of the data transfer between the two apps, cause I do not lock the memory
for writing or reading (I didn't needed it, functions were only call in cylce of 40 ms).
Greetings
Covean
|
|
|
|
|
Thanks a lot. I will look into it.
--
Christoph
|
|
|
|
|
Hi,
I want a notification for the usb device connection and disconnection in vc++ DLL.
I am implementing J2534 DLL in that i want a notification for usb device connect and disconnect.
I read about WM_DEVICECHANGE notification and RegisterDeviceNotification.
but RegisterDeviceNotification will give error "undeclared identifier".
and both will use window handle.
if i use these functions in my DLL i wont get the window handle.
so anybody give me the solution to implement the same.
and one more thing i have found one example code to achieve the same.
this code uses AtUsbHid.dll to detect usb connect and removal.
but to use these dll functions also i need to pass window handle which is not possible in DLL.so if anybody knows the solution to use same dll without window handle.
Thanks in advance
|
|
|
|
|
Why can't you just create a hidden window that can receive the WM_DEVICECHANGE notification?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Its a really bad practice to open hidden windows in dlls, cause you never can use these dlls
in services on vista or later.
Greetings
Covean
|
|
|
|
|
If you are creating a service, then you can use RegisterDeviceNotification() to receive notification.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Yes you are right about this Register function, I only meant, not to open a hidden window
in a dll if you do not know if it can be used later in the context of a service.
Greetings
Covean
|
|
|
|
|
yes u r right creating hidden window in a dll is a bad habit.
but what ever i am implementing its not a service also.
so please suggest me some alternative solution to achieve this.
i found hid dll and i am checking that now.
anybody have idea about HID dll.can i use this dll to implement my reuirement.
|
|
|
|