|
I want to parse a some text from a file. The format of the text goes something like this:
#BeginRegisterList
0= RegisterName A2 D2;
1= "Control Set";
2= Byte control &c5;
#EndRegisterList
I have converted the text from the file into a CString object, so that I can pass it into the StringParser functions.
I was able to use the modified StringParser class (I only changed the delimiter data type for "char" to "CString") to extract the lines between "#BeginRegisterList" and "#EndRegisterList" (I used these strings as the delimiter), leaving behind the following lines:
0= RegisterName A2 D1
1= "Control Set"
2= Byte control &c5
bit control
my problem arose at the point whereby I use a 'for' loop to extract the various parameters to be stored in the document:
RagisterName
2
1
Control Set
Byte Control
c5
bit control
the 'for' loop is to change the delimiter from "0=", "1=", ... "9=".
I hope the explanation is clear. I downloaded your code last week. will download the latest version now.
|
|
|
|
|
I'm leaving for work - I'll answer this when I get there. Do not dispair.
|
|
|
|
|
I have changed to the latest version and the 'for' loop works! I dunno what went wrong really. The old StringParser class still doesn't work.
Maybe you would like to take a look at the changes I made to your updated source code, using CString as delimiter. I have added another private member variable m_cDelimiterLen to adjust the workString for in the function CQStringParser::ParseString(). Will send the modified source files to your email.
|
|
|
|
|
I would use just the ' ' (space) character as the delimiter. This would result in the following:
//string 1
CStringParser("0= RegisterName A2 D2", ' ', '\"');
GetField(1) - "0="
GetField(2) - "RegisterName"
GetField(3) - "A2"
GetField(4) - "D2"
//string 2
CStringParser("1= /"Control Set/"", ' ', '\"');
GetField(1) = "1="
GetField(2) = ""Control Set""
GetField(2, TRUE) = "Control Set" // strip the quotes from the string
//string 3
CStringParser("2= Byte Control %c5", ' ', '\"');
GetField(1) - "2="
GetField(2) - "Byte"
GetField(3) - "Control"
GetField(4) - "&c5"
If you wanted to, it would be a simple matter (with the latest version of CStringParser) to modify the sub-strings (removing the '=' or leading spaces) by creating your own derived CStringParser class and handling the special cases as they arise without the need to change the underlying base class.
|
|
|
|
|
just wondering,
if I use a white space character ' ', the code does not detect the tabs spaces. Is there any way I can make the tab space(s) = a single white space?
Wat delimiter should I use if I want to parse my string into lines of text. Should the delimiter be the end-of-line (or is it some linefeed or CR character) character? If yes, what is the character?
Please provide me with some sample code if possible.
Thanks a lot!
|
|
|
|
|
I think your problem was with CStringArray(). I used CArrays() in my program and it was sometimes very hard to find out what causes the problem - one time it worked and one it doesn't. And even if you passed the same type of variables to it! I just had to rebuild the whole functions sometimes to make it work. Sometimes it worked if you rebiudl the whole project and sometimes when you restart VS - maybe it uses some kind of cache memory?
Microsoft knows.
Greets,
|
|
|
|
|
Hi
I'm a Korean..
How to control the other program(for example, MS Word, Internet Explore etc...)'s scrollbar?
For example, when any button in my program is clicked,
my program want to know other program's scrollbar's "range"(or page, position) in client area.
how to???
|
|
|
|
|
Why on earth would you want to do *that* ?
If you enumerate the windows in some manner you can get the CWnd of another Window, then I presume you can call SetScrollPos, etc.
Christian
I've learned that you cannot make someone love you. All you can do is stalk them and hope they panic and give in.
The early bird may get the worm, but it's the second mouse that gets the cheese.
|
|
|
|
|
Hi Christian.
But how can i get CWnd pointer from other program ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Like this
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
char* h = new char[255];
GetWindowText(hwnd,h,255);
CString text(h);
long wl = GetWindowLong(hwnd,GWL_STYLE);
CArray<cstring, cstring="">* lb = (CArray<cstring, cstring="">*)lParam;
if (text.GetLength()>0 && IsWindowVisible(hwnd) &&
text != "Program Manager" && text != "Window Popper")
lb->Add(text);
return TRUE;
}
In my code, lParam is a CArray ( nowadays I would use a vector ), and I check the title of the window to see if it's one I want to ignore and if it's visible ( not doing the visibility check gives you a gazillion hidden windows ) and then pass the title into my list. Then I do this in my main code:
CArray<cstring, cstring=""> list;
EnumWindows(EnumWindowsProc, (long)&list);
and I can do this:
CWnd *pOtherWnd = CWnd::FindWindow(NULL, name);
if I find the Window I want ( for example, I might search for the first four letters of the title to be Word, but the next three not to be Pad ), then I get the CWnd by calling FindWindow. If I know for sure something is running and it's full title, then I can just go to this step.
Christian
I've learned that you cannot make someone love you. All you can do is stalk them and hope they panic and give in.
The early bird may get the worm, but it's the second mouse that gets the cheese.
|
|
|
|
|
Hello everybody,
Iam a newbie to ATL&ADOs.I am developing an ATL component which is to store some binary data in to a table using ADOs.I have a problem with storing of binary data. I don't know how to pass a parameter along with the SQL query, that's why i am using a sample ADO dll(adosamp) which is there in MSDN samples. I am getting the binary data (which may have null characters in between) thru a ptr to the buffer (char*) from another dll, after that i am using CComVariant to encapsulate that buffer (char*) & passing along with SQL query as a parameter. In the data that i am getting, the second character itself is null char (ASCII 0). I tried asigning the buffer's data (char*) in 2 ways
one is
passing the char* in constructor of CComVariant as CComVariant vt(buff)
and passing it's length as 195. if i do so it's taking the CComVartiant as of type VT_BSTR, the data getting stored is first 2 chars only (terminated with null char).
Second is
i have assigned the char* to "pcVal" field of CComVariant and set type of the CComVariant as VT_BYREF|VT_I1 & passing the length of buffer as 195. when i did so it's giving an error stating that
" Invalid string or length".
The data in CComVariant variable is there till the execute command.
How can i solve this problem & insert binary data in table(Access)?
Also tell me how to pass the buffer along with the SQL query as a parameter?
Thanks in Advance.
My e-mail id kgrajashekar@usa.net
|
|
|
|
|
convert the data bytes to text (inc 0 for zero's) and send them as a string into the db
ie, "hello world0It is a nice day0"
---
"every year we invent better idiot proof systems and every year they invent better idiots"
|
|
|
|
|
Thanks for reply.
But Sorry lauren,
i didn't get u, what do u mean to say, please elobarate it.
|
|
|
|
|
well supposing you have binary data as follows:
765076004325600tsktsk00876
convert it to a ascii representation and in the sql statement that updates the db instead of using a numeric type to make the query text use a string type ... the db will convert it back to binary on the insert
---
"every year we invent better idiot proof systems and every year they invent better idiots"
|
|
|
|
|
Couldn't he also use a SAFEARRAY of characters? That would preclude him from having to convert characters, and what if there's actually zero's in the blob of data?
I'm certainly no COM expert (far from it actually), but it seems a SAFEARRAY would be, ummm, safer.
|
|
|
|
|
awwwww ... where's the fun in that
---
"every year we invent better idiot proof systems and every year they invent better idiots"
|
|
|
|
|
I think he's past the "having fun" part...
|
|
|
|
|
Addressed below is a subset of your problem. Essentially, first, you are getting a byte array data typecast to char* and hence the trouble.
0. Use BT_BYREF|VT_UI1 *and* pbVal.
I bet this will work because VT_BYREF|VT_I1 maps to char*. (Meaning, a C-String to be ended at the first null character).
1. For another clean solution. (Divide the work between you and the dll guy):
- HGLOBAL hG = GlobalAlloc( GPTR, 192 );
- CreateStreamOnHGlobal gives you a pStream
- Use CComVariant::ReadFromStream
- Release pStream and hG correctly, later.
2. Or, you can hack like this:
::SysAllocByteLen(192 bytes) to allocate a BSTR yourself.
memcpy your data into BSTR
Encapsulate this BSTR into CComVariant.
Release SysFreeString the BSTR later
I think solution 0 above should solve your problem completely. If not, try 1. If 1 doesn't work, 2. also will not work, and it will be time to focus on ADO/Access interaction rather than CComVariant.
But, if ADO/Access is graceful enough about string lengths and all, I am betting, it's just the issue of data types, and solution 0 will take care of it.
-------
Nature, to be commanded, must be obeyed. (Francis Bacon)
Nature, to be apprehended, must be obeyed. (Ayn Rand)
|
|
|
|
|
On second thoughts...
Solution 2. above may not be suitable at all. Here's why. ADO/Access may not like a VARIANT of BSTR type for updates to a binary field in the DB. (Just check up about what data types it can take for TEXT, MEMO, etc. field types.)
-------
Nature, to be commanded, must be obeyed. (Francis Bacon)
Nature, to be apprehended, must be obeyed. (Ayn Rand)
|
|
|
|
|
Thank u very much Ajith for prompt reply. I will all the solutions.And inform u the result .Thanks once again.
K.G.RajaShekar
|
|
|
|
|
Hi All,
I am working with VC++(ATL COM AppWizard).How can I trim the leading and trailing spaces in a BSTR value ?
Thanx in advance for help !
Y.Yamini Devi .
|
|
|
|
|
hello,
im using winrunner to test an app and it is failing to find text in a list box when the fields are becomeing truncated. I wanted to overcome this by calling api functions to find the x y coordinates of focus rectangle as the desired item in the list has already been selected using the apps search function. With these i could move the mouse to those coordinates and continue the test.
Ive tried the following:
***********************************************************************************************
HWND Handel, ChildHandel; //Handels
POINT Pos;
Handel = FindWindow (NULL, "Fields"); //Get fields Window handel
ChildHandel = FindWindowEx (Handel, NULL, "STRHList", NULL); //Get List window
SetForegroundWindow(ChildHandel);
GetCaretPos (&Pos);
printf ("%d\n\n", Pos.x);
***********************************************************************************************
This prints out 0.
Is there any api function that will give my screen coordinates for the focus rectangle or the currently selected item in a list???
|
|
|
|
|
GetWindowRect ? What are you trying to do ? Did you copy and paste this code, and if so, I'm curious as to how your compiler accepts handel ?
Christian
I've learned that you cannot make someone love you. All you can do is stalk them and hope they panic and give in.
The early bird may get the worm, but it's the second mouse that gets the cheese.
|
|
|
|
|
By George I think he must have the classic version of the compiler!!!
|
|
|
|
|
Im trying to find the coordinates for a selected item in a list. The code i wrote there finds the handel for the list then sets it to the foreground. Then i try to get the caret position. As far as i know the focus rectangle is an invisible caret??? This code compiles and runs but obviously isnt giving me what i need. Im using visual C++ 6 is this a bad thing?
|
|
|
|