|
For the following code
int DLLGetKeywords( char* keyBuf)<br />
{<br />
char buffer[] = " type1,depth,type2,range,type3*";<br />
*strchr(buffer,'*') = 0;
AfxMessageBox(buffer); <br />
char *pc,*pc1;<br />
for (pc = buffer ; *pc ; pc = strchr(pc,0) + 1) <br />
{<br />
<br />
char* pc1 = strchr(pc,',');
if (pc1) *pc1 = 0; <br />
}<br />
<br />
<br />
strcpy(keyBuf,buffer);<br />
AfxMessageBox(buffer); //////////////msgbox2
The first msgbox has an output as expected: " type1,depth,type2,range,type3*"
The second msgbox has an output of "type1". Thats all.
ALl thats happening in the routine is that commas are being replaced by nulls. I thought that its because the msgbox only "reads" upto the first null. But when I go to populate a listbox with this buffer, (post messagebox2), i only get "type1" in it.
Any light on this mystery?
Thanks,
ns
|
|
|
|
|
ns wrote:
ALl thats happening in the routine is that commas are being replaced by nulls.
When you do this, you terminate the string. The array is filled with characters and nulls, but when you output them from the beginning, it only goes as far as the first null.
Dave
"You can say that again." -- Dept. of Redundancy Dept.
|
|
|
|
|
I suspected this. So how does one extract the words buried in a string which has nulls between words?
I have stuff like "abc\0aaa\0ddd\0" which is my attempt at saying I've got nulls between words? I'm using this:
<br />
void CTrain1View::popDisplayList(int popDisplayFlag, char * buffer)<br />
{<br />
if (popDisplayFlag)<br />
{<br />
char* pc;<br />
<br />
CString string;<br />
int nListIndex = 0;<br />
for (pc = buffer ; *pc ; pc = strchr(pc,0) + 1) <br />
{<br />
char* pc1 = strchr(pc,',');
if (pc1) *pc1 = 0;
string = pc;<br />
int nItem = m_listdisplay.InsertItem(nListIndex,string);<br />
<br />
}<br />
<br />
but my listbox gets one extra line of garbage after the first five (buffer has five words in it, commma delimited)entries. I dont see why.
Any clues? I do thank you for confirming my suspicion regarding the buffers condition after putting in the nulls.
|
|
|
|
|
My suggestion would be to use the 'strtok' function (string to token) on the original string with the commas. On the first call, you specify the source string and a set of delimiters (a comma, in your case) and the function returns a pointer (I think) to the first sequence of characters up to the specified delimiter. On subsequent calls, the source string is specified as NULL, as the function maintains its own buffer. Each consecutive call will return a pointer (I think) to the next sequence of characters up to the specified delimiter. When strtok returns NULL, there are no more tokens.
Two things:
1) strtok replaces the found delimiter with a NULL, which you don't have to worry at all about.
2) the set of delimiters can be changed on each call, if desired. This is handy for parsing a sequence where things are not always the same.
Dave
"You can say that again." -- Dept. of Redundancy Dept.
|
|
|
|
|
Thank you very much for the strtok - i didnt know about it. I appreciate your responses - they are most helpful!
ns
|
|
|
|
|
Ugh, code like this is difficult to maintain and won't pass a review. Now back to our regularly scheduled broadcast...
The first msgbox has an output as expected: " type1,depth,type2,range,type3*"
This surprises me. The output shouldn't include the trailing asterisk.
The second msgbox has an output of "type1". Thats all.
That makes sense, because you've happened to have (eventually) replaced the first comma with a null byte. Btw, the loop logic (specifically the increment) is suspect. What do you want to have happen?
/ravi
Let's put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I was trying to extract words out of a buffer which has null terminators between words. I was supplying myself with a fake buffer of the sort I expect to get, to see if my code would process the buffer correctly. You are right - there was of course no * in the messageBox. In this thread char * got much clearer to me. I like CStrings better but I have to use whatever someone elses dll supplies. Thanks much.
|
|
|
|
|
Consider using strtok() to extract tokens from a C string. The tokens need to be delimited by a non-null char. If you're creating the string yourself, then this is easy. I usually use '`' or '~' as delimiters, because they stand out while debugging. Hope this helps!
/ravi
Let's put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I just saw David's response to your email. Never mind...
/ravi
Let's put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I didn't see any documentation that you couldn't. I'd like one at the top and one at the bottom essentially taking up all of the client area. Is that possible?
|
|
|
|
|
Has anyone seen this problem with ADO query:
select /*?*/ 1 from dual
Basically it seems if the query / proc / function contains question mark, ADO query will return "Wrong number of parameters" error message. Change ? to '?' will be fine, but that alter the code as well.
For instance, the following code will cause problem:
create or replace function aaa return number
value number;
is
begin
value := select sum(amount) /*Total Amount?*/ from bill_info;
return value;
end;
Has anyone know what is the right escape for question mark?
Thanks.;P
|
|
|
|
|
How do I prevent my application showing a button on the taskbar?
Thanx
|
|
|
|
|
See this article.
/ravi
Let's put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
|
Simply remove the WS_EX_APPWINDOW style from your window.
MFC:
pWnd->ModifyStyleEx(WS_EX_APPWINDOW, 0);
Win32 API:
LONG lStyle = ::GetWindowLong(hWnd, GWL_EXSTYLE);
lStyle &= ~WS_EX_APPWINDOW;
::SetWindowLong(hWnd, GWL_EXSTYLE, lStyle);
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
i have 2 methods that are using IWebBrowser2 to execute a print method from a com object that is hosted on a webpage. here is the code for the methods:
---------------------------------
STDMETHODIMP CTemplatePrinter::IEPrintNoPrompt(VARIANT varTemplateURL)
{
CComPtr<iolecontainer> spContainer;
CComPtr<iserviceprovider> spSP;
CComPtr<iwebbrowser2> spWB;
CComPtr<idispatch> spDisp;
CComPtr<ihtmldocument2> spDoc;
CComPtr<iolecommandtarget> spCT;
CComVariant vPTPath = varTemplateURL;
m_spClientSite->GetContainer(&spContainer);
spContainer->QueryInterface(IID_IServiceProvider, (void**)&spSP);
spSP->QueryService(SID_SWebBrowserApp, IID_IWebBrowser, (void**)&spWB);
spWB->get_Document(&spDisp);
spDisp->QueryInterface(IID_IHTMLDocument2, (void**)&spDoc);
spDoc->QueryInterface(IID_IOleCommandTarget, (void**)&spCT);
// ******* THIS IS WHERE IT'S GOING CRAZY!!!! ******* //
spCT->Exec(&CGID_MSHTML, IDM_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, &vPTPath, NULL);
return S_OK;
}
---------------------------------------
STDMETHODIMP CTemplatePrinter::IEPrint(VARIANT varTemplateURL)
{
CComPtr<iolecontainer> spContainer;
CComPtr<iserviceprovider> spSP;
CComPtr<iwebbrowser2> spWB;
CComPtr<idispatch> spDisp;
CComPtr<ihtmldocument2> spDoc;
CComPtr<iolecommandtarget> spCT;
CComVariant vPTPath = varTemplateURL;
m_spClientSite->GetContainer(&spContainer);
spContainer->QueryInterface(IID_IServiceProvider, (void**)&spSP);
spSP->QueryService(SID_SWebBrowserApp, IID_IWebBrowser, (void**)&spWB);
spWB->get_Document(&spDisp);
spDisp->QueryInterface(IID_IHTMLDocument2, (void**)&spDoc);
spDoc->QueryInterface(IID_IOleCommandTarget, (void**)&spCT);
// ***** IT CALLS THIS 2 TIMES? ******** //
spCT->Exec(&CGID_MSHTML, IDM_PRINT, OLECMDEXECOPT_PROMPTUSER, &vPTPath, NULL);
return S_OK;
}
--------------------------
my question is: does anyone have any idea why the IOleCommandTarget::Exec method it going berzerk? when i call the method from a script, the first one keeps spooling pages into the printer, and the second one opens 2 print dialogs in a row...i also have another function for opening a print preview window that works fine....the only difference is my call to Exec is as follows:
spCT->Exec(&CGID_MSHTML, IDM_PRINTPREVIEW, OLECMDEXECOPT_PROMPTUSER, &vPTPath, NULL);
i've tried all that i can see...if i replace spCT->Exec(...) with
spWB->ExecWB(OLECMD_PRINT, OLECMDEXECOPY_PROMPTUSER, &vPTPath, NULL);
it still does the same thing...i've even tryied without passing in the &vPTPath (printing template path) argument
i also know that the method is only getting called once...i tested this by also using spDoc to write some stuff out to pop up a message box every time it got called, and the message box only came up once, but the printing kept going...
any suggestions?
michael griffith
--------------------
mgriffith@lauren.com
mdg12@po.cwru.edu
|
|
|
|
|
I would like to set the font size of a dialog based on the screen resolution of the user's PC. Does anyone have a quick function to do this???
Thanks,
FL
|
|
|
|
|
i'm using a class from another program, but if i compile i get the a *.obj : error LNK2001:unresolved external symbol error, __imp__waveOutWrite@12. (waveOutWrite is the function declared in mmsystem.h) how can i fix this?
|
|
|
|
|
You must link with Winmm.lib .
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
Hello there,
I came back !!!!
NICE TO MEET ALL OF YOU
Well, i have new question ... it's about finding a value in vector array !
As i know, find(one of STL functions) function could search in usual array very well ...
But how could i find a value in vector ???
Thanks in Advance
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
std::find(v.begin(),v.end(),value);
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hello Joaquín ...
my pal
thanks for your reply ...
But could u tell me how could i get the location of value in the vector ?
I know, i must check the return value of find function ...
But in which kind of variables ?
I must use iterator ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
std::find returns an iterator pointing to the position within the vector where the value was found. If the value is not found, end() is returned. Use std::distance in <iterator> to easily determine the location within the vector.
// warning untested code
std::vector<type>::const_iterator it = std::find(v.begin(), v.end(), value);
if (it != v.end())
{
std::vector<type>::differenc_type loc = std::distance(v.begin(), it);
}
Phil Boyd
MCP
CPT, AR
You may be gone, but we will never forget your sacrifice.
"Proud to be an American..." Lee Greenwood
|
|
|
|
|
Hello all,
Thanks for the dialog tricks answers. They were very helpful. Thanks a bunch.
So now I got more questions:
1)This code from MSDN help files
void CMainFrame::OnFileNewchild()
{
CMDIChildWnd* pMDIChildWnd = new CMDIChildWnd;
VERIFY(pMDIChildWnd->Create(
NULL, // standard CMDIChildWnd class
_T("My MDIChildWnd"), // caption of MDI child window
WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW, // window styles
rectDefault, // default rectangle size
this)); // parent window; can be NULL
// the default PostNcDestroy handler will delete this object when destroyed
}
This will create a new MDI Child Window if I paste it into the Mainframe.cpp class of my MDI app. What I'd like to know, is how to pass the messages to it to get it to do something?
I'd like it to open Bitmaps, and I have a bitmap file viewer that will open Bitmaps into the default MDI child windows. How do I send a message to the onDraw function to draw into THIS custom MDI child window?? Basically, how can I get this Window to do somethign apart from appear?
If any of you know how to go about doing this and on top of that, want to let ME know , I'd be mega-grateful. I really want to know how to do this. Does this involve creating a new Doc and view class? Arghhh...I'm kinda lost and some diretion would be nice
|
|
|
|
|
NickOne wrote:
This will create a new MDI Child Window if I paste it into the Mainframe.cpp class of my MDI app. What I'd like to know, is how to pass the messages to it to get it to do something?
If it'll always do the same thing, then put the code in the child windows constructor. Otherwise, there is code on MSDN to iterate through all open documents ( that is to say, I forget how to do it, but that is where I learned )
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|