|
Wrong answer!!! It is possible with dlls. Read articles in MSDN about dll nature.
Regards,
Alexander Fedorenko,
Author of DevPlanner - tool for effective planning in development.
|
|
|
|
|
You should never create a DLL singleton. This has been discussed many times
in the past, and I won't recount the reasons why. But if you want to do some
background research, check the archives at http://discuss.microsoft.com, and
do a search for "DLL singleton".
think about a process creating your SINGLETON.
It will lookup the registry that says: load DLL
Then it will ask the DLL to get a ClassFactory for SINGLETON
The factory will create a new object and return it.
Every time to process asks for SINGLETON it get the same object.
That's what singleton means.
But now a second process tries the same.
Will it get the same object from the different adress space ?
I hope not, because of the 0xC0000005 exception you would probably see then
DLL SINGLETON's are only singletons within a process.
Donno, if now something as changed but one year ago... the techies said that...
|
|
|
|
|
Yes... I have been looking now... there is one strange way of doing now... but then you are making not a right thing... something wrong with the architecture of the system...
Greetings
Braulio
|
|
|
|
|
I just wanted to know is it possible or not
and the articles referred to in msdn and internal atl on devx are all for taking care in sta based thing i just want to know that is it possible or not
if it is i need the method. If not then i would look into exe based singleton which i have worked on before and managed it easily.
My conclusion uptill now is that singleton for a dll is like for a proces. I mean to say you can only have one object per process but many for many processes i.e. one for each process.
And for exe base out of process one and only one instance runs in an address space.
So i need a shared memory(dynamic mechanism) between all the process using dll.
|
|
|
|
|
I had the following code:
for_each(pool.begin(), pool.end(), ::ResumeThread);
In this case pool was a vector of handles.
std::vector<HANDLE> pool;
I needed to convert it to a map so here is the new code:
std::map<HANDLE, unsigned int> pool;
So now I wrote the code with a for loop instead.
for(std::map<HANDLE, unsigned int>::iterator it =pool.begin(); it != pool.end();it++) {
::ResumeThread(it->first);
}
My question is how do I do this with a for_each statement?
John
|
|
|
|
|
Unfortunately, you'll need to use the non-standard select1st and compose1 functions (AFAIK). VS.NET 2K3 doesn't support either function out of the box, but other STL implementations do (they are SGI extensions).
Here's an example using GCC 3.x:
<br />
#include <map><br />
#include <algorithm><br />
#include <functional><br />
#include <ext/functional><br />
<br />
using namespace std;<br />
using namespace __gnu_cxx;<br />
<br />
typedef map<int,int> pool_t;<br />
<br />
void Process(int i) {<br />
printf("%d\n",i);<br />
}<br />
<br />
int main(int argc,char **argv) {<br />
pool.insert(pool_t::value_type(1,2));<br />
pool.insert(pool_t::value_type(5,2));<br />
pool.insert(pool_t::value_type(3,2));<br />
pool.insert(pool_t::value_type(2,2));<br />
<br />
for_each(pool.begin(),pool.end(),<br />
compose1(ptr_fun(Process),<br />
select1st<pool_t::value_type>()));<br />
<br />
return 0;<br />
}<br />
Of course, it's a bit dubious as to whether this is really any easier to work with than writing your own iteration loop.
If there's another way to accomplish this without using the extensions, I'd love to know
- Mike
|
|
|
|
|
Thank You for the detailed explanation.
Michael Imamura wrote:
Of course, it's a bit dubious as to whether this is really any easier to work with than writing your own iteration loop.
I agree. The loop looks simpler to me.
Thanks again,
John
|
|
|
|
|
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
|
|
|
|
|