|
One way to do it is to just write a small wrapper function around ResumeThread that takes a std::pair instead of just a HANDLE
void myResumeThread(const std::pair<HANDLE, int> &pair) {
::ResumeThread(pair.first);
}
int main(int argc, char* argv[])
{
std::map<HANDLE, int> blah;
std::for_each(blah.begin(), blah.end(), myResumeThread);
}
Another alternative, is if you find yourself doing it alot, is to write a really small class to do the wrapping automagically (Which is probably similar to what the other STL implementations would do anyway, but I'm not sure, since I just made this up) :
template <class T, class PAIR>
class FirstWrapper {
public:
FirstWrapper(T f) {
func = f;
}
void operator()(const PAIR &p) {
func(p.first);
}
T func;
};
template <class T, class CONTAINER>
FirstWrapper<T,CONTAINER::value_type> makeFirstWrapper(T func, const CONTAINER &cont) {
return FirstWrapper<T,CONTAINER::value_type>(func);
}
int main(int argc, char* argv[])
{
std::map<HANDLE, int> blah;
std::for_each(blah.begin(), blah.end(), makeFirstWrapper(::ResumeThread, blah));
}
The above code just makes an adhoc function wrapper around whatever function call you need.
The STL extensions suggested in the other post are more flexible, but this would do for this purpose.
Phil
|
|
|
|
|
Thanks a lot. I did not think of that...
John
|
|
|
|
|
Hello there,
I am doing array of stuctures marshalling using a local server i just wanted to know is there any limitation on marshalling or should i allocate 1mb or more of memory on the server side and pass it back.
function is like this on server side
[helpstring("method ")]GetBuddyList HRESULT GetBuddyList( [in] BSTR nick, [out] ULONG* pSize, [out, size_is(, *pSize)] loginInfo** ppBuddyList);
client just passes and empty pointer by reference and size also as empty UINT.
What i mean to say is that it wouldn't crash for very large marshalling of array of structures.
|
|
|
|
|
It shouldn't crash. You need to remember, however, that marshalling in a lot of cases makes copies as the data goes back and forth. It might be better to have the client ask for specific chunks, rather than the entire array at once.
Software Zen: delete this;
|
|
|
|
|
I just wanted to bring it into your notice that me and my friend worked on another dcom project in which server was remote and there it gave an error on more than 200kb of data passage or so. MTU Problem or whatever. Now i am going to try to marshal for local server and i just wanted to confirm that it would work for any array size.
And also could u give me explanation of
"marshalling in a lot of cases makes copies as the data goes back and forth."
|
|
|
|
|
Clients communicating with local servers have to pass data across process boundaries, which requires copying the data (which is what the marshalling process does). Win32 applications have separate address spaces, making the copy operation more complicated than a simple memory to memory copy. The copy operation is slow in this case. You should make sure that this is acceptable for your application. Using smaller amounts of data, while requiring more transactions to pass the same total amount of data, can make the application more responsive overall.
In my experience, almost any size of data can be transferred. In one application, we were transferring 32Mb images between the client and a remote server. While it was slow (several seconds over a dedicated 100 Mbit network), it was fairly reliable.
Software Zen: delete this;
|
|
|
|
|
Thank you i have tried four MB of marshalling no problem so that i am confident that it would work for bigger cases.
And i am thankful for your responsiveness.
regards,
umar.
|
|
|
|
|
Hi, I am planning to start ATL Com programming. Can anybody suggest a good starting point / online tutorial ?
Thanks
|
|
|
|
|
"Inside ATL" from Microsoft Press, it's hard to digest but not a bad book. If you know COM raw programming it will be easy for you, if not... you will enjoy a lot
Greetings
Braulio
|
|
|
|
|
Can anyone tell me how to catch a dialog box in IE and respond to it. specifically I'm trying to stop the dialog that asks if you want to work offline or try again. I need to have it just try again and complete, instead of making the user click the button. I have already tried setting the machine internet connection flag , but the target system uses some funky custom dialer that seems to override the setting. if I hit "try again" the operation completes fine.
the task involves posting data to a mini-webserver on the local machine.
Thanks for any help or hints.
Rick
|
|
|
|
|
Hi,
I'm planning to make an ATL Com Object ( that will invoke a web service). I'm thinking about using ATL 7.0, which things the I would need to install it on the client machines ?
ATL7.DLL ?, MSXML40.DLL ? Something more ? ( .net framework not needed isn't it ?).
Thanks in advance, Greetings
Braulio
|
|
|
|
|
An COM writed with ATL has a parameter which type is BSTRS.
such as
STDMETHODIMP CPNRTool::GetPNRInf(BSTR PNRNo, BSTR* PNRInf, LONG* Flag)
An application writed by VB call this COM such as
Dim sPNRNO As String
Dim sPNRNO As String
Dim lLog As Long
Dim DCSTool As DCSTool.CPNRTool
Set DCSTool = New DCSTool.CPNRTool
Call DCSTool.GetPNRInf(sPNRNO, sPNRInf, lLog)
Set DCSTool = Nothing
After finish call, I am doubt whether I need to release the memory of param"PNRInf" and "Flag"
and how to release?
Will this situation make memory leaks?
TIA
Hello everyone
|
|
|
|
|
Hi,
In theory the responsible of freeing memory/objects is the one who created it ( so like that should be Ok, VBasic created it VBasic must free it)... but with all this ATL/COM stuff ... no one really knows
On test could be take that PNRInf, and free it in the com server, then try to use it after that from the VBasic Code, if it crashes you shouldn't use that
Good Luck
Braulio
|
|
|
|
|
Here are the simple rules for COM:
[in] - Caller creates, Callee uses but cannot modify, Caller frees
[in,out] - Caller creates, Callee deallocates/allocates new, Caller frees
[out] - Caller invokes uninitialized,Callee creates, Caller frees
In any case, VB is designed to handle the memory according to the rules. It can do nothing else.
If you are having a memory leak problem then you probably have the following situation:
GetPNRInf takes [in] *PNRInf
Forgets to call ::SysFreeString on it
Then does a ::SysAllocString on it
Then returns to pass it back [out]
The memory leak happens during the call. Since VB knows the call is [in,out] it knows the string may have a different address upon return. What it cannot know is that the callee moved the address, but did not free the old string.
Someone please correct me if I overstated something here.
|
|
|
|
|
Hi! It's me again!
I'm trying to insert a DropdownButton in my Outlook plugin...a msoControlButtonDropdown button, but I just don't know how!
Here is (a piece of)my code:
CComVariant vToolBarType2(msoControlDropdown);
CComPtr < Office::CommandBarControl> spNewBar;
spNewBar = spBarControls->Add(vToolBarType,vEmpty,vEmpty,vEmpty,vShow);
ATLASSERT(spNewBar2);
The problem is that the Add Method only accepts as the first parameter msoControlButton, msoControlEdit, msoControlDropdown, msoControlComboBox, or msoControlPopup; and I want to use msoControlButtonDropdown.
Any ideas how should I do this, or how should I go around it?
As you see, the code is written in C++, but even if you have a VB sample, I guess it should do the trick.
Thanks a lot,
Doru K.
|
|
|
|
|
Hi!
I have a question for you, older & more skilled (then me ) COM programmers. I have an ATL Addin for MSOutlook2k. For now, it only displays some buttons in outlook (thanks Amit Dey! great tutorial!), but I would like to send an e-mail when pressing one of them(with some content set by me). Any ideas, tutorials, examples, Office APIs(if there is such a thing) or something like that?
BTW, I'm using VC++, NOT VB(I kind of had enough of VB tutorials
Thanks!
Doru K.
|
|
|
|
|
The easiest way (IMO) to work out how to do something using the Office object models is to prototype it in VBA (sorry...), then translate to VC++. It's not too tricky - you need to translate GetObject & CreateObject calls and work out how to call methods and access properties
Hmmm - I found this page[^] on Google - that might help?
<edit> This[^] might help even more - it converts VB automation code (i.e. what all the Outlook samples are written in) to C...
</edit>
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
Thanks a lot! I hope it will work out...the code convertor is such a great ideea! Thanks again,
Doru
|
|
|
|
|
I'm tearing my hair out looking for atltypes.h. I've downloaded the WTL library, searched online, I'm stumped. Could someone tell me where this file lives please.
|
|
|
|
|
|
I downloaded and installed WTL70.exe from Microsoft. I did a search on my HD afterwards, no atltypes.h.
|
|
|
|
|
No, not a WTL file, an ATL file, ie it comes with VC++.NET
It's in the vc7/atlmfc/include folder.
Steve S
|
|
|
|
|
|
i am using the machine generated Code for the MS Command button (ActiveX).
When developing under WinNT4.0 there was no problem in Setting the Picture Path in the Properties to a BMP File and é voila, the dialog showed up with a bitmap button.
Now i am developing under Win2k, and everytime the dialog with the buttons intialises, the code crashes. Without the Bitmaps it works perfectly. Checking the Source i would manually load the bitmaps to the buttons (hoping that this might work).. i would like to load bitmaps from an Resource ID.
My Problem right now is that it needs an IDispatch*. I guess that i need a CPicture Object (casting it to an IDispatch*), but i can't find any constructor which would take an id, or a CBitmap or sthing like that.
Can anybody help?
Thanks in advance,
Bernhard
"I'm from the South Bronx, and I don't care what you say: those cows look dangerous." U.S. Secretary of State Colin Powell at George Bush's ranch in Texas
|
|
|
|
|
See my article "PixView". You may be able to use some of the code I have in the pix.h header for the second part of your problem.
|
|
|
|
|