|
I am quite a bit further along than I was last night, but I still have a problem:
IVariantDictionary* pVD;
cxt.Session()->get_Contents(&pVD);
if (pVD)
{
int nCount = 0;
pVD->get_Count(&nCount);
for (int i = 0; i < nCount; ++i)
{
_variant_t vItem;
_variant_t vIndex(i);
_variant_t vKey;
pVD->get_Key(vIndex, &vKey);
pVD->get_Item(vKey, &vItem);
cxt.Response()->Write(vKey);
cxt.Response()->Write(_variant_t(" = "));
cxt.Response()->Write(vItem);
cxt.Response()->Write(_variant_t("<br/>"));
}
}
All of this works, except that get_Key and get_Item both require the name of the key. Why would I want to ask for the key if I know it ? There is a get__NewEnum method, but I can't figure out how to use it. I just want to iterate through the entire collection, it surely can't be as hard as MSDN makes it look ?
Help me Obi Wan Kenobi, you're my only hope....
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
_NewEnum is the actual method call translated from VB code (or other automation languages) anytime it's getting items of a collection.
Usually both the Item property and _NewEnum take a variant as input param and accept both VT_I4 indexes and VT_BSTR names. As a consequence, unless the implementation does not follow the standards, you should be easily able to enumerate the collection without bothering the keys.
|
|
|
|
|
That's what I expected, but I've been passing in an index and getting nothing back. You're saying in essence that the code I've tried should work ? That I should be able to pass in an index and get back the value ? I wonder if I need to change the VT of the number I am passing in to VT_I4 ?
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
have you tried VariantDictionnary[i] using VB code ?
If this works, then yes, switch your _variant_t type to VI_I4.
|
|
|
|
|
from "ATL Internals"
Chris Sells does this, on his definition:
<br />
IPrimeNumbers : IDispatch<br />
{<br />
[propget]<br />
HRESULT Count([out,retval] long *pCount);<br />
[propget,id(DISPID_VALUE)]<br />
HRESULT Item([in] long n, [out,retval] long* pVal);<br />
[propget, id(DISPID_NEWENUM)]<br />
HRESULT _NewEnum([out,retval] IUnknown** ppunkEnum);<br />
}<br />
interface IMyEnum : IUnknown<br />
{<br />
[local]<br />
[helpstring("method Next")] HRESULT Next([in] ULONG celt, [out] long* rgelt, [out] ULONG* pceltFetched);<br />
<br />
[call_as(Next)]<br />
[helpstring("method RemoteNext")] HRESULT RemoteNext([in] ULONG celt, [out, size_is(celt), length_is(*pceltFetched)] long* rgelt,[out] ULONG* pceltFetched);<br />
<br />
[helpstring("method Reset")] HRESULT Reset();<br />
[helpstring("method Clone")] HRESULT Clone([out] IMyEnum **ppenum);<br />
[helpstring("method Skip")] HRESULT Skip([in] ULONG celt);<br />
};<br />
that worked for me when i needed to do a for each in vb.
you also need to add this at the end of the idl file, just change IMyEnum with your enum interface:
<br />
cpp_quote("#ifdef __midl_proxy")<br />
cpp_quote("static HRESULT STDMETHODCALLTYPE")<br />
cpp_quote("IMyEnum_Next_Proxy(IMyEnum* This, ULONG celt, long* rgelt, ULONG* pceltFetched)")<br />
cpp_quote("{")<br />
cpp_quote(" ULONG cFetched;")<br />
cpp_quote(" if( !pceltFetched && celt != 1 ) return E_INVALIDARG;")<br />
cpp_quote(" return IMyEnum_RemoteNext_Proxy(This, celt, rgelt, pceltFetched ? pceltFetched : &cFetched);")<br />
cpp_quote("}")<br />
cpp_quote("")<br />
cpp_quote("static HRESULT STDMETHODCALLTYPE")<br />
cpp_quote("IMyEnum_Next_Stub(IEnumPrimes* This, ULONG celt, long* rgelt, ULONG* pceltFetched)")<br />
cpp_quote("{")<br />
cpp_quote(" HRESULT hr = This->lpVtbl->Next(This, celt, rgelt, pceltFetched);")<br />
cpp_quote(" if( hr == S_OK && celt == 1 ) *pceltFetched = 1;")<br />
cpp_quote(" return hr;")<br />
cpp_quote("}")<br />
cpp_quote("#endif // __midl_proxy")<br />
hope this can help you.
also this page may help you:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/vcconImplementingSTLBasedCollection.asp[^]
"Now I guess I'll sit back and watch people misinterpret what I just said......"
Christian Graus At The Soapbox
[^]
|
|
|
|
|
|
How can i determine that someone is scrolling in my listbox?
|
|
|
|
|
I'm not sure that this works on a listbox, but in the listctrl it does...
1. Create your own ListBox.
1.1. Create a new class using the wizard and select CListBox as base class
2. Handle the message ON_WM_VSCROLL (up/down scrolling)
2.1. In your newly created class you should right click it's name in the ClassView tab and add the mesage handlers (Vertical and horizontal scrolling)
3. Notify parent...
3.1. Use SendMessage/Postmessage (the nicest methods) or get access to your parent window and call a method/function in order to notify it...
I've used this in order to prevent the user to scroll while edition in the listctrl was active and it worked...
Hope this helps...
|
|
|
|
|
I don't know the answer, but I'm still curious: why does your app need to know this?
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
|
|
|
|
|
I am using the following to get a handle for the font that I need to write with.
HFONT hNewFont = ::CreateFont(iHeight, 0, 0, 0, (IsBold? FW_BOLD: FW_NORMAL),
IsItalic, IsUnderline, IsStrikeOut, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, FontName);
My problem is that I have to delete the handle after using it to free the memory, but when I use DeleteObject(hNewFont) the font is not drawn correctly. How can I remove the font handle from the memory that will not affect my drawing.
Daed
|
|
|
|
|
You probably still use the font (draw text with it) after you deleted the HFONT handle.
Maybe you selected it?
The solution is to DeleteObject the HFONT handle only after you unselected it in any window using it, e.g when the window is destroyed.
--------------------------------------------------
If my messages appear curt, I apologize.
I try to be brief to save your time as well as mine.
--------------------------------------------------
|
|
|
|
|
I assume the font is being draw correctly if you don't delete it? If so, it sounds like you are calling DeleteObject before you have finished drawing the text. This usually happens becasue you have done something like PostMessage to draw the text then immediately afterwards called DeleteObject. I tend to do this, in "pseudo" code, when changing fonts
hFont = CreateFont
hFoldOld = SelectObject(hFont
drawtext
SelectObject(hFoldOld
DeleteObject(hFont
|
|
|
|
|
I pass the hNewFont as a parameter in a function SetMyFont, this function sets a member variable called m_hFont to hNewFont as follows:
void CMyClass::SetMyFont(HFONT hNewFont)
{
m_hFont = hNewFont;
}
then later I use the member variable m_hFont to draw the text. My exact code is:
HFONT hNewFont = ::CreateFont(iHeight, 0, 0, 0, (IsBold? FW_BOLD: FW_NORMAL),
IsItalic, IsUnderline, IsStrikeOut, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, FontName);
if (hNewFont)
{
SetMyFont(hNewFont);
}
I thought that there is no harm in deleting the handle here because I will use the copy of it, and I delete the m_hFont in the destructor.
Can you help me in this?
Daed
|
|
|
|
|
This statement m_hFont = hNewFont does not "make a copy" of the font, all you have done is assigned the variable m_hFont to hNewFont. m_hFont is a HANDLE it just points to some memory location, i.e. the same memory location as hNewFont. So basically don't delete hNewFont.
I suggest in the construtor
m_hFont = NULL;
then
if(m_hFont)
DeleteObject(hFont)
m_hFont = NULL;
hNewFont = ::CreateFont
if (hNewFont)
{
SetMyFont(hNewFont);
}
|
|
|
|
|
Sorry must learn to type
if(m_hFont)
DeleteObject(m_hFont)
|
|
|
|
|
I tried it, but i will still have one font handle in the memory!
|
|
|
|
|
If is difficult to answer your question, without seeing the code. I assume you are failing to delete a font you have created? You could have called CreateFont twice, thereby overwritting the previous font value?
Assuming, again, it is all in one class.
Constructor
m_hFont = NULL
CreatingFont
if(m_hFont)
DeleteObject(m_hFont)
m_hFont = NULL;
m_hFont = CreateFont(
Destructor
if(m_hFont)
DeleteObject(m_hFont)
This way you are only using m_hFont, so it is easier to check what you are doing. Also check the error returns from the functions.
|
|
|
|
|
Can anybody suggest a good profiling tool that will monitor the execution of a program and breakdown the amount of time spent calling the various Win32 API functions. In particular I need to know how long a program is spending reading, writing and flushing files.
Systems AXIS Ltd - Software for Business ...
|
|
|
|
|
Personally I prefer Quantify[^] from Rational. But you can do it also with the VC profiler.
TrueTime from Numega works too, but I dont like its interface. Too clumsy. Quantify is intuitive and really easy to use. Also gives better results.
I don't think this is a serious possesion, and the evil most likely comes from your hand. Colin J Davies, The Lounge
|
|
|
|
|
Hi,
I am doing a very basic thing of sending data to a server and getting the reply back.
For which first I have to send in a Login request and get authenticated, once authenticated, I have to send the actual data.
The problem I am facing is when I send the data, it embeds some funny characters before the actual text, which is causing the problem.
Upon further investigation, it was found that if I send the data without the login, it gets to the server correctly.
Is there some kind of REFRESH!!! for the second time when the data is sent so that it has correct values?
[CODE]
=========================================
for login authentication:
e = sendto(sd,"<req><loginid>8888\n",89,0,(struct sockaddr *)&saServer,sizeof(saServer));
For sending Data:
e = sendto(sd,"<req><loginid>8888<reqtype>08<broadcast><messagetype>M<no>5359846<message>Test+Value\n");
==========================================
[CODE]
The second sendto, does not send the data correctly.
Is there some refresh after we do the first sendto?
Kindly Help!!!
Best Regards,
John
|
|
|
|
|
From MSDN-doc I get that the 3rd parameter of ::sendto() is int len .
Are you setting this one correctly to the length of the data you want to transmit?
And: do you get an error-return in your variable e ?
--
"My opinions may have changed, but not the fact that I am right."
Found in the sig of Herbert Kaminski
|
|
|
|
|
Hi,
yes the return variable is '0' which is correct.
Thanks,
John
|
|
|
|
|
So, having 0 bytes transfered is correct?
I don't think so! Something is rotten here, and I am of no help, 'cause I never used sockets. Sorry!
But it seems you HAVE TO read the MSDN about this.
"My opinions may have changed, but not the fact that I am right."
Found in the sig of Herbert Kaminski
|
|
|
|
|
Oops!! sorry I gave you the return code '0' which means success.
yes, there is a return confirmation which I am getting.
But I am not selecting the entire return confirmation, just taking in first 40 bytes.
Thanks,
John
|
|
|
|
|
John Bosko wrote:
yes the return variable is '0' which is correct.
which is _not_ correct. Try and give the length of the data you want to send as third parameter of the sendto . I think that this is really a buffer problem. When you send your data without preceding it by the login request, the buffer is empty (and not full with the loggin request stuff), so IMO that's why there is no problem in that case.
~RaGE();
|
|
|
|
|